raw regexp

This commit is contained in:
j 2025-08-05 15:22:21 +02:00
commit 33a7832d64

View file

@ -80,13 +80,13 @@ def build_oxjs(downloads=False, geo=False):
path = source_path + 'UI/svg/'
for filename in [filename for filename in os.listdir(path) if not filename[0] in '._']:
svg = read_text(path + filename)
svg = re.sub('\n\s*', '', svg)
svg = re.sub('<!--.+?-->', '', svg)
svg = re.sub(r'\n\s*', '', svg)
svg = re.sub(r'<!--.+?-->', '', svg)
# end fix
ui_images[filename[:-4]] = svg
if filename.startswith('symbolLoading'):
for theme in themes:
theme_svg = re.sub('#808080', format_hex(theme_data[theme]['symbolDefaultColor']), svg)
theme_svg = re.sub(r'#808080', format_hex(theme_data[theme]['symbolDefaultColor']), svg)
write_file('%sUI/themes/%s/svg/%s' % (dev_path, theme, filename), theme_svg)
write_file('%sUI/themes/%s/svg/%s' % (min_path, theme, filename), theme_svg)
@ -101,10 +101,10 @@ def build_oxjs(downloads=False, geo=False):
and (geo or '/Geo/' not in path):
# write copies in min path
source = os.path.join(path, filename)
is_jquery = re.search('^jquery-[\d\.]+\.js$', filename)
is_jquery_min = re.search('^jquery-[\d\.]+\.min\.js$', filename)
is_jquery_plugin = re.search('^jquery\..*?\.js$', filename)
is_jsonc = re.search('\.jsonc$', filename)
is_jquery = re.search(r'^jquery-[\d\.]+\.js$', filename)
is_jquery_min = re.search(r'^jquery-[\d\.]+\.min\.js$', filename)
is_jquery_plugin = re.search(r'^jquery\..*?\.js$', filename)
is_jsonc = re.search(r'\.jsonc$', filename)
if is_jquery or is_jquery_min:
target = os.path.join(path.replace(source_path, min_path), 'jquery.js')
else:
@ -113,7 +113,7 @@ def build_oxjs(downloads=False, geo=False):
ui_files['dev'].append(target.replace(min_path, ''))
ui_files['min'].append(target.replace(min_path, ''))
if '/Ox/js/' not in source and '/UI/js/' not in source and not is_jquery:
if re.match('^Ox\..+\.js$', filename) or is_jsonc:
if re.match(r'^Ox\..+\.js$', filename) or is_jsonc:
js = read_text(source)
print('minifiy and write', filename, target)
write_file(target, ox.js.minify(js, '' if is_jsonc else comment))
@ -129,7 +129,7 @@ def build_oxjs(downloads=False, geo=False):
if not is_jquery_min:
write_link(link_source, link_target)
# locales
match = re.search('/(\w+)/json/locale.(\w+).json', source)
match = re.search(r'/(\w+)/json/locale.(\w+).json', source)
if match:
module = match.group(1)
locale = match.group(2)
@ -182,12 +182,12 @@ def build_oxjs(downloads=False, geo=False):
if not js_dir + filename in sum(ox_files, []):
ox_files[-1].append(js_dir + filename)
js = re.sub(
'Ox.LOCALES = \{\}',
r'Ox.LOCALES = \{\}',
'Ox.LOCALES = ' + json.dumps(locales, indent=4, sort_keys=True),
js
)
js = re.sub(
"Ox.VERSION = '([\d\.]+)'",
r"Ox.VERSION = '([\d\.]+)'",
"Ox.VERSION = '%s'" % version,
js
)
@ -238,7 +238,7 @@ def build_oxjs(downloads=False, geo=False):
data = {
# sum(list, []) is flatten
'documentation': sorted(sum(ox_files, [])) + sorted(list(filter(
lambda x: re.search('\.js$', x),
lambda x: re.search(r'\.js$', x),
ui_files['dev']
)) + ['%s/%s.js' % (x, x) for x in ['Geo', 'Image', 'Unicode']]),
'examples': sorted(sum(map(
@ -250,7 +250,7 @@ def build_oxjs(downloads=False, geo=False):
)
)),
list(filter(
lambda x: not re.search('^[._]', x),
lambda x: not re.search(r'^[._]', x),
os.listdir(root_path + 'examples/')
))
), [])) if os.path.exists(root_path + 'examples/') else (),
@ -264,7 +264,7 @@ def build_oxjs(downloads=False, geo=False):
'title': get_title(root_path + 'readme/' + x)
},
filter(
lambda x: not re.search('^[._]', x) and re.search('\.html$', x),
lambda x: not re.search(r'^[._]', x) and re.search(r'\.html$', x),
os.listdir(root_path + 'readme/')
)
))
@ -355,7 +355,7 @@ def parse_css(css, values):
) for vals in value]
)
return string
return re.sub('\$(\w+)(\[\d+\])?', sub, css)
return re.sub(r'\$(\w+)(\[\d+\])?', sub, css)
def read_file(file):
print('reading', file)