a41fd22e80cb v1.0.1

Merge.
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Wed, 09 Dec 2015 13:54:53 +0000
parents c4f5cf1bfffd (diff) 6399abfdb127 (current diff)
children c34d05425c3f
branches/tags v1.0.1
files peat

Changes

--- a/.hgtags	Mon Dec 23 01:05:44 2013 +0200
+++ b/.hgtags	Wed Dec 09 13:54:53 2015 +0000
@@ -2,3 +2,4 @@
 6ba80dea59944ba46c8538322052c5f3259cc979 v0.2.0
 0e92c9363422df88fb493d3546fa6309eb60f7af v0.2.1
 6cdd3ed3ef128c6c6a875e93f48b3fff684cfbc3 v0.3.0
+f421e218452df1230a276b1a6ad62063640e93d0 v1.0.0
--- a/README.markdown	Mon Dec 23 01:05:44 2013 +0200
+++ b/README.markdown	Wed Dec 09 13:54:53 2015 +0000
@@ -57,26 +57,15 @@
 newly created files without having to restart it) you can use the `--dynamic`
 option.
 
-Instead of piping in the list of files to watch, you'll pipe in a *command* that
-`peat` will run to generate the list before every check.  For example:
+Instead of piping in the list of files to watch, you'll specify a *command* that
+`peat` will run to generate the list before every check (as well as the actual
+command to run, of course).  For example:
 
     $ ffind ".markdown$"
     ./foo.markdown
     ./bar/baz.markdown
 
-    $ echo 'ffind ".markdown$"'
-    ffind ".markdown$"
-
-    $ echo 'ffind ".markdown$"' | peat --dynamic 'echo "A file changed!"'
-
-If your command contains quotes you'll need to make sure they get passed
-into peat properly.  For example, the following will **not** work:
-
-    $ echo "find . -name '*.markdown'" | peat --dynamic ...
-
-The problem is that the shell will expand the `*` in the double-quoted string
-before it ever gets to `peat`.  Google around and learn about shell quoting if
-you don't understand.  This can be tricky.  You've been warned.
+    $ peat --dynamic 'ffind ".markdown$"' 'echo "A file changed!"'
 
 ### Full Usage
 
@@ -94,17 +83,11 @@
         find . -name '*.py' | peat 'rm *.pyc'
         find . -name '*.py' -print0 | peat -0 'rm *.pyc'
 
-    If --dynamic is given, a command to generate the list should be piped in
-    on standard input instead.  It will be used to generate the list of files
-    to check before each run.
+    If --dynamic is used, the given command will be run each time to generate the
+    list of files to check:
 
-    This command must be quoted properly, and this can be tricky.  Make sure
-    you know what you're doing.
-
-    For example:
-
-        echo find . | peat --dynamic './test.sh'
-        echo find . -name '*.py' | peat --dynamic 'rm *.pyc'
+        peat --dynamic 'find .' './test.sh'
+        peat --dynamic 'find . -name '\''*.py'\''' 'rm *.pyc'
 
 
     Options:
@@ -112,18 +95,18 @@
       -i N, --interval=N    interval between checks in milliseconds
       -I, --smart-interval  determine the interval based on number of files
                             watched (default)
-      -d, --dynamic         take a command on standard input to generate the list
-                            of files to watch
+      -d COMMAND, --dynamic=COMMAND
+                            run COMMAND before each run to generate the list of
+                            files to check
       -D, --no-dynamic      take a list of files to watch on standard in (default)
       -c, --clear           clear screen before runs (default)
       -C, --no-clear        don't clear screen before runs
       -v, --verbose         show extra logging output (default)
       -q, --quiet           don't show extra logging output
-      -w, --whitespace      assume paths on stdin are separated by whitespace
-                            (default)
-      -n, --newlines        assume paths on stdin are separated by newlines
-      -s, --spaces          assume paths on stdin are separated by spaces
-      -0, --zero            assume paths on stdin are separated by null bytes
+      -w, --whitespace      assume paths are separated by whitespace (default)
+      -n, --newlines        assume paths are separated by newlines
+      -s, --spaces          assume paths are separated by spaces
+      -0, --zero            assume paths are separated by null bytes
 
 License
 -------
--- a/peat	Mon Dec 23 01:05:44 2013 +0200
+++ b/peat	Wed Dec 09 13:54:53 2015 +0000
@@ -23,11 +23,9 @@
 clear = True
 get_paths = lambda: set()
 verbose = True
-dynamic = False
-paths_command = None
+dynamic = None
 
-USAGE = """\
-usage: %prog [options] COMMAND
+USAGE = r"""usage: %prog [options] COMMAND
 
 COMMAND should be given as a single argument using a shell string.
 
@@ -39,17 +37,11 @@
     find . -name '*.py' | peat 'rm *.pyc'
     find . -name '*.py' -print0 | peat -0 'rm *.pyc'
 
-If --dynamic is given, a command to generate the list should be piped in
-on standard input instead.  It will be used to generate the list of files
-to check before each run.
+If --dynamic is used, the given command will be run each time to generate the
+list of files to check:
 
-This command must be quoted properly, and this can be tricky.  Make sure
-you know what you're doing.
-
-For example:
-
-    echo find . | peat --dynamic './test.sh'
-    echo find . -name '*.py' | peat --dynamic 'rm *.pyc'
+    peat --dynamic 'find .' './test.sh'
+    peat --dynamic 'find . -name '\''*.py'\''' 'rm *.pyc'
 """
 
 
@@ -90,36 +82,40 @@
     p.add_option('-I', '--smart-interval', dest='interval',
                  action='store_const', const=None,
                  help='determine the interval based on number of files watched (default)')
-    p.add_option('-d', '--dynamic', default=False,
-                 action='store_true',
-                 help='take a command on standard input to generate the list of files to watch')
+
+    p.add_option('-d', '--dynamic', default=None,
+                 help='run COMMAND before each run to generate the list of files to check',
+                 metavar='COMMAND')
     p.add_option('-D', '--no-dynamic', dest='dynamic',
-                 action='store_false',
+                 action='store_const', const=None,
                  help='take a list of files to watch on standard in (default)')
+
     p.add_option('-c', '--clear', default=True,
                  action='store_true', dest='clear',
                  help='clear screen before runs (default)')
     p.add_option('-C', '--no-clear',
                  action='store_false', dest='clear',
                  help="don't clear screen before runs")
+
     p.add_option('-v', '--verbose', default=True,
                  action='store_true', dest='verbose',
                  help='show extra logging output (default)')
     p.add_option('-q', '--quiet',
                  action='store_false', dest='verbose',
                  help="don't show extra logging output")
+
     p.add_option('-w', '--whitespace', default=None,
                  action='store_const', dest='sep', const=None,
-                 help="assume paths on stdin are separated by whitespace (default)")
+                 help="assume paths are separated by whitespace (default)")
     p.add_option('-n', '--newlines',
                  action='store_const', dest='sep', const='\n',
-                 help="assume paths on stdin are separated by newlines")
+                 help="assume paths are separated by newlines")
     p.add_option('-s', '--spaces',
                  action='store_const', dest='sep', const=' ',
-                 help="assume paths on stdin are separated by spaces")
+                 help="assume paths are separated by spaces")
     p.add_option('-0', '--zero',
                  action='store_const', dest='sep', const='\0',
-                 help="assume paths on stdin are separated by null bytes")
+                 help="assume paths are separated by null bytes")
 
     return p
 
@@ -127,7 +123,7 @@
 def _main():
     if dynamic:
         log("Running the following command to generate watch list:")
-        log('  ' + paths_command)
+        log('  ' + dynamic)
         log('')
 
     log("Watching the following paths:")
@@ -178,7 +174,7 @@
     return paths
 
 def main():
-    global interval, command, clear, get_paths, verbose, dynamic, paths_command
+    global interval, command, clear, get_paths, verbose, dynamic
 
     (options, args) = build_option_parser().parse_args()
 
@@ -192,13 +188,8 @@
     dynamic = options.dynamic
 
     if dynamic:
-        paths_command = sys.stdin.read().rstrip()
-
-        if not paths_command:
-            die("no command to generate watch list was given on standard input")
-
         def _get_paths():
-            data = subprocess.check_output(paths_command, shell=True)
+            data = subprocess.check_output(dynamic, shell=True)
             return _parse_paths(sep, data)
 
         get_paths = _get_paths