Lint fixes
This commit is contained in:
parent
8539d69810
commit
8670a5e903
|
@ -28,6 +28,7 @@ def parse_qs():
|
||||||
class HTTPBasicAuth:
|
class HTTPBasicAuth:
|
||||||
username = None
|
username = None
|
||||||
password = None
|
password = None
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "<HTTPBasicAuth object username='%s' password='%s'>" % (self.username, self.password)
|
return "<HTTPBasicAuth object username='%s' password='%s'>" % (self.username, self.password)
|
||||||
|
|
||||||
|
|
12
get_backup
12
get_backup
|
@ -2,11 +2,11 @@
|
||||||
|
|
||||||
import traceback
|
import traceback
|
||||||
import os
|
import os
|
||||||
from sys import exit,stdin,stdout
|
from sys import exit, stdout
|
||||||
from os.path import join as pathjoin
|
from os.path import join as pathjoin
|
||||||
from os.path import exists, getsize
|
from os.path import exists, getsize
|
||||||
from common.cgi import parse_qs, parse_auth, start_response
|
from common.cgi import parse_qs, parse_auth, start_response
|
||||||
from common.datadb import DATADB_ROOT, DATADB_TMP, DATADB_DIR_TIMESTAMP_FORMAT
|
from common.datadb import DATADB_ROOT, DATADB_DIR_TIMESTAMP_FORMAT
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
|
|
||||||
|
@ -28,7 +28,8 @@ def get_backup_dir(backup_name):
|
||||||
|
|
||||||
def handle_head(backup_name):
|
def handle_head(backup_name):
|
||||||
try:
|
try:
|
||||||
backup_path = get_backup_dir(backup_name)
|
# backup_path = get_backup_dir(backup_name)
|
||||||
|
# TODO appropriate content-length for HEAD
|
||||||
start_response(extra_headers=['Content-length: 0'])
|
start_response(extra_headers=['Content-length: 0'])
|
||||||
except:
|
except:
|
||||||
start_response(status_code=("404", "Not Found",), extra_headers=['Content-length: 0'])
|
start_response(status_code=("404", "Not Found",), extra_headers=['Content-length: 0'])
|
||||||
|
@ -52,7 +53,8 @@ def handle_get_archive(backup_name):
|
||||||
backup_path = pathjoin(get_backup_dir(backup_name), 'backup.tar.gz')
|
backup_path = pathjoin(get_backup_dir(backup_name), 'backup.tar.gz')
|
||||||
|
|
||||||
with open(backup_path, 'rb') as f:
|
with open(backup_path, 'rb') as f:
|
||||||
start_response(content_type="application/x-gzip", extra_headers=["Content-length: %s" % getsize(backup_path),
|
start_response(content_type="application/x-gzip",
|
||||||
|
extra_headers=["Content-length: %s" % getsize(backup_path),
|
||||||
"Content-Disposition: attachment; filename=\"backup.tar.gz\""])
|
"Content-Disposition: attachment; filename=\"backup.tar.gz\""])
|
||||||
while True:
|
while True:
|
||||||
data = f.read(8192)
|
data = f.read(8192)
|
||||||
|
@ -69,7 +71,7 @@ def handle_req():
|
||||||
params = parse_qs()
|
params = parse_qs()
|
||||||
|
|
||||||
for param_name in ["proto", "name"]:
|
for param_name in ["proto", "name"]:
|
||||||
if not param_name in params:
|
if param_name not in params:
|
||||||
raise Exception("Missing parameter: %s" % param_name)
|
raise Exception("Missing parameter: %s" % param_name)
|
||||||
|
|
||||||
if os.environ['REQUEST_METHOD'] == "GET" and params["proto"] == "rsync":
|
if os.environ['REQUEST_METHOD'] == "GET" and params["proto"] == "rsync":
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
import os,sys,cgi
|
import os
|
||||||
|
import sys
|
||||||
import traceback
|
import traceback
|
||||||
from os import mkdir,rename,unlink,rmdir,utime,makedirs
|
from os import mkdir, rename, unlink, rmdir, utime
|
||||||
from os.path import exists
|
from os.path import exists
|
||||||
from os.path import join as pathjoin
|
from os.path import join as pathjoin
|
||||||
from common.cgi import parse_qs, parse_auth, start_response
|
from common.cgi import parse_qs, parse_auth, start_response
|
||||||
|
@ -204,7 +205,7 @@ def handle_req():
|
||||||
params = parse_qs()
|
params = parse_qs()
|
||||||
|
|
||||||
for param_name in ["proto", "name"]:
|
for param_name in ["proto", "name"]:
|
||||||
if not param_name in params:
|
if param_name not in params:
|
||||||
raise Exception("Missing parameter: %s" % param_name)
|
raise Exception("Missing parameter: %s" % param_name)
|
||||||
|
|
||||||
max_backups = int(params["keep"]) if "keep" in params else 5
|
max_backups = int(params["keep"]) if "keep" in params else 5
|
||||||
|
|
2
test
2
test
|
@ -3,11 +3,13 @@
|
||||||
import os
|
import os
|
||||||
from urllib.parse import parse_qs
|
from urllib.parse import parse_qs
|
||||||
|
|
||||||
|
|
||||||
def start_response(content_type="text/html", status_code=("200", "OK",)):
|
def start_response(content_type="text/html", status_code=("200", "OK",)):
|
||||||
print('Status: %s %s' % (status_code))
|
print('Status: %s %s' % (status_code))
|
||||||
print("Content-Type: %s" % content_type)
|
print("Content-Type: %s" % content_type)
|
||||||
print()
|
print()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
try:
|
try:
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue