cleanup
This commit is contained in:
parent
1ef031e381
commit
cb6ab90619
|
@ -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 "<HTTPBasicAuth object username='%s' password='%s'>" % (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()
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue