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

python action ipv command string to avoid encountered quoting/escape issues

parent f84030fe
......@@ -39,6 +39,21 @@ from jinja2 import Markup
# # Later rules override earlier rules.
# return lambda file_path: gitignore_parser.handle_negation(file_path, rules)
# def escape(arg):
# """escape shell special characters"""
# print(f"ESCAPE {arg}")
# slash = '\\'
# special = '"$*'
# arg = arg.replace(slash, slash+slash)
# for c in special:
# arg = arg.replace(c, slash+c)
# print("ESCAPE RESULT: %s" % arg)
# return '"' + arg + '"'
def innerHTML (elt):
if elt.text != None:
ret = elt.text
......@@ -221,15 +236,24 @@ ffmpeg -i $SOURCE -ss 3 -vframes 1 $TARGET && \
mogrify -resize 200x200 $TARGET
""".strip())
ImagePoster = Builder(action="""
mkdir -p $TARGET.dir && \
convert $SOURCE[0] -auto-orient -resize 640x640 $TARGET
""".strip())
# ImagePoster = Builder(action="""
# mkdir -p $TARGET.dir && \
# convert $SOURCE[0] -auto-orient -resize 640x640 -flatten $TARGET || convert wizard: -resize 640x640 $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])
ImagePoster = Builder(action=make_image_poster)
ImageThumb = Builder(action="""
mkdir -p $TARGET.dir && \
convert $SOURCE[0] -auto-orient -resize 200x200 $TARGET
""".strip())
# ImageThumb = Builder(action="""
# mkdir -p $TARGET.dir && \
# convert $SOURCE[0] -auto-orient -resize 200x200 -flatten $TARGET || convert wizard: -resize 640x640 $TARGET
# """.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])
ImageThumb = Builder(action=make_image_thumb)
def make_image_meta (target, source, env):
......@@ -275,12 +299,15 @@ def add_attribute_to_links (src, attrname, attrvalue):
def template_action (target, source, env):
# print (f"template_builder_action: {target[0]} ({len(source)} sources)")
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['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("_", " ")
jenv.filters['add_attribute_to_links'] = add_attribute_to_links
md = markdown.Markdown(extensions=['meta'])
......@@ -290,7 +317,9 @@ 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
......@@ -308,6 +337,7 @@ 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:
......@@ -319,9 +349,12 @@ def template_action (target, source, env):
allkeys.add(key)
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)
Template = Builder(action=template_action)
# Template = Builder(action=template_action)
Template = Builder(action=Action(template_action, varlist=("index_template", "rootpath")))
### Perform the build
......@@ -337,8 +370,10 @@ builders = {
"FFMPEGMeta": FFMPEGMeta
}
env = Environment(BUILDERS=builders)
# env['ESCAPE']=escape
# env.Append(BUILDERS=builders)
# def decide_if_file_not_exists (dependency, target, prev_ni, repo_node=None):
# return not os.path.exists(str(target))
......@@ -427,68 +462,69 @@ for folder, deps in depwalk("."):
ext = os.path.splitext(d)[1].lstrip(".").lower()
file_meta = os.path.join(folder, ".index", os.path.basename(d), "metadata.json")
if ext in AUDIO_EXTENSIONS:
meta_sources = [d]
play = os.path.join(folder, ".index", os.path.basename(d), "play.mp3")
if os.path.exists(play):
meta_sources.append(play)
env.FFMPEGMeta(target=file_meta, source=meta_sources)
depsmeta.append(file_meta)
elif ext in VIDEO_EXTENSIONS:
# if env.ENSURE_THUMBNAIL
meta_sources = [d]
poster = os.path.join(folder, ".index", os.path.basename(d), "poster.png")
if not os.path.exists(poster): # build iff it doesn't exist
env.VideoPoster(target=poster, source=d)
meta_sources.append(poster)
thumb = os.path.join(folder, ".index", os.path.basename(d), "thumb.png")
if not os.path.exists(thumb): # build iff it doesn't exist
env.VideoThumb(target=thumb, source=d)
meta_sources.append(thumb)
# play: if present include it
play = os.path.join(folder, ".index", os.path.basename(d), "play.mp4")
if os.path.exists(play):
meta_sources.append(play)
env.FFMPEGMeta(target=file_meta, source=meta_sources)
depsmeta.append(file_meta)
elif ext in IMAGE_EXTENSIONS:
meta_sources = [d]
poster = os.path.join(folder, ".index", os.path.basename(d), "poster.jpg")
if not os.path.exists(poster): # build iff it doesn't exist
env.ImagePoster(target=poster, source=d)
meta_sources.append(poster)
thumb = os.path.join(folder, ".index", os.path.basename(d), "thumb.jpg")
if not os.path.exists(thumb): # build iff it doesn't exist
env.ImageThumb(target=thumb, source=d)
meta_sources.append(thumb)
env.ImageMeta(target=file_meta, source=meta_sources)
depsmeta.append(file_meta)
elif ext in PDF_EXTENSIONS:
meta_sources = [d]
poster = os.path.join(folder, ".index", os.path.basename(d), "poster.jpg")
if not os.path.exists(poster): # build iff it doesn't exist
env.ImagePoster(target=poster, source=d)
meta_sources.append(poster)
thumb = os.path.join(folder, ".index", os.path.basename(d), "thumb.jpg")
if not os.path.exists(thumb): # build iff it doesn't exist
env.ImageThumb(target=thumb, source=d)
meta_sources.append(thumb)
env.PDFMeta(target=file_meta, source=meta_sources)
depsmeta.append(file_meta)
if ext:
if ext in AUDIO_EXTENSIONS:
meta_sources = [d]
play = os.path.join(folder, ".index", os.path.basename(d), "play.mp3")
if os.path.exists(play):
meta_sources.append(play)
env.FFMPEGMeta(target=file_meta, source=meta_sources)
depsmeta.append(file_meta)
elif ext and ext in VIDEO_EXTENSIONS:
# if env.ENSURE_THUMBNAIL
meta_sources = [d]
poster = os.path.join(folder, ".index", os.path.basename(d), "poster.png")
if not os.path.exists(poster): # build iff it doesn't exist
env.VideoPoster(target=poster, source=d)
meta_sources.append(poster)
thumb = os.path.join(folder, ".index", os.path.basename(d), "thumb.png")
if not os.path.exists(thumb): # build iff it doesn't exist
env.VideoThumb(target=thumb, source=d)
meta_sources.append(thumb)
# play: if present include it
play = os.path.join(folder, ".index", os.path.basename(d), "play.mp4")
if os.path.exists(play):
meta_sources.append(play)
env.FFMPEGMeta(target=file_meta, source=meta_sources)
depsmeta.append(file_meta)
elif ext in IMAGE_EXTENSIONS:
meta_sources = [d]
poster = os.path.join(folder, ".index", os.path.basename(d), "poster.jpg")
if not os.path.exists(poster): # build iff it doesn't exist
env.ImagePoster(target=poster, source=d)
meta_sources.append(poster)
thumb = os.path.join(folder, ".index", os.path.basename(d), "thumb.jpg")
if not os.path.exists(thumb): # build iff it doesn't exist
env.ImageThumb(target=thumb, source=d)
meta_sources.append(thumb)
env.ImageMeta(target=file_meta, source=meta_sources)
depsmeta.append(file_meta)
elif ext in PDF_EXTENSIONS:
meta_sources = [d]
poster = os.path.join(folder, ".index", os.path.basename(d), "poster.jpg")
if not os.path.exists(poster): # build iff it doesn't exist
env.ImagePoster(target=poster, source=d)
meta_sources.append(poster)
thumb = os.path.join(folder, ".index", os.path.basename(d), "thumb.jpg")
if not os.path.exists(thumb): # build iff it doesn't exist
env.ImageThumb(target=thumb, source=d)
meta_sources.append(thumb)
env.PDFMeta(target=file_meta, source=meta_sources)
depsmeta.append(file_meta)
env.FolderMeta(target=folder_meta_path, source=deps+depsmeta)
env.Template(target=os.path.join(folder, "index.html"), \
source=[folder_meta_path, File("templates/index-template.html")], \
index_template="templates/index-template.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", \
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