Package: woof
Version: 20091227-1
Severity: wishlist
Tags: patch

I added a patch to get stdin support, allowing to use woof directly from mutt 
(serving attached files, for example).

-- System Information:
Debian Release: wheezy/sid
  APT prefers testing
  APT policy: (900, 'testing'), (900, 'stable'), (1, 'experimental'), (1, 
'unstable'), (1, 'testing'), (1, 'stable')
Architecture: amd64 (x86_64)

Kernel: Linux 2.6.39-2-amd64 (SMP w/2 CPU cores)
Locale: LANG=C, LC_CTYPE=C (charmap=UTF-8) (ignored: LC_ALL set to fr_FR.UTF-8)
Shell: /bin/sh linked to /bin/dash

Versions of packages woof depends on:
ii  python                        2.6.7-2    interactive high-level object-orie

woof recommends no packages.

woof suggests no packages.

-- no debconf information
>From 0ad2a1ce128423177030a8c15cc05e9e6b40c00b Mon Sep 17 00:00:00 2001
From: Hugues Hiegel <hug...@hiegel.fr>
Date: Tue, 7 Jun 2011 18:24:10 +0200
Subject: [PATCH] adds stdin support

---
 woof |   39 ++++++++++++++++++++++++---------------
 1 files changed, 24 insertions(+), 15 deletions(-)

diff --git a/woof b/woof
index 770231c..d1474b7 100644
--- a/woof
+++ b/woof
@@ -123,7 +123,7 @@ class FileServHTTPRequestHandler (BaseHTTPServer.BaseHTTPRequestHandler):
    server_version = "Simons FileServer"
    protocol_version = "HTTP/1.0"
 
-   filename = "."
+   filename = "-"
 
    def log_request (self, code='-', size='-'):
       if code == 200:
@@ -203,7 +203,7 @@ class FileServHTTPRequestHandler (BaseHTTPServer.BaseHTTPRequestHandler):
       maxdownloads -= 1
 
       return
-      
+
 
    def do_GET (self):
       global maxdownloads, cpid, compressed, upload
@@ -269,14 +269,16 @@ class FileServHTTPRequestHandler (BaseHTTPServer.BaseHTTPRequestHandler):
          # Child process
          child = None
          type = None
-         
+
          if os.path.isfile (self.filename):
             type = "file"
          elif os.path.isdir (self.filename):
             type = "dir"
+         elif self.filename == "-":
+            type = "stdin"
 
          if not type:
-            print >> sys.stderr, "can only serve files or directories. Aborting."
+            print >> sys.stderr, "can only serve files, directories or stdin. Aborting."
             sys.exit (1)
 
          self.send_response (200)
@@ -310,6 +312,9 @@ class FileServHTTPRequestHandler (BaseHTTPServer.BaseHTTPRequestHandler):
                   tfile.add (self.filename,
                              arcname=os.path.basename(self.filename))
                   tfile.close ()
+            elif type == "stdin":
+               datafile = sys.stdin
+               shutil.copyfileobj (datafile, self.wfile)
          except Exception, e:
             print e
             print >>sys.stderr, "Connection broke. Aborting"
@@ -345,13 +350,14 @@ def serve_files (filename, maxdown = 1, ip_addr = '', port = 8080):
 def usage (defport, defmaxdown, errmsg = None):
    name = os.path.basename (sys.argv[0])
    print >>sys.stderr, """
-    Usage: %s [-i <ip_addr>] [-p <port>] [-c <count>] <file>
+    Usage: %s [-i <ip_addr>] [-p <port>] [-c <count>] [<file>]
            %s [-i <ip_addr>] [-p <port>] [-c <count>] [-z|-j|-Z|-u] <dir>
            %s [-i <ip_addr>] [-p <port>] [-c <count>] -s
            %s [-i <ip_addr>] [-p <port>] [-c <count>] -U
    
     Serves a single file <count> times via http on port <port> on IP
     address <ip_addr>.
+    When no filename is specified, or set to '-', then stdin will be read.
     When a directory is specified, an tar archive gets served. By default
     it is gzip compressed. You can specify -z for gzip compression, 
     -j for bzip2 compression, -Z for ZIP compression or -u for no compression.
@@ -360,6 +366,7 @@ def usage (defport, defmaxdown, errmsg = None):
 
     When -s is specified instead of a filename, %s distributes itself.
 
+
     When -U is specified, woof provides an upload form and allows uploading files.
    
     defaults: count = %d, port = %d
@@ -392,6 +399,8 @@ def main ():
    port = 8080
    ip_addr = ''
 
+   filename = '-'
+
    config = ConfigParser.ConfigParser()
    config.read (['/etc/woofrc', os.path.expanduser('~/.woofrc')])
 
@@ -473,18 +482,18 @@ def main ():
 
    else:
       if len (filenames) == 1:
-         filename = os.path.abspath (filenames[0])
-      else:
-         usage (defaultport, defaultmaxdown,
-                "Can only serve single files/directories.")
+         if filenames[0] != "-":
+            filename = os.path.abspath (filenames[0])
 
-      if not os.path.exists (filename):
-         usage (defaultport, defaultmaxdown,
-                "%s: No such file or directory" % filenames[0])
+            if not os.path.exists (filename):
+               usage (defaultport, defaultmaxdown,
+                      "Can only serve single files/directories.")
 
-      if not (os.path.isfile (filename) or os.path.isdir (filename)):
-         usage (defaultport, defaultmaxdown,
-                "%s: Neither file nor directory" % filenames[0])
+            if not (os.path.isfile (filename) or os.path.isdir (filename)):
+               usage (defaultport, defaultmaxdown,
+                      "%s: Neither file nor directory" % filenames[0])
+         else:
+            filename = "-"
 
    serve_files (filename, maxdown, ip_addr, port)
 
-- 
1.7.5.4

Reply via email to