mirror of
https://github.com/krateng/maloja.git
synced 2023-08-10 21:12:55 +03:00
Discrimination between human-edited files (with comments) and generated logs
This commit is contained in:
parent
55a2383788
commit
edb4e14372
@ -687,7 +687,7 @@ def build_db():
|
||||
|
||||
|
||||
|
||||
db = parseAllTSV("scrobbles","int","string","string")
|
||||
db = parseAllTSV("scrobbles","int","string","string",escape=False)
|
||||
for sc in db:
|
||||
artists = sc[1].split("␟")
|
||||
title = sc[2]
|
||||
@ -742,7 +742,7 @@ def sync():
|
||||
SCROBBLES[idx] = (SCROBBLES[idx][0],SCROBBLES[idx][1],True)
|
||||
|
||||
for e in entries:
|
||||
addEntries("scrobbles/" + e + ".tsv",entries[e])
|
||||
addEntries("scrobbles/" + e + ".tsv",entries[e],escape=False)
|
||||
combineChecksums("scrobbles/" + e + ".tsv",cla.checksums)
|
||||
|
||||
|
||||
|
@ -51,7 +51,7 @@ for l in log:
|
||||
|
||||
|
||||
entry = "\t".join([str(timestamp),artistsstr,title,album])
|
||||
|
||||
entry = entry.replace("#",r"\num")
|
||||
|
||||
outputlog.write(entry)
|
||||
outputlog.write("\n")
|
||||
|
@ -18,6 +18,7 @@ The first column defines the type of the rule:
|
||||
Third column the replacement artist / grouping label
|
||||
|
||||
Rules in non-tsv files are ignored. '#' is used for comments. Additional columns are ignored. To have a '#' in a name, use '\num'
|
||||
Comments are not supported in scrobble lists, but you probably never edit these manually anyway.
|
||||
|
||||
An example file could look like this:
|
||||
|
||||
|
20
utilities.py
20
utilities.py
@ -9,14 +9,16 @@ import datetime
|
||||
|
||||
### TSV files
|
||||
|
||||
def parseTSV(filename,*args):
|
||||
def parseTSV(filename,*args,escape=True):
|
||||
f = open(filename)
|
||||
|
||||
result = []
|
||||
for l in [l for l in f if (not l.startswith("#")) and (not l.strip()=="")]:
|
||||
|
||||
l = l.replace("\n","").split("#")[0]
|
||||
l = l.replace(r"\num","#")
|
||||
l = l.replace("\n","")
|
||||
if escape:
|
||||
l = l.split("#")[0]
|
||||
l = l.replace(r"\num","#") # translate escape sequences even if we don't support comments in the file and they are not actually necessary (they might still be used for some reason)
|
||||
data = list(filter(None,l.split("\t"))) # Multiple tabs are okay, we don't accept empty fields unless trailing
|
||||
entry = [] * len(args)
|
||||
for i in range(len(args)):
|
||||
@ -107,7 +109,7 @@ def consistentRulestate(folder,checksums):
|
||||
return True
|
||||
|
||||
|
||||
def parseAllTSV(path,*args):
|
||||
def parseAllTSV(path,*args,escape=True):
|
||||
|
||||
|
||||
result = []
|
||||
@ -115,7 +117,7 @@ def parseAllTSV(path,*args):
|
||||
|
||||
if (f.endswith(".tsv")):
|
||||
|
||||
result += parseTSV(path + "/" + f,*args)
|
||||
result += parseTSV(path + "/" + f,*args,escape=escape)
|
||||
|
||||
return result
|
||||
|
||||
@ -124,21 +126,21 @@ def createTSV(filename):
|
||||
if not os.path.exists(filename):
|
||||
open(filename,"w").close()
|
||||
|
||||
def addEntry(filename,a):
|
||||
def addEntry(filename,a,escape=True):
|
||||
|
||||
createTSV(filename)
|
||||
|
||||
line = "\t".join(a)
|
||||
line = line.replace("#",r"\num")
|
||||
if escape: line = line.replace("#",r"\num")
|
||||
with open(filename,"a") as f:
|
||||
f.write(line + "\n")
|
||||
|
||||
def addEntries(filename,al):
|
||||
def addEntries(filename,al,escape=True):
|
||||
|
||||
with open(filename,"a") as f:
|
||||
for a in al:
|
||||
line = "\t".join(a)
|
||||
line = line.replace("#",r"\num")
|
||||
if escape: line = line.replace("#",r"\num")
|
||||
f.write(line + "\n")
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user