Cotton code
54 lines · 2.0 KB · PythonRaw
#!/usr/bin/env python3"""Put the editing fan's pictures into the app's catalogue.    python3 scripts/import-editing-art.py <art/editing directory>Each `<name>.png` Card design delivers becomes the imageset `edit-<name>` inCottonPaper's Media.xcassets, copied as delivered (the architect approved themas drawn). The fan draws each on its card's paper (`FanTier.Card`), the cornerring round the date corner. Carddesign's contact sheets (`editing-*`) are not pictures and are passed over; anyother name is refused."""import jsonimport pathlibimport shutilimport sysNAMES = [    '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'))