Clean up imports and formatting

This commit is contained in:
Luke Murphy 2019-07-08 20:02:41 +02:00
parent d5606e5325
commit df71f44550
No known key found for this signature in database
GPG Key ID: 5E2EF5A63E3718CC
2 changed files with 23 additions and 34 deletions

View File

@ -2,61 +2,55 @@ import argparse
from distribusi.distribusi import distribusify from distribusi.distribusi import distribusify
def build_argparser(): def build_argparser():
parser = argparse.ArgumentParser(""" parser = argparse.ArgumentParser(
"""
distbusi is a content management system for the web that produces static 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 index pages based on folders in the filesystem. It is inspired by the
automatic index functions featured in several web servers. It works by automatic index functions featured in several web servers. It works by
traversing the file system and directory hierarchy to automatically list traversing the file system and directory hierarchy to automatically list
all the files in the directory and providing them with html classes and all the files in the directory and providing them with html classes and
tags for easy styling. tags for easy styling.
""") """
parser.add_argument(
'-d',
'--directory',
help="Select which directory to distribute"
) )
parser.add_argument( parser.add_argument(
'-s', '-d', '--directory', help="Select which directory to distribute"
'--style',
help="Select a CSS style to include"
) )
parser.add_argument('-s', '--style', help="Select a CSS style to include")
parser.add_argument( parser.add_argument(
'-v', '-v', '--verbose', help="Print verbose debug output", action="store_true"
'--verbose',
help="Print verbose debug output",
action="store_true"
) )
parser.add_argument( parser.add_argument(
'-t', '-t',
'--thumbnail', '--thumbnail',
help="Generate 150x150 thumbnails for images", help="Generate 150x150 thumbnails for images",
action="store_true" action="store_true",
) )
parser.add_argument( parser.add_argument(
'-n', '-n',
'--no-template', '--no-template',
help="Don't use the template to output html", help="Don't use the template to output html",
action="store_true" action="store_true",
) )
parser.add_argument( parser.add_argument(
'-nf', '-nf',
'--no-filenames', '--no-filenames',
help="Don't include image filenames", help="Don't include image filenames",
action="store_true" action="store_true",
) )
parser.add_argument( parser.add_argument(
'-c', '-c',
'--captions', '--captions',
help="Print captions stored in exif metadata", help="Print captions stored in exif metadata",
action="store_true" action="store_true",
) )
return parser return parser

View File

@ -1,16 +1,14 @@
import base64 import base64
import os import os
import subprocess
from io import BytesIO from io import BytesIO
import magic import magic
from distribusi.page_template import html_footer, html_head
from PIL import Image from PIL import Image
import subprocess
CODE_TYPES = [ from distribusi.page_template import html_footer, html_head
'x-c',
'html' CODE_TYPES = ['x-c', 'html']
]
FILE_TYPES = { FILE_TYPES = {
'image': '<figure><img class="image" src="{}">{}</figure>', 'image': '<figure><img class="image" src="{}">{}</figure>',
@ -19,19 +17,14 @@ FILE_TYPES = {
'<embed src="{}" type="application/pdf" /></object>' '<embed src="{}" type="application/pdf" /></object>'
), ),
'text': '<a href="{}" class="text">{}</a>', 'text': '<a href="{}" class="text">{}</a>',
'video': ( 'video': ('<video class="video" controls>' '<source src="{}"></source></video>'),
'<video class="video" controls>' 'audio': ('<audio controls class="audio">' '<source src="{}"></source></audio>'),
'<source src="{}"></source></video>'
),
'audio': (
'<audio controls class="audio">'
'<source src="{}"></source></audio>'
),
} }
MIME_TYPE = magic.Magic(mime=True) MIME_TYPE = magic.Magic(mime=True)
def caption(image): def caption(image):
process = subprocess.Popen(['exiftool', '-Comment', image], stdout=subprocess.PIPE) process = subprocess.Popen(['exiftool', '-Comment', image], stdout=subprocess.PIPE)
out, err = process.communicate() out, err = process.communicate()
@ -41,6 +34,7 @@ def caption(image):
caption = '' caption = ''
return caption return caption
def thumbnail(image, name, args): def thumbnail(image, name, args):
size = (450, 450) size = (450, 450)
im = Image.open(image) im = Image.open(image)
@ -58,6 +52,7 @@ def thumbnail(image, name, args):
"<figure><a href='{}'><img class='thumbnail' src='data:image/jpg;base64,{}'></a>{}</figure>" "<figure><a href='{}'><img class='thumbnail' src='data:image/jpg;base64,{}'></a>{}</figure>"
).format(name, data_url, cap) ).format(name, data_url, cap)
def div(args, mime, tag, *values): def div(args, mime, tag, *values):
id_name = values[0].split('.')[0].replace(' ', '_') id_name = values[0].split('.')[0].replace(' ', '_')
if not args.no_filenames: if not args.no_filenames: