Skip to content

Commit

Permalink
Clean up usage and make PEP8 happy
Browse files Browse the repository at this point in the history
  • Loading branch information
justinmayhew committed Oct 26, 2013
1 parent b0a3d11 commit cfd20f6
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 28 deletions.
20 changes: 10 additions & 10 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

from distutils.core import setup

setup( name='When-changed',
version='0.2.0',
description='Run a command when a file is changed',
author='Johannes H. Jensen',
url='https://github.com/joh/when-changed',
packages=['whenchanged'],
scripts=['when-changed'],
requires=['pyinotify'],
license = 'BSD'
)
setup(name='When-changed',
version='0.2.0',
description='Run a command when a file is changed',
author='Johannes H. Jensen',
url='https://github.com/joh/when-changed',
packages=['whenchanged'],
scripts=['when-changed'],
requires=['pyinotify'],
license='BSD'
)
2 changes: 1 addition & 1 deletion when-changed
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python

from whenchanged.whenchanged import main
from whenchanged.whenchanged import main
main()
29 changes: 12 additions & 17 deletions whenchanged/whenchanged.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#!/usr/bin/env python
"""
when-changed - run a command when a file is changed
"""%(prog)s - run a command when a file is changed
Usage: %(prog)s [-r] FILE COMMAND...
%(prog)s [-r] FILE [FILE ...] -c COMMAND
Usage: when-changed [-r] FILE COMMAND...
when-changed [-r] FILE [FILE ...] -c COMMAND
FILE can be a directory. Watch recursively with -r.
Use %%f to pass the filename to the command.
Copyright (c) 2011, Johannes H. Jensen.
License: BSD, see LICENSE for more details.
Expand All @@ -15,6 +17,7 @@
import re
import pyinotify


class WhenChanged(pyinotify.ProcessEvent):
# Exclude Vim swap files, its file creation test file 4913 and backup files
exclude = re.compile(r'^\..*\.sw[px]*$|^4913$|.~$')
Expand Down Expand Up @@ -64,7 +67,8 @@ def run(self):
for p in self.paths:
if os.path.isdir(p) and not p in watched:
# Add directory
wdd = wm.add_watch(p, mask, rec=self.recursive, auto_add=self.recursive)
wdd = wm.add_watch(p, mask, rec=self.recursive,
auto_add=self.recursive)
else:
# Add parent directory
path = os.path.dirname(p)
Expand All @@ -74,25 +78,16 @@ def run(self):
notifier.loop()


usage = 'Usage: %(prog)s [-r] FILE COMMAND...\n'
usage += ' %(prog)s [-r] FILE [FILE ...] -c COMMAND...'
description = 'Run a command when a file is changed.\n'
description += 'FILE can be a directory. Watch recursively with -r.\n'
description += 'Use %f to pass the filename to the command.\n'

def print_usage(prog):
print(usage % {'prog': prog})
print(__doc__ % {'prog': prog}, end='')

def print_help(prog):
print_usage(prog)
print("\n" + description)

def main():
args = sys.argv
prog = args.pop(0)
prog = os.path.basename(args.pop(0))

if '-h' in args or '--help' in args:
print_help(prog)
print_usage(prog)
exit(0)

files = []
Expand Down

0 comments on commit cfd20f6

Please sign in to comment.