Commits

Nikolaj Sjujskij committed 99a388a

Fix imports, docstrings, newlines and other stuff

Comments (0)

Files changed (1)

inotify_watcher.py

 Distributed under the terms of the GNU General Public License v3
 '''
 
-from optparse import OptionParser, OptionGroup
+from optparse import OptionParser
 import os.path
+import time
 
 import inotifyx
 import docutils.core
 from pygments import highlight
-from pygments.lexers import guess_lexer, guess_lexer_for_filename
+from pygments.lexers import guess_lexer_for_filename
 from pygments.formatters import TerminalFormatter
 
 implemented_actions = {}
 
+
 def register_action(name=None, catalogue=implemented_actions):
-    ''' Registration decorator, maintaining dictionary of implemented actions'''
+    ''' Registration decorator, maintaining dict of implemented actions'''
     name = name or f.__name__
+
     def register_closure(f):
         catalogue[name] = f
+
         def tmp(*args, **kwargs):
             return f(*args, **kwargs)
         return tmp
+
     return register_closure
 
+
 @register_action('hlite')
 def highlight_watched(filename):
     ''' File contents highlighter '''
                         TerminalFormatter(bg='dark'))
     print(content)
 
+
 @register_action('rsthtml')
 def view_rst_as_html(filename):
     ''' Function converting reStructuredText to HTML for display in browser '''
     docutils.core.publish_file(source_path=filename, destination_path=htmlfile,
                                writer_name='html')
 
+
 def ino_watch(file_to_watch, action, action_args=[], action_kwargs={}):
-    ''' ``inotify``-based watcher, applying function on modification events '''
+    ''' ``inotify``-based watcher, applying function upon
+        *write-and-close* events '''
     watcher = inotifyx.init()
     dirname = os.path.dirname(file_to_watch) or '.'
     basename = os.path.basename(file_to_watch)
             action(file_to_watch, *action_args, **action_kwargs)
         events = inotifyx.get_events(watcher)
 
+
 def main():
     ''' Mainloop function handling arguments and control flow '''
     usage = '''Usage: %prog [options] file_to_watch'''
     if len(args) > 1:
         print("How should I know what to watch from this list?\n"
               "Watching only first one, '%s'" % args[0])
-        sleep(7)
+        time.sleep(7)
     file_to_watch = args[0]
     action = implemented_actions.get(options.action)
     if not action:
     except KeyboardInterrupt:
         print('\nCaught keyboard interrupt, exiting')
 
+
 if __name__ == "__main__":
     main()
-
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.