Commit a2bc1d13 authored by Michael Murtaugh's avatar Michael Murtaugh
Browse files

smake with scons!

parent b7a38726
......@@ -524,6 +524,8 @@ def main():
from . import jsoncountkeys
jsoncountkeys.add_subparser(subparsers)
from . import smake
smake.add_subparser(subparsers)
args = parser.parse_args()
if 'func' not in args:
......
This diff is collapsed.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Index of {{filename|default("/", True)}}</title>
<link rel="stylesheet" type="text/css" href="/lib/index.css">
<script src="/lib/index.js"></script>
</head>
<body vocab="http://activearchives.org/terms/" typeof="mediafolder">
<h1 class="breadcrumbs">{% for b in breadcrumbs %}
{%- if not loop.last -%}
<a href="{{b.relpath}}">
{%- else -%}
<b class="active" property="dcterms:title" content="{% if title %}{{title}}{%else%}{{b.name|filename2title}}{%endif%}">
{%- endif -%}
{%- if b.name == "/" -%}&blacktriangle;{%- else -%}{{b.name|filename2title}}{%endif%}
{%- if not loop.last -%}</a> /{%- else -%} </b>{%endif%}
{% endfor %}
</h1>
<div class="description" property="dcterms:description">{% if description %}{{description|markdown|add_attribute_to_links("property", "hasTag")}}{% endif %}</div>
<!-- <h1>{{filename|default("/", True)}}</h1> -->
{% set colcount = 5 %}
{% with items=contents %}
<table>
<thead>
<tr>
<th valign="top">&nbsp;</th>
<th>Name</th>
<th>Last modified</th>
<th>Size</th>
{% if 'pages' in allkeys %}<th>Pages</th>{% set colcount=colcount+1 %}{% endif %}
{# {% if 'title' in allkeys %}<th>Title</th>{% set colcount=colcount+1 %}{% endif %} #}
{# {% if 'author' in allkeys %}<th>Author</th>{% set colcount=colcount+1 %}{% endif %} #}
{% if 'duration' in allkeys %}<th>Duration</th>{% set colcount=colcount+1 %}{% endif %}
<th>Description</th>
</tr>
<tr><td colspan="{{ colcount }}"><hr></td></tr>
</thead>
<tbody class="files">
{% for i in items %}
{% if i.type != 'file' %}
<!-- DIRECTORY -->
{% set d = i %}
<tr class="folder" property="dcterms:hasPart" resource="{{d.id}}" typeof="mediafolder">
<td class="icon" valign="top"><img src="/lib/icons/folder.gif" alt="[FOLDER]"></td>
<td class="name"><a href="{{d.id}}">{{d.filename}}/</a></td>
<td class="lastmod" align="right">{% if d.last_modification %}{{d.last_modification|strftime}}{%else%}&mdash;{%endif%}</td>
<td class="size" align="right" content="{{d.total_bytes}}">{{d.total_bytes|filesizeformat}}</td>
{% if 'pages' in allkeys %}<td class="pages">&mdash;</td>{% endif %}
{# {% if 'title' in allkeys %}<td class="title">&mdash;</td>{% endif %} #}
{# {% if 'author' in allkeys %}<td class="author">&mdash;</td>{% endif %} #}
{% if 'duration' in allkeys %}<td class="duration">&mdash;</td>{% endif %}
<td class="description">{{d.total_files}} file{% if d.total_files != 1 %}s{% endif %}{% if d.total_folders > 1 %}, {{d.total_folders-1}} subfolder{% if d.total_folders-1!=1%}s{%endif%}{% endif %}</td>
</tr>
{% else %}
<!-- FILE -->
{% set f = i %}
{% if f.play %}
{% set play_link = f.play|urlencode %}
{%else%}
{% set play_link = f.id %}
{% endif %}
<tr class="file" property="dcterms:hasPart" resource="{{f.id}}" typeof="{% if f.ext in ('jpg', 'png', 'gif') or f.ext.startswith("video/") or f.ext.startswith("audio/") or f.ext == "pdf" %}mediaitem {%endif%}file">
<td class="icon" valign="top">
<a href="{{play_link}}">
{% if f.thumbnail %}
<img src="{{f.thumbnail}}" class="icon" alt="[FILE]">
{% elif f.ext.startswith("image/") %}
<img src="/lib/icons/image1.gif" alt="[IMAGE]">
{% elif f.ext.startswith("audio/") or f.ext.startswith("video/") %}
{% if f.video %}<img src="/lib/icons/video.gif" alt="[IMAGE]">{% else %}<img src="/lib/icons/sound2.gif" alt="[IMAGE]">{%endif%}
{% else %}
<img src="/lib/icons/generic.gif" alt="[IMAGE]">
{% endif %}
</a>
{% if f.thumbnail %}
<!-- rdf outside of link above which seems to reset the subject -->
<a class="metadata" property="hasThumbnail" href="{{f.thumbnail}}"></a>
{% endif %}
</td>
<td class="name">
<a {% if f.play %}property="hasPlay dcterms:hasFormat" href="{{f.play|urlencode}}"{%else%}href="{{f.id}}"{% endif %}><span property="dcterms:title" content="{%if f.title%}{{f.title}}{% else %}{{f.filename|filename2title}}{% endif %}">{{f.filename|wbr_}}</span></a>
{% if f.play %}<a class="original" href="{{f.id}}">&crarr;</a>{% endif %}
{% if f.ext == "pdf" %}
<span property="mediatype" content="pdf"></span>
{% elif f.ext.startswith("audio/") or f.ext.startswith("video/") %}
{% if f.video %}<span property="mediatype" content="video"></span>{%else%}<span property="mediatype" content="audio"></span>{%endif%}
{% elif f.ext.startswith("image/") %}
<span property="mediatype" content="image"></span>
{% endif %}
{% if f.ext %}<span property="dcterms:format" content="{{f.ext}}"></span>{% endif %}
{% if f.poster %}
<a class="rdf" property="hasPoster dcterms:hasFormat" href="{{f.poster|urlencode}}"></a>
{% endif %}
</td>
<td class="lastmod" align="right" property="dcterms:modified" datatype="xsd:dateTime" content="{{f.mtime}}">{{f.mtime|strftime}}</td>
<td class="size" align="right" data-sort-numeric="{{f.size}}">{{f.size|filesizeformat}}</td>
{% if 'pages' in allkeys %}<td class="pages" data-sort-numeric="{{f.pages|default(0,True)}}" {% if f.pages %}property="pages" content="{{f.pages}}"{%endif%}>{% if f.pages %}{{f.pages}}{% else %}&mdash;{%endif%}</td>{% endif %}
{# {% if 'author' in allkeys %}<td class="author">{% if f.author %}{{f.author}}{% else %}&mdash;{%endif%}</td>{% endif %} #}
{% if 'duration' in allkeys %}{% if f.duration %}<td class="duration" data-sort-numeric="{{f.duration}}" property="duration dcterms:extent" content="{{f.duration|isoduration}}" datatype="xsd:duration">{{f.duration|timecode(fract=False)}}</td>{% else %}<td class="duration" data-sort-numeric="0">&mdash;</td>{%endif%}{% endif %}
{% if f.description %}
<td class="description" property="dcterms:description">{{f.description|markdown|add_attribute_to_links("property", "hasTag")}}</td>
{% else %}
<td class="description">&mdash;</td>
{%endif%}
</tr>
{% endif %}
{% endfor %}
</tbody>
<tbody class="summary">
<tr><td colspan="{{ colcount }}"><hr></td></tr>
<tr class="summary">
<td>&nbsp;</td>
<td>
{{total_files}} file{% if total_files != 1 %}s{%endif%}{% if total_folders %}, {{total_folders}} folder{% if total_folders != 1 %}s{%endif%}{%endif%}
{% if 'play' in allkeys %}<span class="legend_original">(original: &crarr;)</span>{%endif%}
</td>
<td align="right">{% if last_modification%}<span property="dcterms:modified" datatype="xsd:dateTime" content="{{last_modification}}">{{last_modification|strftime}}</span>{%else %}&nbsp;{%endif%}</td>
<td align="right">{{total_bytes|filesizeformat}}</td>
<!-- TODO: sums of other values -->
{% if 'pages' in allkeys %}<td>&nbsp;</td>{% endif %}
{% if 'title' in allkeys %}<td>&nbsp;</td>{% endif %}
{% if 'author' in allkeys %}<td>&nbsp;</td>{% endif %}
{% if 'duration' in allkeys %}<td>&nbsp;</td>{% endif %}
<td></td>
</tr>
</tbody>
</table>
{% endwith %}
</body>
</html>
#!/usr/bin/env python3
from __future__ import print_function
import subprocess, re, json
from exif import Image as ExifImage
"""
21A_0334.jpg JPEG 1450x967 1450x967+0+0 8-bit sRGB 328134B 0.000u 0:00.010
......@@ -23,6 +25,28 @@ def get_info(path, data=None):
data['image_format'] = d['format']
data['width'] = int(d['width'])
data['height'] = int(d['height'])
with open (path, "rb") as f:
im = ExifImage(f)
if im and im.has_exif:
if hasattr(im, "datetime_original"):
data['datetime_original'] = im.datetime_original
if hasattr(im, "model"):
data['model'] = im.model
if hasattr(im, "software"):
data['software'] = im.software
if hasattr(im, "lens_model"):
data['lens_model'] = im.lens_model
if hasattr(im, "flash") and hasattr(im.flash, "flash_fired"):
data['flash'] = im.flash.flash_fired
if hasattr(im, "f_number"):
data['f_number'] = im.f_number
if hasattr(im, "focal_length"):
data['focal_length'] = im.focal_length
if hasattr(im, "orientation") and hasattr(im.orientation, 'name'):
data['orientation'] = im.orientation.name
if hasattr(im, "exposure_time"):
data['exposure_time'] = im.exposure_time
return data
def main (args):
......
......@@ -242,7 +242,9 @@ mogrify -resize 200x200 $TARGET
# """.strip())
def make_image_poster (target, source, env):
os.makedirs(os.path.dirname(target[0].path), exist_ok=True)
subprocess.run(["convert", source[0].path+"[0]", "-auto-orient", "-resize", "640x640", "-flatten", target[0].path])
ret = subprocess.run(["convert", source[0].path+"[0]", "-auto-orient", "-resize", "640x640", "-flatten", target[0].path])
if ret.returncode != 0:
subprocess.run(["convert", "wizard:", "-auto-orient", "-resize", "640x640", "-flatten", target[0].path])
ImagePoster = Builder(action=make_image_poster)
......@@ -252,7 +254,9 @@ ImagePoster = Builder(action=make_image_poster)
# """.strip())
def make_image_thumb (target, source, env):
os.makedirs(os.path.dirname(target[0].path), exist_ok=True)
subprocess.run(["convert", source[0].path+"[0]", "-auto-orient", "-resize", "200x200", "-flatten", target[0].path])
ret = subprocess.run(["convert", source[0].path+"[0]", "-auto-orient", "-resize", "200x200", "-flatten", target[0].path])
if ret.returncode != 0:
subprocess.run(["convert", "wizard:", "-auto-orient", "-resize", "200x200", "-flatten", target[0].path])
ImageThumb = Builder(action=make_image_thumb)
......@@ -299,13 +303,10 @@ def add_attribute_to_links (src, attrname, attrvalue):
def template_action (target, source, env):
print (f"template_action: {target[0]} ({len(source)} sources)")
tpath, tname = os.path.split(env.Dictionary().get("index_template"))
rootpath = env.Dictionary().get("rootpath")
print (f"template_action1: tpath:{tpath} tname:{tname}")
jenv = jinja2.Environment(loader=jinja2.FileSystemLoader(tpath))
print (f"template_action2: {target[0]} ({len(source)} sources)")
jenv.filters['strftime'] = lambda x, format='%Y-%m-%d %H:%M:%S': datetime.datetime.fromisoformat(x).strftime(format)
jenv.filters['filename2title'] = lambda x: os.path.splitext(x)[0].replace("_", " ")
......@@ -317,9 +318,7 @@ def template_action (target, source, env):
jenv.filters['isoduration'] = lambda x: isodate.duration_isoformat(datetime.timedelta(0, x))
jenv.filters['timecode'] = timecode_fromsecs
print (f"template_action2b: {target[0]} ({len(source)} sources)")
template = jenv.get_template(tname)
print (f"template_action3: {target[0]} ({len(source)} sources)")
# calc breadcrumbs...
# example breadcrumbs
......@@ -337,7 +336,6 @@ def template_action (target, source, env):
rpath.insert(0, '/')
bc = [{'relpath': '../'*(len(rpath)-i-1), 'name': name} for i, name in enumerate(rpath)]
# print (f"path: {path}, breadcrumbs: {bc}")
print (f"template_action4: {target[0]} ({len(source)} sources)")
# combine source json
with open(source[0].path) as fin:
......@@ -350,7 +348,6 @@ def template_action (target, source, env):
data['allkeys'] = allkeys
data['breadcrumbs'] = bc
print (f"template_action writing {target[0].path}")
with open(target[0].path, "w") as fout:
print (template.render(**data), file=fout)
......@@ -439,12 +436,12 @@ def depwalk (path, base_path=None, ignores=None):
yield path, deps
AUDIO_EXTENSIONS = ("mp3", "wav", "ogg", "oga", "m4a", "opus")
PDF_EXTENSIONS = ("pdf")
PDF_EXTENSIONS = ("pdf", )
VIDEO_EXTENSIONS = ("mp4", "m4v", "ogv", "mpeg", "webm", "mkv", "avi", "mov", "flv", )
IMAGE_EXTENSIONS = ("jpg", "jpeg", "tiff", "tif", "png", "gif", "svg", "webp")
rootdir = Dir('#')
# print (f"root {rootdir.abspath}")
print (f"root {rootdir.abspath}")
# Walk the directory tree (top-down) to express targets + dependencies
for folder, deps in depwalk("."):
# print (f"path {path}, deps: {deps}")
......@@ -454,8 +451,8 @@ for folder, deps in depwalk("."):
# folder = base
# deps = [os.path.join(folder, x) for x in lsdeps(folder)]
folder_meta_path = os.path.join(folder, ".index", ".index.json")
print (f"directory:{folder} ({folder_meta_path})")
print (f" deps:{deps}")
# print (f"directory:{folder} ({folder_meta_path})")
# print (f" deps:{deps}")
# print ()
depsmeta = []
for d in deps:
......@@ -522,9 +519,11 @@ for folder, deps in depwalk("."):
depsmeta.append(file_meta)
env.FolderMeta(target=folder_meta_path, source=deps+depsmeta)
template_path = os.environ.get("scons-template") or "templates/index.html"
root_path = os.environ.get("scons-root") or rootdir.abspath
env.Template(target=os.path.join(folder, "index.html"), \
source=[folder_meta_path, File("/home/murtaugh/projects/indexalist/scons/templates/index-template.html")], \
index_template="/home/murtaugh/projects/indexalist/scons/templates/index-template.html", \
source=[folder_meta_path, File(template_path)], \
index_template=template_path, \
rootpath=rootdir.abspath)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment