From cb6ab9061962ad9db317910ab62f53c37a9a7be1 Mon Sep 17 00:00:00 2001 From: dave Date: Sat, 26 Dec 2015 21:41:51 -0800 Subject: [PATCH] cleanup --- common/cgi.py | 23 +++++------------------ get_backup | 3 +-- new_backup | 6 ++++-- 3 files changed, 10 insertions(+), 22 deletions(-) diff --git a/common/cgi.py b/common/cgi.py index 7817c96..c545666 100755 --- a/common/cgi.py +++ b/common/cgi.py @@ -1,10 +1,11 @@ #!/usr/bin/env python3 import os -from urllib.parse import parse_qs as _parse_qs -from base64 import b64decode import sys import traceback +from urllib.parse import parse_qs as _parse_qs +from base64 import b64decode + def start_response(content_type="text/html", status_code=("200", "OK",), extra_headers=[]): print('Status: %s %s' % (status_code)) @@ -23,12 +24,14 @@ def parse_qs(): GET = {k:v[0] for k,v in GET.items()} return GET + class HTTPBasicAuth: username = None password = None def __str__(self): return "" % (self.username, self.password) + def parse_auth(): if "HTTP_AUTHORIZATION" in os.environ: authtype, value = os.environ["HTTP_AUTHORIZATION"].split(' ') @@ -37,20 +40,4 @@ def parse_auth(): auth.username, auth.password = b64decode(value).decode().split(":") return auth -def fulltrace(): - """Return the stack trace of the bot as a string""" - result = "" - result += "\n*** STACKTRACE - START ***\n" - code = [] - for threadId, stack in sys._current_frames().items(): - code.append("\n# ThreadID: %s" % threadId) - for filename, lineno, name, line in traceback.extract_stack(stack): - code.append('File: "%s", line %d, in %s' % (filename, lineno, name)) - if line: - code.append(" %s" % (line.strip())) - for line in code: - result += line + "\n" - result += "\n*** STACKTRACE - END ***\n" - return result - # cgi.print_environ() \ No newline at end of file diff --git a/get_backup b/get_backup index 47c1ac2..c2f35d5 100755 --- a/get_backup +++ b/get_backup @@ -1,11 +1,10 @@ #!/usr/bin/env python3 import traceback -from sys import exit,stdin,stdout import os +from sys import exit,stdin,stdout from os.path import join as pathjoin from os.path import exists,getsize - from common.cgi import parse_qs,parse_auth,start_response from common.datadb import DATADB_ROOT,DATADB_TMP diff --git a/new_backup b/new_backup index f693467..0155344 100755 --- a/new_backup +++ b/new_backup @@ -1,15 +1,16 @@ #!/usr/bin/env python3 import os,sys,cgi +import traceback from os import mkdir,rename,unlink from os.path import exists from os.path import join as pathjoin -from common.cgi import parse_qs,parse_auth,start_response,fulltrace +from common.cgi import parse_qs,parse_auth,start_response from common.datadb import DATADB_ROOT,DATADB_TMP from shutil import rmtree from subprocess import Popen,PIPE from time import time -import traceback + def rotate_backups(backup_dir, sync_prev=False, max_backups=5): """ @@ -158,6 +159,7 @@ def handle_req(): else: raise Exception("Invalid request. Params: %s" % params) + if __name__ == "__main__": try: handle_req()