slight cleaning for webserver
This commit is contained in:
@@ -119,11 +119,11 @@ def add_single(conn,filename,change=False,hash=None,minsize=0,fullfile=False):
|
||||
if hash==None:
|
||||
hash=get_md5(filename,fullfile)
|
||||
ftime=os.path.getmtime(filename)
|
||||
mime=MIME.file(filename.encode('UTF-8'))
|
||||
mime=MIME.file(str(filename.encode('UTF-8')))
|
||||
except IOError:
|
||||
print("File '%s' not found. Bad link?"%(filename,))
|
||||
return
|
||||
except UnicodeDecodeError:
|
||||
except (UnicodeDecodeError, TypeError):
|
||||
mime="NA"
|
||||
|
||||
if change:
|
||||
|
||||
@@ -16,7 +16,9 @@ def setup_options():
|
||||
parser.add_argument("rootpath",type=str,action="store",default=os.path.abspath('.'),nargs='?',
|
||||
help="Root path of the server")
|
||||
options=parser.parse_args()
|
||||
|
||||
if not os.path.exists(options.rootpath):
|
||||
parser.error("Path does not exist")
|
||||
options.rootpath = os.path.abspath(options.rootpath)
|
||||
return options
|
||||
|
||||
|
||||
@@ -27,6 +29,7 @@ def serve(options):
|
||||
Protocol = "HTTP/1.0"
|
||||
|
||||
server_address = (options.address, options.port)
|
||||
|
||||
os.chdir(options.rootpath)
|
||||
|
||||
HandlerClass.protocol_version = Protocol
|
||||
@@ -37,9 +40,11 @@ def serve(options):
|
||||
try:
|
||||
httpd.serve_forever()
|
||||
except KeyboardInterrupt:
|
||||
pass
|
||||
httpd.server_close()
|
||||
except OSError:
|
||||
httpd.server_close()
|
||||
|
||||
if __name__ == "__main__":
|
||||
options=setup_options()
|
||||
serve(options)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user