slight cleaning for webserver

This commit is contained in:
ville rantanen
2018-11-20 23:00:43 +02:00
parent d8c6a73fab
commit c35fee7989
2 changed files with 14 additions and 9 deletions

View File

@@ -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:

View File

@@ -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)