raw regexp

This commit is contained in:
j 2026-01-25 20:07:06 +01:00
commit 5da0a07693
2 changed files with 4 additions and 4 deletions

View file

@ -9,7 +9,7 @@ def get(config_jsonc='config.pandora.jsonc'):
data = fd.read().decode('utf-8') data = fd.read().decode('utf-8')
config = ox.jsonc.loads(data) config = ox.jsonc.loads(data)
docs = {} docs = {}
for m in re.compile('( \/\*.*?\*\/)\W+"([^\W]+?)":', re.DOTALL).findall(data): for m in re.compile(r'( \/\*.*?\*\/)\W+"([^\W]+?)":', re.DOTALL).findall(data):
docs[m[1]] = m[0].strip() docs[m[1]] = m[0].strip()
''' '''
for key in config: for key in config:
@ -29,7 +29,7 @@ def update(config_jsonc='config.jsonc', base='config.pandora.jsonc'):
current_docs = get(config_jsonc) current_docs = get(config_jsonc)
for key in docs: for key in docs:
if key in current_docs: if key in current_docs:
match = '\n' + re.escape(' ' + current_docs[key]) + '\W+"' + re.escape(key) + '":' match = '\n' + re.escape(' ' + current_docs[key]) + r'\W+"' + re.escape(key) + '":'
else: else:
match = '\n "' + re.escape(key) + '":' match = '\n "' + re.escape(key) + '":'
data = re.sub(match, '\n %s\n "%s":' % (docs[key], key), data) data = re.sub(match, '\n %s\n "%s":' % (docs[key], key), data)

View file

@ -25,9 +25,9 @@ class Command(BaseCommand):
print('delete', f) print('delete', f)
os.unlink(f) os.unlink(f)
else: else:
n = re.compile('timeline(\d+)p(\d+)').findall(base) n = re.compile(r'timeline(\d+)p(\d+)').findall(base)
if not n: if not n:
n = re.compile('timeline(\d+)p').findall(base) n = re.compile(r'timeline(\d+)p').findall(base)
target = 'timelineantialias%sp.jpg' % n[0] target = 'timelineantialias%sp.jpg' % n[0]
print(f, target) print(f, target)
target = os.path.join(os.path.dirname(f), target) target = os.path.join(os.path.dirname(f), target)