Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 21 Aug 2011 03:30:39 GMT
From:      Nicole Reid <root@cooltrainer.org>
To:        freebsd-gnats-submit@FreeBSD.org
Subject:   ports/159951: [patch] www/woof to support Python 2.7
Message-ID:  <201108210330.p7L3UdpN070143@red.freebsd.org>
Resent-Message-ID: <201108210340.p7L3e6F3076243@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         159951
>Category:       ports
>Synopsis:       [patch] www/woof to support Python 2.7
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-ports-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Sun Aug 21 03:40:06 UTC 2011
>Closed-Date:
>Last-Modified:
>Originator:     Nicole Reid
>Release:        8.2 amd64
>Organization:
>Environment:
>Description:
woof.py is broken under Python 2.7.



[nicole@emi#Desktop]woof WOHDTeamLogos.zip
Now serving on http://172.16.0.40:8080/
Ashlotte.aloe.cooltrainer.org - - [20/Aug/2011 23:21:35] "GET /WOHDTeamLogos.zip HTTP/1.1" 200 -
----------------------------------------
Exception happened during processing of request from ('172.16.0.202', 58655)
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/SocketServer.py", line 284, in _handle_request_noblock
    self.process_request(request, client_address)
  File "/usr/local/lib/python2.7/SocketServer.py", line 310, in process_request
    self.finish_request(request, client_address)
  File "/usr/local/lib/python2.7/SocketServer.py", line 323, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "/usr/local/lib/python2.7/SocketServer.py", line 641, in __init__
    self.finish()
  File "/usr/local/lib/python2.7/SocketServer.py", line 694, in finish
    self.wfile.flush()
  File "/usr/local/lib/python2.7/socket.py", line 303, in flush
    self._sock.sendall(view[write_offset:write_offset+buffer_size])
error: [Errno 32] Broken pipe
----------------------------------------

>How-To-Repeat:

>Fix:
Apply the included patch.






[nicole@emi#Desktop]woof WOHDTeamLogos.zip 
Now serving on http://172.16.0.40:8080/
Ashlotte.aloe.cooltrainer.org - - [20/Aug/2011 23:20:31] "GET /WOHDTeamLogos.zip HTTP/1.1" 200 -

[nicole@emi#Desktop]python --version
Python 2.7.2



Patch submitted upstream as well.

Patch attached with submission follows:

diff -ruN woof.orig/Makefile woof/Makefile
--- woof.orig/Makefile	2011-03-24 22:51:51.034872251 -0400
+++ woof/Makefile	2011-08-20 23:21:50.768190102 -0400
@@ -22,7 +22,17 @@
 NO_BUILD=	yes
 PLIST_FILES=	bin/woof
 
+.include <bsd.port.pre.mk>
+
+.if ${PYTHON_REL} >= 270
+EXTRA_PATCHES+=	${FILESDIR}/extra-patch-woof-2009-12-27-python27.diff
+.endif
+
+do-extract:
+	@${MKDIR} ${WRKSRC}
+	@${CP} ${DISTDIR}/${DISTFILES} ${WRKSRC}/${DISTFILES}
+
 do-install:
-	${INSTALL_SCRIPT} ${DISTDIR}/${DISTFILES} ${PREFIX}/bin/woof
+	${INSTALL_SCRIPT} ${WRKSRC}/${DISTFILES} ${PREFIX}/bin/woof
 
-.include <bsd.port.mk>
+.include <bsd.port.post.mk>
diff -ruN woof.orig/distinfo woof/distinfo
--- woof.orig/distinfo	2011-03-24 22:51:51.034872251 -0400
+++ woof/distinfo	2011-03-24 23:24:59.827591181 -0400
@@ -1,2 +1,4 @@
 SHA256 (woof-2009-12-27.py) = 21086b67489381b477c9c0567b1d9f8b8f1deec12bd4e414969e3f155c1ff889
 SIZE (woof-2009-12-27.py) = 16810
+SHA256 (/usr/ports/www/woof/files/extra-patch-woof-2009-12-27-python3.diff) = 0088ba2641d02b5fece1a4320294bf29ea550d54acc31f9ce6bb8d4831884c14
+SIZE (/usr/ports/www/woof/files/extra-patch-woof-2009-12-27-python3.diff) = 8381
diff -ruN woof.orig/files/extra-patch-woof-2009-12-27-python27.diff woof/files/extra-patch-woof-2009-12-27-python27.diff
--- woof.orig/files/extra-patch-woof-2009-12-27-python27.diff	1969-12-31 19:00:00.000000000 -0500
+++ woof/files/extra-patch-woof-2009-12-27-python27.diff	2011-03-25 00:56:22.276193564 -0400
@@ -0,0 +1,190 @@
+--- woof-2009-12-27.py.orig	2009-12-27 23:47:43.000000000 +0100
++++ woof-2009-12-27.py	2011-02-08 20:38:51.150000040 +0100
+@@ -28,13 +28,13 @@
+ 
+ import sys, os, errno, socket, getopt, commands, tempfile
+ import cgi, urllib, BaseHTTPServer
++from SocketServer import ThreadingMixIn
+ import ConfigParser
+ import shutil, tarfile, zipfile
+ import struct
+ 
+ maxdownloads = 1
+ TM = object
+-cpid = -1
+ compressed = 'gz'
+ upload = False
+ 
+@@ -137,6 +137,11 @@ class FileServHTTPRequestHandler (BaseHT
+          self.send_error (501, "Unsupported method (POST)")
+          return
+       
++      maxdownloads -= 1
++
++      if maxdownloads < 1:
++         httpd.shutdown()
++
+       # taken from
+       # http://mail.python.org/pipermail/python-list/2006-September/402441.html
+ 
+@@ -200,13 +205,11 @@ class FileServHTTPRequestHandler (BaseHT
+       self.end_headers ()
+       self.wfile.write (txt)
+ 
+-      maxdownloads -= 1
+-
+       return
+       
+ 
+    def do_GET (self):
+-      global maxdownloads, cpid, compressed, upload
++      global maxdownloads, compressed, upload
+ 
+       # Form for uploading a file
+       if upload:
+@@ -260,63 +263,62 @@ class FileServHTTPRequestHandler (BaseHT
+ 
+       maxdownloads -= 1
+ 
+-      # let a separate process handle the actual download, so that
+-      # multiple downloads can happen simultaneously.
++      if maxdownloads < 1:
++         httpd.shutdown()
+ 
+-      cpid = os.fork ()
++      type = None
++      
++      if os.path.isfile (self.filename):
++         type = "file"
++      elif os.path.isdir (self.filename):
++         type = "dir"
+ 
+-      if cpid == 0:
+-         # Child process
+-         child = None
+-         type = None
+-         
+-         if os.path.isfile (self.filename):
+-            type = "file"
+-         elif os.path.isdir (self.filename):
+-            type = "dir"
++      if not type:
++         print >> sys.stderr, "can only serve files or directories. Aborting."
++         sys.exit (1)
+ 
+-         if not type:
+-            print >> sys.stderr, "can only serve files or directories. Aborting."
+-            sys.exit (1)
++      self.send_response (200)
++      self.send_header ("Content-Type", "application/octet-stream")
++      if os.path.isfile (self.filename):
++         self.send_header ("Content-Length",
++                           os.path.getsize (self.filename))
++      self.end_headers ()
+ 
+-         self.send_response (200)
+-         self.send_header ("Content-Type", "application/octet-stream")
+-         if os.path.isfile (self.filename):
+-            self.send_header ("Content-Length",
+-                              os.path.getsize (self.filename))
+-         self.end_headers ()
++      try:
++         if type == "file":
++            datafile = file (self.filename)
++            shutil.copyfileobj (datafile, self.wfile)
++            datafile.close ()
++         elif type == "dir":
++            if compressed == 'zip':
++               ezfile = EvilZipStreamWrapper (self.wfile)
++               zfile = zipfile.ZipFile (ezfile, 'w', zipfile.ZIP_DEFLATED)
++               stripoff = os.path.dirname (self.filename) + os.sep
+ 
+-         try:
+-            if type == "file":
+-               datafile = file (self.filename)
+-               shutil.copyfileobj (datafile, self.wfile)
+-               datafile.close ()
+-            elif type == "dir":
+-               if compressed == 'zip':
+-                  ezfile = EvilZipStreamWrapper (self.wfile)
+-                  zfile = zipfile.ZipFile (ezfile, 'w', zipfile.ZIP_DEFLATED)
+-                  stripoff = os.path.dirname (self.filename) + os.sep
++               for root, dirs, files in os.walk (self.filename):
++                  for f in files:
++                     filename = os.path.join (root, f)
++                     if filename[:len (stripoff)] != stripoff:
++                        raise RuntimeException, "invalid filename assumptions, please report!"
++                     zfile.write (filename, filename[len (stripoff):])
++               zfile.close ()
++            else:
++               tfile = tarfile.open (mode=('w|' + compressed),
++                                     fileobj=self.wfile)
++               tfile.add (self.filename,
++                          arcname=os.path.basename(self.filename))
++               tfile.close ()
++      except Exception, e:
++         print e
++         print >>sys.stderr, "Connection broke. Aborting"
+ 
+-                  for root, dirs, files in os.walk (self.filename):
+-                     for f in files:
+-                        filename = os.path.join (root, f)
+-                        if filename[:len (stripoff)] != stripoff:
+-                           raise RuntimeException, "invalid filename assumptions, please report!"
+-                        zfile.write (filename, filename[len (stripoff):])
+-                  zfile.close ()
+-               else:
+-                  tfile = tarfile.open (mode=('w|' + compressed),
+-                                        fileobj=self.wfile)
+-                  tfile.add (self.filename,
+-                             arcname=os.path.basename(self.filename))
+-                  tfile.close ()
+-         except Exception, e:
+-            print e
+-            print >>sys.stderr, "Connection broke. Aborting"
++
++class ThreadedHTTPServer(ThreadingMixIn, BaseHTTPServer.HTTPServer):
++   """Handle requests in a separate thread"""
+ 
+ 
+ def serve_files (filename, maxdown = 1, ip_addr = '', port = 8080):
+-   global maxdownloads
++   global maxdownloads, httpd
+ 
+    maxdownloads = maxdown
+ 
+@@ -326,8 +328,7 @@ def serve_files (filename, maxdown = 1, 
+    FileServHTTPRequestHandler.filename = filename
+ 
+    try:
+-      httpd = BaseHTTPServer.HTTPServer ((ip_addr, port),
+-                                         FileServHTTPRequestHandler)
++      httpd = ThreadedHTTPServer ((ip_addr, port), FileServHTTPRequestHandler)
+    except socket.error:
+       print >>sys.stderr, "cannot bind to IP address '%s' port %d" % (ip_addr, port)
+       sys.exit (1)
+@@ -337,8 +338,7 @@ def serve_files (filename, maxdown = 1, 
+    if ip_addr:
+       print "Now serving on http://%s:%s/" % (ip_addr, httpd.server_port)
+ 
+-   while cpid != 0 and maxdownloads > 0:
+-      httpd.handle_request ()
++   httpd.serve_forever ()
+ 
+ 
+ 
+@@ -488,14 +488,6 @@ def main ():
+ 
+    serve_files (filename, maxdown, ip_addr, port)
+ 
+-   # wait for child processes to terminate
+-   if cpid != 0:
+-      try:
+-         while 1:
+-            os.wait ()
+-      except OSError:
+-         pass
+-
+ 
+ 
+ if __name__=='__main__':


>Release-Note:
>Audit-Trail:
>Unformatted:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201108210330.p7L3UdpN070143>