#!/usr/bin/env python3 """Put the editing fan's pictures into the app's catalogue. python3 scripts/import-editing-art.py Each `.png` Card design delivers becomes the imageset `edit-` in CottonPaper's Media.xcassets, copied as delivered (the architect approved them as drawn). The fan draws each on its card's paper (`FanTier.Card`), the corner ring round the date corner. Card design's contact sheets (`editing-*`) are not pictures and are passed over; any other name is refused. """ import json import pathlib import shutil import sys NAMES = [ 'value-today', 'value-day', 'act-when', 'act-group', 'act-repeat', 'act-status', 'act-bin', 'corner-ring', 'ink-mark', ] CATALOGUE = pathlib.Path(__file__).resolve().parent.parent / 'apps/loom/Sources/CottonPaper/Media.xcassets' def main(source): found = set() for png in sorted(pathlib.Path(source).glob('*.png')): if png.stem.startswith('editing-'): continue if png.stem not in NAMES: raise SystemExit(f'{png.name}: not one of {NAMES}') imageset = CATALOGUE / f'edit-{png.stem}.imageset' imageset.mkdir(exist_ok=True) target = imageset / f'edit-{png.stem}.png' shutil.copyfile(png, target) contents = { 'images': [ {'filename': target.name, 'idiom': 'universal', 'scale': '3x'}, {'filename': target.name, 'idiom': 'mac', 'scale': '2x'}, ], 'info': {'author': 'xcode', 'version': 1}, 'properties': {'preserves-vector-representation': False}, } (imageset / 'Contents.json').write_text(json.dumps(contents, indent=2) + '\n') found.add(png.stem) print(f'{png.name} -> {imageset.name}') missing = [name for name in NAMES if name not in found] if missing: raise SystemExit(f'missing: {missing}') if __name__ == '__main__': main(sys.argv[1] if len(sys.argv) > 1 else str(pathlib.Path.home() / 'lane-briefs/carddesign-images/art/editing'))