diff --git a/distribusi/cli.py b/distribusi/cli.py index 14d5d13..68ccc90 100644 --- a/distribusi/cli.py +++ b/distribusi/cli.py @@ -2,61 +2,55 @@ import argparse from distribusi.distribusi import distribusify + def build_argparser(): - parser = argparse.ArgumentParser(""" + parser = argparse.ArgumentParser( + """ distbusi is a content management system for the web that produces static index pages based on folders in the filesystem. It is inspired by the automatic index functions featured in several web servers. It works by traversing the file system and directory hierarchy to automatically list all the files in the directory and providing them with html classes and tags for easy styling. - """) - - parser.add_argument( - '-d', - '--directory', - help="Select which directory to distribute" + """ ) parser.add_argument( - '-s', - '--style', - help="Select a CSS style to include" + '-d', '--directory', help="Select which directory to distribute" ) + parser.add_argument('-s', '--style', help="Select a CSS style to include") + parser.add_argument( - '-v', - '--verbose', - help="Print verbose debug output", - action="store_true" + '-v', '--verbose', help="Print verbose debug output", action="store_true" ) parser.add_argument( '-t', '--thumbnail', help="Generate 150x150 thumbnails for images", - action="store_true" + action="store_true", ) parser.add_argument( '-n', '--no-template', help="Don't use the template to output html", - action="store_true" + action="store_true", ) parser.add_argument( '-nf', '--no-filenames', help="Don't include image filenames", - action="store_true" + action="store_true", ) parser.add_argument( '-c', '--captions', help="Print captions stored in exif metadata", - action="store_true" + action="store_true", ) return parser diff --git a/distribusi/distribusi.py b/distribusi/distribusi.py index 4a09ef9..334f26f 100644 --- a/distribusi/distribusi.py +++ b/distribusi/distribusi.py @@ -1,16 +1,14 @@ import base64 import os +import subprocess from io import BytesIO import magic -from distribusi.page_template import html_footer, html_head from PIL import Image -import subprocess -CODE_TYPES = [ - 'x-c', - 'html' -] +from distribusi.page_template import html_footer, html_head + +CODE_TYPES = ['x-c', 'html'] FILE_TYPES = { 'image': '
{}
', @@ -19,19 +17,14 @@ FILE_TYPES = { '' ), 'text': '{}', - 'video': ( - '' - ), - 'audio': ( - '' - ), + 'video': (''), + 'audio': (''), } MIME_TYPE = magic.Magic(mime=True) + def caption(image): process = subprocess.Popen(['exiftool', '-Comment', image], stdout=subprocess.PIPE) out, err = process.communicate() @@ -41,6 +34,7 @@ def caption(image): caption = '' return caption + def thumbnail(image, name, args): size = (450, 450) im = Image.open(image) @@ -58,6 +52,7 @@ def thumbnail(image, name, args): "
{}
" ).format(name, data_url, cap) + def div(args, mime, tag, *values): id_name = values[0].split('.')[0].replace(' ', '_') if not args.no_filenames: @@ -101,7 +96,7 @@ def distribusify(args, directory): # noqa elif format in CODE_TYPES: # if the plain text is code, # which types do we wrap in pre-tags? - a = "
"+open(full_path).read()+"
" + a = "
" + open(full_path).read() + "
" else: a = FILE_TYPES[mime] @@ -146,7 +141,7 @@ def distribusify(args, directory): # noqa f.write(styled_html_head) for line in html: - f.write(line+'\n') + f.write(line + '\n') if not args.no_template: f.write(html_footer)