Changeset 4741 for lang/python
- Timestamp:
- 01/17/08 02:34:56 (5 years ago)
- Files:
-
- 1 modified
-
lang/python/misc/woof (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lang/python/misc/woof
r4740 r4741 31 31 maxdownloads = 1 32 32 cpid = -1 33 compressed = True 33 compress_type_alist = {'tar.gz': 'tar czf - "$woof_file"', 34 'tar' : 'tar cf - "$woof_file"', 35 'zip' : 'zip -qr - "$woof_file"'} 36 compress_type = 'tar.gz' 34 37 35 38 … … 111 114 112 115 def do_GET (self): 113 global maxdownloads, cpid, compress ed116 global maxdownloads, cpid, compress_type 114 117 115 118 # Redirect any request to the filename of the file to serve. … … 119 122 location = "/" + urllib.quote (os.path.basename (self.filename)) 120 123 if os.path.isdir (self.filename): 121 if compressed: 122 location += ".tar.gz" 123 else: 124 location += ".tar" 124 location += ("." + compress_type) 125 125 126 126 if self.path != location: … … 157 157 elif os.path.isdir (self.filename): 158 158 os.environ['woof_dir'], os.environ['woof_file'] = os.path.split (self.filename) 159 if compressed: 160 arg = 'z' 161 else: 162 arg = '' 163 child = popen2.Popen3 ('cd "$woof_dir";tar c%sf - "$woof_file"' % arg) 159 cmdline = compress_type_alist[compress_type] 160 child = popen2.Popen3 ('cd "$woof_dir";%(cmdline)s' % locals()) 164 161 datafile = child.fromchild 165 162 … … 220 217 name = os.path.basename (sys.argv[0]) 221 218 print >>sys.stderr, """ 222 Usage: %s [-i <ip_addr>] [-p <port>] [-c <count>] [-u ] <file/dir>223 %s [-i <ip_addr>] [-p <port>] [-c <count>] [-u ] -s219 Usage: %s [-i <ip_addr>] [-p <port>] [-c <count>] [-u <suffix>] <file/dir> 220 %s [-i <ip_addr>] [-p <port>] [-c <count>] [-u <suffix>] -s 224 221 225 222 Serves a single file <count> times via http on port <port> on IP … … 242 239 count = 2 243 240 ip = 127.0.0.1 244 compress ed = true241 compress_type = 'tar.gz' 245 242 """ % (name, name, name, defmaxdown, defport) 246 243 if errmsg: … … 250 247 251 248 252 253 249 def main (): 254 global cpid, compress ed250 global cpid, compress_type 255 251 256 252 maxdown = 1 … … 270 266 ip_addr = config.get ('main', 'ip') 271 267 272 if config.has_option ('main', 'compress ed'):273 compress ed = config.getboolean ('main', 'compressed')268 if config.has_option ('main', 'compress_type'): 269 compress_type = config.get ('main', 'compress_type') 274 270 275 271 defaultport = port … … 277 273 278 274 try: 279 options, filenames = getopt.getopt (sys.argv[1:], "hsu i:c:p:")275 options, filenames = getopt.getopt (sys.argv[1:], "hsu:i:c:p:") 280 276 except getopt.GetoptError, desc: 281 277 usage (defaultport, defaultmaxdown, desc) … … 309 305 310 306 elif option == '-u': 311 compressed = False 312 307 if val[0] == ".": 308 val = val[1:] 309 try: 310 compress_type = val 311 compress_type_alist[compress_type] 312 except KeyError: 313 usage (defaultport, defaultmaxdown, 314 "acceptable suffix is: %s" % compress_type_alist.keys()) 313 315 else: 314 316 usage (defaultport, defaultmaxdown, "Unknown option: %r" % option) … … 345 347 except KeyboardInterrupt: 346 348 pass 347
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)