trivial: apply black

This commit is contained in:
Frédéric Péters 2021-01-11 19:10:08 +01:00
parent da4448c589
commit 2bf37aaa7e
9 changed files with 203 additions and 139 deletions

View File

@ -28,8 +28,9 @@ for dirname in sorted(os.listdir('static')):
theme['variables']['no_extra_js'] = False
else:
theme['variables']['no_extra_js'] = True
if (os.path.exists(os.path.join('static', dirname, 'backoffice.scss')) or
os.path.exists(os.path.join('static', dirname, 'backoffice.css'))):
if os.path.exists(os.path.join('static', dirname, 'backoffice.scss')) or os.path.exists(
os.path.join('static', dirname, 'backoffice.css')
):
theme['variables']['portal_agent_extra_css'] = '/static/%s/backoffice.css' % dirname
else:
theme['variables']['portal_agent_extra_css'] = None
@ -67,7 +68,9 @@ for dirname in sorted(os.listdir('static')):
'WCS_CATEGORY_ASSET_SLOTS',
'WCS_FORM_ASSET_SLOTS',
):
print('E: unknown settings key for %s (%s)' % (dirname, settings_key), file=sys.stderr)
print(
'E: unknown settings key for %s (%s)' % (dirname, settings_key), file=sys.stderr
)
errors = True
themes.append(theme)
@ -85,8 +88,12 @@ if os.path.exists('help/fr/misc-scss.page'):
description = ''.join(description.itertext()).strip('$')
value = ''.join(value.itertext()).strip('$')
parameter_type = 'text'
if (value.startswith('#') or value in ('white', 'black') or
name.endswith('color') or name.endswith('background')):
if (
value.startswith('#')
or value in ('white', 'black')
or name.endswith('color')
or name.endswith('background')
):
parameter_type = 'color'
if value.endswith('px') or value.endswith('rem') or name.endswith('size'):
parameter_type = 'size'

View File

@ -9,10 +9,7 @@ os.chdir(sys.argv[1])
data_uris = []
for filename in os.listdir('img/'):
varname, filetype = os.path.splitext(filename)
mimetype = {
'.png': 'image/png',
'.svg': 'image/svg+xml'
}.get(filetype)
mimetype = {'.png': 'image/png', '.svg': 'image/svg+xml'}.get(filetype)
if not mimetype:
continue
filesize = os.stat('img/' + filename).st_size

View File

@ -13,11 +13,20 @@ args = parser.parse_args()
for filename in os.listdir(os.path.join(args.path, 'src')):
outname = os.path.basename(filename)
fd = open('/tmp/tmp-%s' % outname, 'w')
fd.write(open(os.path.join(args.path, 'src', filename)).read().replace(
'fill:#DA0000', 'fill:#%s' % args.color))
fd.write(
open(os.path.join(args.path, 'src', filename)).read().replace('fill:#DA0000', 'fill:#%s' % args.color)
)
fd.close()
subprocess.call(['inkscape', '--without-gui',
'--file', '/tmp/tmp-%s' % outname,
subprocess.call(
[
'inkscape',
'--without-gui',
'--file',
'/tmp/tmp-%s' % outname,
'--export-area-drawing',
'--export-png', os.path.join(args.path, outname.replace('.svg', '-%s.png' % args.color)),
'--export-height', '31'])
'--export-png',
os.path.join(args.path, outname.replace('.svg', '-%s.png' % args.color)),
'--export-height',
'31',
]
)

View File

@ -10,6 +10,8 @@ args = sys.argv[1:]
if b'Inkscape 0' not in inkscape_version:
# --export-png replaced by --export-filename
# --without-gui and --file removed
args = [x.replace('--export-png', '--export-filename') for x in args if x not in ('--without-gui', '--file')]
args = [
x.replace('--export-png', '--export-filename') for x in args if x not in ('--without-gui', '--file')
]
sys.exit(subprocess.call(['inkscape'] + args))

View File

@ -35,7 +35,7 @@ names = {
'08': 'sport',
'09': 'securite',
'10': 'signalements',
'11': 'dechets'
'11': 'dechets',
}
filenames = [
@ -102,15 +102,26 @@ for filename in filenames:
outname = names.get(re.search(r'\d+', filename).group())
fd = open('tmp-%s.svg' % outname, 'w')
fd.write(open(os.path.join('pictos', filename)).read().replace(
'E0037A', args.primary).replace(
'6D1F80', args.secondary))
fd.write(
open(os.path.join('pictos', filename))
.read()
.replace('E0037A', args.primary)
.replace('6D1F80', args.secondary)
)
fd.close()
subprocess.call([inkscape, '--without-gui',
'--file', 'tmp-%s.svg' % outname,
subprocess.call(
[
inkscape,
'--without-gui',
'--file',
'tmp-%s.svg' % outname,
'--export-area-page',
'--export-png', os.path.join(path_out, '%s.png' % outname),
'--export-width', '128'])
'--export-png',
os.path.join(path_out, '%s.png' % outname),
'--export-width',
'128',
]
)
tree = ET.parse(open(os.path.join('pictos', filename)))
parent_map = {c: p for p in tree.iter() for c in p}
@ -166,11 +177,13 @@ for filename in filenames:
del node.attrib['style']
if tag_name == 'path':
if node.attrib.get('fill') == '#FFFFFF' or (
node.attrib['d'].startswith('M120.281,98.383c-1') or # travail/skirt
node.attrib['d'].startswith('M108.574,71.064L') or # logement/house
node.attrib['d'].startswith('M37.523,66.207c0,5') or # transport/wheel
node.attrib['d'].startswith('M-9.2,66.207c0,5.2') or # transport/other wheel
node.attrib['d'].startswith('M96.33,80.938H84.') # travail/briefcase outline
node.attrib['d'].startswith('M120.281,98.383c-1')
or node.attrib['d'].startswith('M108.574,71.064L') # travail/skirt
or node.attrib['d'].startswith('M37.523,66.207c0,5') # logement/house
or node.attrib['d'].startswith('M-9.2,66.207c0,5.2') # transport/wheel
or node.attrib['d'].startswith( # transport/other wheel
'M96.33,80.938H84.'
) # travail/briefcase outline
):
node.attrib['fill'] = 'none'
node.attrib['stroke'] = '#FFFFFF'
@ -180,8 +193,16 @@ for filename in filenames:
node.attrib['fill'] = 'none'
node.attrib['stroke'] = '#FFFFFF'
tree.write('tmp-%s.svg' % outname)
subprocess.call([inkscape, '--without-gui',
'--file', 'tmp-%s.svg' % outname,
subprocess.call(
[
inkscape,
'--without-gui',
'--file',
'tmp-%s.svg' % outname,
'--export-area-page',
'--export-png', os.path.join(path_out, '%s-on.png' % outname),
'--export-width', '128'])
'--export-png',
os.path.join(path_out, '%s-on.png' % outname),
'--export-width',
'128',
]
)

View File

@ -100,10 +100,15 @@ for filename in filenames:
with tempfile.NamedTemporaryFile(suffix='.svg') as tmpfile:
tree.write(tmpfile.name)
tmpfile.flush()
cmd = [inkscape, '--without-gui',
'--file', tmpfile.name,
cmd = [
inkscape,
'--without-gui',
'--file',
tmpfile.name,
'--export-area-drawing',
'--export-png', out_filepath]
'--export-png',
out_filepath,
]
if variant_width:
cmd.extend(['--export-width', variant_width])
else:

View File

@ -51,27 +51,32 @@ content = re.sub('<script src=.*jquery.min.js.*', '', content)
content = content.replace('<script>document.body.className="withJS"</script>', '')
content = content.replace('<body',
r'<body {% block bodyargs %}{% endblock %} ')
content = content.replace('<body', r'<body {% block bodyargs %}{% endblock %} ')
content = content.replace('</head>', '<title>{% block global_title %}{% endblock %}</title>\n</head>')
content = content.replace('<head>', '<head>{% block head %}{% endblock %}')
content = content.replace('<div id="content">', '''
content = content.replace(
'<div id="content">',
'''
{% if include_top_links != False %}<div id="toplinks">{% block user-info %}{% endblock %}</div>{% endif %}
{% block nav %}{% endblock %}
{% block grenoble-content %}
{% block messages %}
{% endblock %}
{% endblock %}''')
{% endblock %}''',
)
content = content.replace('</body>', '''
content = content.replace(
'</body>',
'''
{% block tracking %}
{% endblock %}
{% block body-bottom %}
{% endblock %}
</body>
''')
''',
)
open('base-theme.html', 'w').write(content)

View File

@ -47,24 +47,27 @@ content = content.replace(FILENAME, '')
content = re.sub('<script( type=.*)? src=.*jquery.min.js.*', '', content)
content = re.sub('<script( type=.*)? src=.*formCtrl.*.js.*', '', content)
content = content.replace('<body',
r'<body {% block bodyargs %}{% endblock %} ')
content = content.replace('<body', r'<body {% block bodyargs %}{% endblock %} ')
content = content.replace('</head>', '<title>{% block global_title %}{% endblock %}</title>\n</head>')
content = content.replace('<head>', '<head>{% block head %}{% endblock %}')
content = content.replace('<main id="corps">', '''<main id="corps">
content = content.replace(
'<main id="corps">',
'''<main id="corps">
{% block nav %}{% endblock %}
{% block messages %}{% endblock %}
{% block local-content-wrapper %}
{% endblock %}''')
{% endblock %}''',
)
content = content.replace('</body>', '{% block local-body-bottom %}{% endblock %}</body>')
content = content.replace("SERVER_ROOT = '/'", 'SERVER_ROOT="//www.hautes-alpes.fr/"')
content = content.replace('<div id="toolbarTraduction">',
'<div id="toolbarTraduction">{% block user-info %}{% endblock %}')
content = content.replace(
'<div id="toolbarTraduction">', '<div id="toolbarTraduction">{% block user-info %}{% endblock %}'
)
open(os.path.join('.', 'base-theme.html'), 'w').write(content)

View File

@ -46,10 +46,14 @@ head_content = etree.tostring(root, method='html')
# remove closing <html> because it will be closed later
head_content = head_content.replace('</html>', '')
head_content = head_content.replace('</head>', external_js + '''
head_content = head_content.replace(
'</head>',
external_js
+ '''
{% block head %}{% endblock %}
<title>{% block global_title %}{% endblock %}</title>
</head>''')
</head>''',
)
subprocess.call(['wget', '--quiet', '-O', HEADER_FILENAME, '--convert-links', HEADER_URL])
header_content = open(HEADER_FILENAME).read().strip()
@ -86,7 +90,18 @@ publik_footer = '''<div id="footer-wrapper">
</div>
</div>'''
content = '\n'.join([head_content, '<body {% block bodyargs %}{% endblock %}>', header_content,
banner_content, publik_content, publik_footer, footer_content,
'{% block tracking %}{% endblock %}', '</body>', '</html>'])
content = '\n'.join(
[
head_content,
'<body {% block bodyargs %}{% endblock %}>',
header_content,
banner_content,
publik_content,
publik_footer,
footer_content,
'{% block tracking %}{% endblock %}',
'</body>',
'</html>',
]
)
open('base-theme.html', 'w').write(content)