Commits

Nikolaj Sjujskij  committed 40f9af5

ino_watch: implement rst2man action

  • Participants
  • Parent commits a61eaa0

Comments (0)

Files changed (1)

File inotify_watcher.py

 implemented_actions = {}
 
 PAGER_OPTS = ['less', '-']
+NROFF_OPTS = ['nroff', '-Tutf8', '-man', '-']
 
 
 def register_action(name=None, is_firsttimer=False,
                                writer_name='html')
 
 
+@register_action('rstman')
+@page_output
+def rst2man(filename):
+    ''' File contents highlighter '''
+    import docutils.core
+    content = docutils.core.publish_file(source_path=filename,
+                                         writer_name='manpage')
+    nroffer = subprocess.Popen(NROFF_OPTS, stdin=subprocess.PIPE,
+                                           stdout=subprocess.PIPE)
+    output, errors = nroffer.communicate(input=content)
+    return output.decode('utf-8'
+                ).encode('latin1', errors='replace'
+                ).decode('utf-8', errors='replace')
+
+
 def ino_watch(file_to_watch, action, action_args=[], action_kwargs={}):
     ''' ``inotify``-based watcher, applying function upon
         *write-and-close* events '''