diff --git a/photogallery.py b/photogallery.py new file mode 100644 index 0000000..6243e51 --- /dev/null +++ b/photogallery.py @@ -0,0 +1,197 @@ +import argparse +import sys +import jinja2 +import textwrap + +from voussoirkit import betterhelp +from voussoirkit import pathclass +from voussoirkit import pipeable +from voussoirkit import vlogging + +log = vlogging.getLogger(__name__, 'imagegallery') + +def imagegallery_argparse(args): + patterns = pipeable.input_many(args.patterns) + files = list(pathclass.glob_many_files(patterns)) + files.sort() + + html = jinja2.Template(textwrap.dedent(''' + + + {% if title %} + {{title}} + {% endif %} + + + + + +
+ scrollbar on/off +
+ {% if title %} +

{{title}}

+ {% endif %} + {% for file in files %} +
+ + #{{loop.index}}/{{files|length}} +
+ {% endfor %} + + + + + ''')).render( + files=files, + title=args.title, + urlroot=args.urlroot or '', + ) + pathclass.Path('gallery.html').open('w', encoding='utf-8').write(html) + return 0 + +@vlogging.main_decorator +def main(argv): + parser = argparse.ArgumentParser( + description=''' + ''', + ) + parser.add_argument( + 'patterns', + nargs='*', + help=''' + ''', + ) + parser.add_argument( + '--title', + default=None, + help=''' + ''', + ) + parser.add_argument( + '--urlroot', + default=None, + help=''' + ''', + ) + parser.set_defaults(func=imagegallery_argparse) + + return betterhelp.go(parser, argv) + +if __name__ == '__main__': + raise SystemExit(main(sys.argv[1:]))