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') TEMPLATE = jinja2.Template(''' {% if title %} {{title}} {% endif %}
scrollbar on/off
{% if title %}

{{title}}

{% endif %}

Click each photo to view its full resolution. Click the number to download it.

{% for file in files %}
{% if with_download_links %} #{{loop.index}}/{{files|length}} {% endif %}
{% endfor %} ''') def imagegallery(files, title, urlroot, with_download_links): html = TEMPLATE.render( files=files, title=title, urlroot=urlroot, with_download_links=with_download_links, ) return html def imagegallery_argparse(args): patterns = pipeable.input_many(args.patterns) files = list(pathclass.glob_many_files(patterns)) files.sort() html = imagegallery( files=files, title=args.title, urlroot=args.urlroot or '', with_download_links=True, ) 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:]))