Usage:
Input address: for example, http: // 0.0.0.0: 8000? ABC, def
#! Usr/bin/Python
# Coding = UTF-8
Import UUID
Import OS
Import zipfile
Import re
Import sys
Import officetoimage
Import rarfile
Import tarfile
Import subprocess
From cherrypy import wsgiserver
Import time
Import threading
######## Set code to deal Chinese ############
Default_encoding = 'utf-8'
If SYS. getdefaultencoding ()! = Default_encoding:
Reload (sys)
SYS. setdefaultencoding (default_encoding)
Def app (Environ, start_response ):
Out = 'tmp/'{str(uid.uuid1({{}'.zip'
Status = '100 OK'
Filename = 'test.zip'
Response_header = [('content-type', 'application/'+ out), ('content-disposition', 'attachment; filename =' + filename)]
Start_response (status, response_header)
# Dict_e = get_environ ()
Filename_list = environ ['query _ string']. Split (',')
If OS. Path. exists ('tmp ') is not true:
OS. makedirs ('tmp ', 0755)
Position = 0
Flag = true
Archive = zipfile. zipfile (Out, 'A', zipfile. zip_deflated)
STRs = open (Out, 'rb ')
For filename in filename_list:
If OS. Path. isfile (filename ):
Archive. Write (filename)
STRs. Seek (position)
Result = STRs. Read ()
Position = STRs. Tell ()
Yield result
Else:
For root, dirs, files in OS. Walk (filename ):
For file in files:
Archive. Write (OS. Path. Join (root, file ))
STRs. Seek (position)
Result = STRs. Read ()
Position = STRs. Tell ()
Yield result
Archive. Close ()
STRs. Seek (position)
Result = STRs. Read ()
Position = STRs. Tell ()
Yield result
Return
If _ name _ = '_ main __':
Server = wsgiserver. cherrypywsgiserver ('0. 0.0.0 ', 8000), APP)
Server. Start ()