home
·
contact
·
privacy
projects
/
misc
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Improve /fix accounting scripts.
[misc]
/
plomlib.py
diff --git
a/plomlib.py
b/plomlib.py
index 92bfb8535d7604bc1e47f0595cc68fd28e433283..18c2f185ec615a6dc61c6232bdf19b585499668b 100644
(file)
--- a/
plomlib.py
+++ b/
plomlib.py
@@
-27,6
+27,9
@@
class PlomDB:
def backup(self):
import shutil
from datetime import datetime, timedelta
def backup(self):
import shutil
from datetime import datetime, timedelta
+ if not os.path.exists(self.db_file):
+ return
+
# collect modification times of numbered .bak files
bak_prefix = f'{self.db_file}.bak.'
backup_dates = []
# collect modification times of numbered .bak files
bak_prefix = f'{self.db_file}.bak.'
backup_dates = []
@@
-77,25
+80,17
@@
class PlomDB:
self.unlock()
self.unlock()
-class PlomServer(BaseHTTPRequestHandler):
+class PlomHandler(BaseHTTPRequestHandler):
+ homepage = '/'
+ html_head = '<!DOCTYPE html>\n<html>\n<meta charset="UTF-8">'
+ html_foot = '</body>\n</html>'
- def __init__(self, *args, **kwargs):
- self.html_head = ['<!DOCTYPE html>\n<html>\n<meta charset="UTF-8">']
- self.html_foot = ['</body>\n</html>']
- self.pre_init()
- super().__init__(*args, **kwargs)
-
- def pre_init(self):
- pass
-
def fail_400(self, e):
self.send_HTML(f'ERROR: {e}', 400)
def send_HTML(self, html, code=200):
self.send_code_and_headers(code, [('Content-type', 'text/html')])
def fail_400(self, e):
self.send_HTML(f'ERROR: {e}', 400)
def send_HTML(self, html, code=200):
self.send_code_and_headers(code, [('Content-type', 'text/html')])
- header = '\n'.join(self.html_head)
- footer = '\n'.join(self.html_foot)
- self.wfile.write(bytes(f'{header}\n{html}\n{footer}', 'utf-8'))
+ self.wfile.write(bytes(f'{self.html_head}\n{html}\n{self.html_foot}', 'utf-8'))
def send_code_and_headers(self, code, headers=[]):
self.send_response(code)
def send_code_and_headers(self, code, headers=[]):
self.send_response(code)
@@
-108,9
+103,9
@@
class PlomServer(BaseHTTPRequestHandler):
-def run_server(port,
serv
er_class):
+def run_server(port,
handl
er_class):
from http.server import HTTPServer
from http.server import HTTPServer
- webServer = HTTPServer(('localhost', port),
serv
er_class)
+ webServer = HTTPServer(('localhost', port),
handl
er_class)
print(f"Server started http://localhost:{port}")
try:
webServer.serve_forever()
print(f"Server started http://localhost:{port}")
try:
webServer.serve_forever()