mirror of
https://github.com/krateng/maloja.git
synced 2023-08-10 21:12:55 +03:00
More logging
This commit is contained in:
parent
52cf14de7e
commit
709f3c129c
@ -35,6 +35,7 @@ def loadAPIkeys():
|
||||
global clients
|
||||
createTSV("clients/authenticated_machines.tsv")
|
||||
clients = parseTSV("clients/authenticated_machines.tsv","string","string")
|
||||
log(str(len(clients)) + " Authenticated Machines " + ", ".join([m[1] for m in clients]))
|
||||
|
||||
def checkAPIkey(k):
|
||||
return (k in [k for [k,d] in clients])
|
||||
@ -621,9 +622,11 @@ def issues():
|
||||
|
||||
@dbserver.post("/rebuild")
|
||||
def rebuild():
|
||||
|
||||
keys = FormsDict.decode(request.forms)
|
||||
apikey = keys.pop("key",None)
|
||||
if (checkAPIkey(apikey)):
|
||||
log("Database rebuild initiated!")
|
||||
global db_rulestate
|
||||
db_rulestate = False
|
||||
sync()
|
||||
@ -660,6 +663,7 @@ def search():
|
||||
|
||||
# Starts the server
|
||||
def runserver(PORT):
|
||||
log("Starting database server...")
|
||||
global lastsync
|
||||
lastsync = int(datetime.datetime.now(tz=datetime.timezone.utc).timestamp())
|
||||
build_db()
|
||||
@ -668,11 +672,12 @@ def runserver(PORT):
|
||||
loadAPIkeys()
|
||||
|
||||
run(dbserver, host='::', port=PORT, server='waitress')
|
||||
log("Database server reachable!")
|
||||
|
||||
def build_db():
|
||||
|
||||
|
||||
|
||||
log("Building database...")
|
||||
|
||||
global SCROBBLES, ARTISTS, TRACKS
|
||||
|
||||
@ -706,6 +711,8 @@ def build_db():
|
||||
# load cached images
|
||||
loadCache()
|
||||
|
||||
log("Database fully built!")
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -1,6 +1,8 @@
|
||||
import os
|
||||
import re
|
||||
from cleanup import CleanerAgent
|
||||
from utilities import log
|
||||
import difflib
|
||||
|
||||
wendigo = CleanerAgent()
|
||||
|
||||
@ -20,6 +22,7 @@ for fn in os.listdir("scrobbles/"):
|
||||
(al,t) = wendigo.fullclean(a,t)
|
||||
a = "␟".join(al)
|
||||
fnew.write(r1 + a + r2 + t + r3 + "\n")
|
||||
|
||||
#print("Artists: " + a)
|
||||
#print("Title: " + t)
|
||||
#print("1: " + r1)
|
||||
@ -29,7 +32,12 @@ for fn in os.listdir("scrobbles/"):
|
||||
f.close()
|
||||
fnew.close()
|
||||
|
||||
os.system("diff " + "scrobbles/" + fn + "_new" + " " + "scrobbles/" + fn)
|
||||
#os.system("diff " + "scrobbles/" + fn + "_new" + " " + "scrobbles/" + fn)
|
||||
with open("scrobbles/" + fn + "_new","r") as newfile:
|
||||
with open("scrobbles/" + fn,"r") as oldfile:
|
||||
diff = difflib.unified_diff(oldfile.read().split("\n"),newfile.read().split("\n"),lineterm="")
|
||||
diff = list(diff)[2:]
|
||||
log("Diff for scrobbles/" + fn + "".join("\n\t" + d for d in diff),module="fixer")
|
||||
|
||||
os.rename("scrobbles/" + fn + "_new","scrobbles/" + fn)
|
||||
|
||||
|
@ -159,11 +159,12 @@ def cleandict(d):
|
||||
|
||||
### Logging
|
||||
|
||||
def log(msg):
|
||||
import inspect
|
||||
def log(msg,module=None):
|
||||
now = datetime.datetime.utcnow().strftime("%Y/%m/%d %H:%M:%S")
|
||||
module = inspect.getmodule(inspect.stack()[1][0]).__name__
|
||||
if module == "__main__": module = "mainserver"
|
||||
if module is None:
|
||||
import inspect
|
||||
module = inspect.getmodule(inspect.stack()[1][0]).__name__
|
||||
if module == "__main__": module = "mainserver"
|
||||
print("[" + module + "] " + msg)
|
||||
with open("logs/" + module + ".log","a") as logfile:
|
||||
logfile.write(now + " " + msg + "\n")
|
||||
|
@ -5,6 +5,7 @@ body {
|
||||
color:beige;
|
||||
font-family:"Ubuntu";
|
||||
padding:15px;
|
||||
padding-bottom:35px;
|
||||
/**
|
||||
padding-top:45px;
|
||||
padding-bottom:25px;
|
||||
|
Loading…
Reference in New Issue
Block a user