On Mon, Oct 28, 2002 at 01:19:54PM -0800, Michael S. Fischer wrote:

> This patch against tmda-pending 0.62 allows messages to be specified on
> standard input instead of the command line by using `-' instead of a
> message ID list.
> 
> Sample usage: 
> 
> tmda-pending -bT | grep 'foobar' | awk '{print $1}' | \
>   tmda-pending -br -

Sorry folks, that should have been a context diff.  Fixed patch
attached. 

-- 
Michael S. Fischer / michael at dynamine.net / +1 650-533-4684
Lead Hacketeer, Dynamine Consulting, Silicon Valley, CA
Index: tmda-pending
===================================================================
RCS file: /cvsroot/tmda/tmda/bin/tmda-pending,v
retrieving revision 1.28
diff -u -r1.28 tmda-pending
--- tmda-pending        27 Jun 2002 03:17:57 -0000      1.28
+++ tmda-pending        28 Oct 2002 23:41:42 -0000
@@ -21,7 +21,7 @@
 
 """Pending queue manipulation tool.
 
-Usage:  %(program)s [OPTIONS] [messages ... ]
+Usage:  %(program)s [OPTIONS] [messages ... | - ]
 
 Where:
     -c <file>
@@ -116,8 +116,10 @@
     --help
        Print this help message and exit.
 
-    messages
-       If one or more messages are provided, operate just on them.
+    messages | -
+       If one or more messages are provided, operate just on them. 
+       If `-' is specified, operate on a list of messages provided by
+         standard input.
        Otherwise, operate on all messages in the pending queue.
        
     Examples:
@@ -131,6 +133,9 @@
     (immediately release these messages from the pending queue)
     %(program)s -b -r 1012182077.5803.msg 1012939546.7870.msg
 
+    (immediately release any messages with `foobar' in them)
+    %(program)s -b -T | grep foobar | awk '{print $1}' | %(program)s -b -r -
+
     (immediately delete all messages from the pending queue)
     %(program)s -b -d
 
@@ -312,7 +317,19 @@
     os.chdir(os.path.join(Defaults.DATADIR, 'pending'))
 
     msgs = args
-    if not msgs:
+
+    # Replace any `-' in the message list with those messages provided via
+    # standard input.  (Since it's pointless to call it twice, it's safe
+    # to remove any subsequent occurrences in the list after processing.)
+    wantedstdin = 0
+    for msg in msgs:
+        if msg == '-':
+            wantedstdin = 1
+            for line in sys.stdin.readlines():
+                msgs.append(line.strip())
+            msgs.remove('-')
+
+    if not msgs and not wantedstdin:
         msgs = glob.glob('*.*.msg')
 
     msgs.sort()

Reply via email to