Skip to content

Commit

Permalink
Verbose mode (optional skip printing) [0.2.1!]
Browse files Browse the repository at this point in the history
- Verbose console mode for printing the specifics of emoji that have been skipped.
- Skipped emoji are now taken out of the exporting process. They do not go through to the export phase to be skipped again in an ExportThread.
- Improved error messages and logs.
- New help message, based on the format used by forc.
- Version bumped to 0.2.1.
  • Loading branch information
dzuk-mutant committed Sep 26, 2019
1 parent 5f111d0 commit cf654ea
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 46 deletions.
29 changes: 23 additions & 6 deletions export.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,30 @@


def export(m, filtered_emoji, input_path, formats, path, src_size,
num_threads, renderer, max_batch):
num_threads, renderer, max_batch, verbose):
"""
Runs the entire orxporter process, includes preliminary checking and
validation of emoji metadata and running the tasks associated with exporting.
"""


# verify emoji
# --------------------------------------------------------------------------
log.out('Checking emoji...', 36)

#print(filtered_emoji)

exporting_emoji = []
skipped_emoji_count = 0
for i, e in enumerate(filtered_emoji):

short = e.get("code", "<UNNAMED>") # to provide info on possible error printouts

try:
format_path(path, e, 'svg')
except FilterException as ex:
if verbose:
log.out(f"- - Skipped emoji: {short} - {ex}", 34)
skipped_emoji_count += 1
continue #skip if filtered out

if 'src' not in e:
Expand All @@ -51,6 +58,14 @@ def export(m, filtered_emoji, input_path, formats, path, src_size,
str(imgsize[0]) + 'x' + str(imgsize[1])
))

# add the emoji to exporting_emoji if it's passed all the tests.
exporting_emoji.append(e)

if skipped_emoji_count > 0:
log.out(f"- {skipped_emoji_count} / {len(filtered_emoji)} emoji have been skipped, leaving {len(exporting_emoji)} emoji to export.", 34)

if not verbose:
log.out(f"- use the --verbose flag to see what those emoji are and why they were skipped.", 34)
log.out('- done!', 32)


Expand All @@ -69,18 +84,18 @@ def export(m, filtered_emoji, input_path, formats, path, src_size,
emoji_queue = queue.Queue()

# put the [filtered] emoji (plus the index, cuz enumerate()) into the queue.
for entry in enumerate(filtered_emoji):
for entry in enumerate(exporting_emoji):
emoji_queue.put(entry)

# initialise the amount of requested threads
threads = []
for i in range(num_threads):
threads.append(ExportThread(emoji_queue, str(i), len(filtered_emoji),
threads.append(ExportThread(emoji_queue, str(i), len(exporting_emoji),
m, input_path, formats, path, renderer))


# keeps checking if the export queue is done.
log.bar.max = len(filtered_emoji)
log.bar.max = len(exporting_emoji)
while True:
done = emoji_queue.empty()

Expand Down Expand Up @@ -126,12 +141,14 @@ def export(m, filtered_emoji, input_path, formats, path, src_size,

if pngs and 'png' in m.license:
png_files = []
for e in filtered_emoji:
for e in exporting_emoji:
for f in formats:
if f.startswith('png-'):
try:
png_files.append(format_path(path, e, f))
except FilterException:
if verbose:
log.out(f"- Filtered emoji: {short}", 34)
continue

log.out(f'Adding license metadata to png files...', 36)
Expand Down
9 changes: 2 additions & 7 deletions export_thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,13 +348,8 @@ def run(self):
except queue.Empty:
break

# try to compose the file path of the emoji.
# (this func can throw a FilterException, hence why it's caught here.)
try:
format_path(self.path, emoji, 'svg')
except FilterException as ex:
log.filtered_export_task_count += 1
continue # this emoji is being skipped and not actually worked on.
# compose the file path of the emoji.
format_path(self.path, emoji, 'svg')

if 'src' not in emoji:
raise ValueError('Missing src attribute')
Expand Down
98 changes: 65 additions & 33 deletions orxport.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import log
import manifest

VERSION = '0.2.0'
VERSION = '0.2.1'

RENDERERS = ['inkscape', 'rendersvg', 'imagemagick']

Expand All @@ -24,33 +24,61 @@
DEF_MAX_BATCH = 1000

HELP = f'''orxporter {VERSION}
by Mutant Standard
(mutant.tech)
USAGE: orxport.py [options...]
OPTIONS:
-h prints this help message
-m PATH manifest file path (default: {DEF_MANIFEST})
-i PATH input directory path (default: {DEF_INPUT_PATH})
-o PATH output directory path (default: {DEF_OUTPUT_PATH})
-f PATH_EXPR output naming system (default: {DEF_OUTPUT_NAMING})
-F FORMAT[,FORMAT...] output formats (default: {','.join(DEF_OUTPUT_FORMATS)})
-e FILTER emoji filter
-j FILE export JSON replica of directory structure
-J FILE export JSON metadata for mutstd website
-c disable ANSI color codes
-q WIDTHxHEIGHT ensure source images have given size
-t NUM number of worker threads (default: {DEF_NUM_THREADS})
--force-desc ensure all emoji have a description
-r RENDERER SVG renderer (default: {DEF_RENDERER})
-b NUM maximum files per exiftool call (default: {DEF_MAX_BATCH})
HELP:
----------------------------------------------------
-h Prints this help message.
Also look at /docs for full documentation.
INPUT:
----------------------------------------------------
-i Input images (default: {DEF_INPUT_PATH})
-m Manifest file (default: {DEF_MANIFEST})
-o Output directory (default: {DEF_OUTPUT_PATH})
IMAGE BUILD:
----------------------------------------------------
-F Format (default: {DEF_OUTPUT_FORMATS[0]})
comma separated with no spaces (ie. 'SVGinOT,CBx,sbixOT')
- svg
- png-SIZE
- flif-SIZE
- webp-SIZE
- avif-SIZE
-f Directory/filename naming system for output (default: {DEF_OUTPUT_NAMING})
See the documentation for how this works.
-t Number of threads working on export tasks (default: {DEF_NUM_THREADS})
OUTPUT FORMATS:
svg
png-SIZE
flif-SIZE
webp-SIZE
-r SVG renderer (default: {DEF_RENDERER})
- rendersvg
- imagemagick
- inkscape
RENDERERS:
''' + '\n'.join(RENDERERS)
JSON BUILD:
----------------------------------------------------
-j <FILE> export JSON replica of directory structure
-J <FILE> export JSON metadata for mutstd website
OTHER OPTIONS:
----------------------------------------------------
-e <FILTER> emoji filter
-c disable ANSI color codes
-q <WIDTHxHEIGHT> ensure source images have certain size
--force-desc ensure all emoji have a text description
-b <NUM> maximum files per exiftool call (default: {DEF_MAX_BATCH})
--verbose verbose printing
'''

def main():
manifest_path = DEF_MANIFEST
Expand All @@ -66,10 +94,11 @@ def main():
force_desc = False
renderer = DEF_RENDERER
max_batch = DEF_MAX_BATCH
verbose = False
try:
opts, _ = getopt.getopt(sys.argv[1:],
'hm:i:o:f:F:ce:j:J:q:t:r:b:',
['help', 'force-desc'])
['help', 'force-desc', 'verbose'])
for opt, arg in opts:
if opt in ['-h', '--help']:
print(HELP)
Expand Down Expand Up @@ -109,6 +138,8 @@ def main():
max_batch = int(arg)
if max_batch <= 0:
raise ValueError
elif opt == '--verbose':
verbose = True
except Exception:
print(HELP)
sys.exit(2)
Expand All @@ -118,24 +149,23 @@ def main():
log.out(f'o∆∆o', 32) #hello

if renderer not in RENDERERS:
raise Exception('Invalid renderer: ' + renderer)
raise Exception(f"{renderer} is not a renderer you can use in orxporter.")

log.out(f'Loading manifest file...', 36)

log.out(f'Loading manifest file...', 36)
m = manifest.Manifest(os.path.dirname(manifest_path),
os.path.basename(manifest_path))

log.out(f'- {len(m.emoji)} emoji defined', 32)
log.out(f'- {len(m.emoji)} emoji defined.', 32)

filtered_emoji = [e for e in m.emoji if emoji.match(e, emoji_filter)]

if emoji_filter:
log.out(f'- {len(filtered_emoji)} / {len(m.emoji)} emoji match filter', 34)
log.out(f'- {len(filtered_emoji)} / {len(m.emoji)} emoji match the filter you gave.', 34)

if force_desc:
nondesc = [e.get('code', str(e)) for e in filtered_emoji if 'desc' not in e]
if nondesc:
raise ValueError('Emoji without a description: ' +
raise ValueError('You have emoji without a description: ' +
', '.join(nondesc))
if json_out:
jsonutils.write_emoji(filtered_emoji, json_out)
Expand All @@ -144,9 +174,11 @@ def main():
else:
export.export(m, filtered_emoji, input_path, output_formats,
os.path.join(output_path, output_naming), src_size,
num_threads, renderer, max_batch)
num_threads, renderer, max_batch, verbose)

except Exception as e:
log.out(f'!!! {e}', 31)
log.out(f'\n!!! {e}', 31)
raise e ######################## TEMP
sys.exit(1)

log.out('All done! ^∆∆^\n', 32) # goodbye
Expand Down

0 comments on commit cf654ea

Please sign in to comment.