Skip to content

Commit

Permalink
remove ns0 namespace added by etree and don't try to construct if a f…
Browse files Browse the repository at this point in the history
…ile doesn't exist in size
  • Loading branch information
wpkelso committed Jan 26, 2025
1 parent fb15b39 commit dc24d05
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 30 deletions.
56 changes: 30 additions & 26 deletions mimes/meson.build
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
mime_sizes = ['16', '24', '32', '48', '64', '128']

python3 = find_program('python3')
python3 = find_program('python3', required: true)

# Copy src dir to build dir, to give a base to work on

Expand Down Expand Up @@ -92,19 +92,21 @@ endforeach

foreach type : mime_types
foreach size: mime_sizes
message('compositing: ' + type[0] + '.svg and ' + type[1] + '.svg @ ' + size )

output_file = '@[email protected]'.format(join_paths(meson.project_build_root(), 'mimes', size, type[0]))
run_command('touch', output_file)

run_command(
python3,
'@[email protected]'.format(join_paths(meson.project_source_root(), 'scripts', 'composite-svg')),
'@[email protected]'.format(join_paths(meson.current_source_dir(), size, type[0])),
'@[email protected]'.format(join_paths(meson.current_source_dir(), size, type[1])),
output_file,
check: false
)
if fs.is_file(size / type[0] + '.svg')
message('compositing: ' + type[0] + '.svg and ' + type[1] + '.svg @ ' + size )

output_file = '@[email protected]'.format(join_paths(meson.project_build_root(), 'mimes', size, type[0]))
run_command('touch', output_file)

run_command(
python3,
'@[email protected]'.format(join_paths(meson.project_source_root(), 'scripts', 'composite-svg')),
'@[email protected]'.format(join_paths(meson.current_source_dir(), size, type[0])),
'@[email protected]'.format(join_paths(meson.current_source_dir(), size, type[1])),
output_file,
check: true
)
endif
endforeach
endforeach

Expand All @@ -126,18 +128,20 @@ templates = [

foreach template : templates
foreach size: mime_sizes
message('adding template decoration: ' + template + '.svg @ ' + size)

run_command(
python3,
'@[email protected]'.format(join_paths(meson.project_source_root(), 'scripts', 'composite-svg')),
'@[email protected]'.format(join_paths(meson.current_source_dir(), size, 'decoration-template')),
# We operate entirely in the build directory here, because we are
# cascading off of a previously composited file
'@[email protected]'.format(join_paths(meson.project_build_root(), 'mimes', size, template)),
'@[email protected]'.format(join_paths(meson.project_build_root(), 'mimes', size, template)),
check: false
)
if fs.is_file(meson.project_build_root() / 'mimes' / size / template + '.svg')
message('adding template decoration: ' + template + '.svg @ ' + size)

run_command(
python3,
'@[email protected]'.format(join_paths(meson.project_source_root(), 'scripts', 'composite-svg')),
'@[email protected]'.format(join_paths(meson.current_source_dir(), size, 'decoration-template')),
# We operate entirely in the build directory here, because we are
# cascading off of a previously composited file
'@[email protected]'.format(join_paths(meson.project_build_root(), 'mimes', size, template)),
'@[email protected]'.format(join_paths(meson.project_build_root(), 'mimes', size, template)),
check: true
)
endif
endforeach
endforeach

Expand Down
11 changes: 7 additions & 4 deletions scripts/composite-svg.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import sys
import xml.etree.ElementTree as ET

ET.register_namespace("","http://www.w3.org/2000/svg")

svg = "{http://www.w3.org/2000/svg}"
fTop = sys.argv[1] # Type file
fBottom = sys.argv[2] # Base file
Expand All @@ -27,10 +29,11 @@
bRoot = bTree.getroot()
bDefs = bRoot.find(f"{svg}defs")

for element in defs.iter():
bDefs.append(element)

#for element in defs.iter():
# bDefs.append(element)
tmp = defs.iter()
bDefs.extend(tmp)
bRoot.extend(shapes)

# Write out the tree to the target filename
bTree.write(fTarget)
bTree.write(fTarget, encoding="utf-8", xml_declaration=True, method="xml")

0 comments on commit dc24d05

Please sign in to comment.