Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP. Bringing Cleaner Terminal Outputs for Several Scripts #4172

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 25 additions & 10 deletions icons/src/fullcolor/render-bitmaps.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@

import os
import sys
import threading
import time
import xml.sax
import subprocess
import shutil
import argparse

from os import popen
from string import whitespace

OPTIPNG = "optipng"
SOURCES = (
Expand All @@ -42,6 +45,8 @@
# DPI multipliers to render at
DPIS = [1, 2]

skips = []


def main(args, SRC, DEST):
def optimize_png(png_file):
Expand All @@ -65,6 +70,7 @@ def wait_for_prompt(process, command=None):
output = output[1:]

def inkscape_render_rect(icon_file, rect, dpi, output_file):
spinner_running = True
cmd = [
"inkscape",
"--batch-process",
Expand All @@ -76,7 +82,8 @@ def inkscape_render_rect(icon_file, rect, dpi, output_file):

cmd.append(icon_file)

print('Running', ' '.join(cmd))

sys.stdout.write(f"\r - Rendering {rect:<9} scale={dpi//96}: {output_file}")
ret = subprocess.run(cmd, capture_output=True)
if ret.returncode != 0:
print("execution of")
Expand All @@ -86,8 +93,8 @@ def inkscape_render_rect(icon_file, rect, dpi, output_file):
print(ret.stdout.decode())
print(5*"=", "stderr", 5*"=")
print(ret.stderr.decode())
raise Exception('Failed to run inkscape')

raise Exception('Failed to run inkscape')
print(f"\r \033[32m✔\033[0m {rect:<9} scale={dpi//96}: {output_file}{" "*len(" Rendering")}")
optimize_png(output_file)

class ContentHandler(xml.sax.ContentHandler):
Expand Down Expand Up @@ -176,7 +183,7 @@ def endElement(self, name):
if self.filter is not None and not self.icon_name in self.filter:
return

print(self.context, self.icon_name)
print(f" \033[1mcontext:{self.context} app-name:{self.icon_name}\033[0m")
for rect in self.rects:
for dpi_factor in DPIS:
width = int(float(rect["width"]))
Expand Down Expand Up @@ -242,18 +249,16 @@ def copy_scalable(file):
file = os.path.join(SRC, svg)

if os.path.exists(file):
print('Rendering SVG "%s" in %s' % (svg, SRC))
print(f'\n\033[1mFound {svg}\033[0m in {SRC}')
print("INKSCAPE is working:")
handler = ContentHandler(file, True, filter=args.filter)
with open(file) as opened:
xml.sax.parse(opened, handler)
if not handler.rendered_icons:
rendered_icons += 1 if copy_scalable(file) else 0
rendered_icons += handler.rendered_icons
else:
print(
'Could not find SVG "%s" in %s, looking into the next one' % (svg, SRC)
)
# icon not in this directory, try the next one
skips.append(SRC)
pass

return rendered_icons
Expand Down Expand Up @@ -307,6 +312,7 @@ def copy_scalable(file):
dest_path = args.dest_path if args.dest_path else os.path.join(script_path, '../../')
rendered_icons = 0

s = time.perf_counter()
for source in SOURCES:
if args.categories and source not in args.categories:
continue
Expand All @@ -316,7 +322,16 @@ def copy_scalable(file):
'default' else "Yaru-" + args.variant))
if os.path.exists(SRC):
rendered_icons += main(args, SRC, DEST)
e = time.perf_counter()
print(e-s)

if len(skips) != 0:
print(f"\033[33m{args.svg}.svg not found in the following sources (SKIPPED): \033[0m")
[print(f" {skip}") for skip in skips]

if rendered_icons == 0:
print('No SVG found to render')
sys.exit(1)