|
@@ -6,6 +6,8 @@ import os
|
|
import markdown
|
|
import markdown
|
|
import pystache
|
|
import pystache
|
|
import shutil
|
|
import shutil
|
|
|
|
+import sys
|
|
|
|
+import tempfile
|
|
import yaml
|
|
import yaml
|
|
|
|
|
|
class Datum:
|
|
class Datum:
|
|
@@ -39,16 +41,19 @@ class Work:
|
|
contents: str
|
|
contents: str
|
|
|
|
|
|
class Path:
|
|
class Path:
|
|
- DATADIR=os.getenv('DATADIR', '/home/gdritter/projects/lib-data')
|
|
|
|
- OUTDIR=os.getenv('OUTDIR', '/tmp/lib')
|
|
|
|
|
|
+ OUTDIR=tempfile.TemporaryDirectory()
|
|
|
|
|
|
@classmethod
|
|
@classmethod
|
|
def data(cls, *paths):
|
|
def data(cls, *paths):
|
|
- return os.path.join(cls.DATADIR, *paths)
|
|
|
|
|
|
+ tgt = os.path.join(*paths)
|
|
|
|
+ for path in sys.argv[2:]:
|
|
|
|
+ if path.endswith(os.path.join(tgt)):
|
|
|
|
+ return path
|
|
|
|
+ raise Exception(f"Could not find {tgt}")
|
|
|
|
|
|
@classmethod
|
|
@classmethod
|
|
def out(cls, *paths):
|
|
def out(cls, *paths):
|
|
- return os.path.join(cls.OUTDIR, *paths)
|
|
|
|
|
|
+ return os.path.join(cls.OUTDIR.name, *paths)
|
|
|
|
|
|
@classmethod
|
|
@classmethod
|
|
def write(cls, *paths):
|
|
def write(cls, *paths):
|
|
@@ -63,7 +68,15 @@ class Path:
|
|
|
|
|
|
@classmethod
|
|
@classmethod
|
|
def list(cls, *paths):
|
|
def list(cls, *paths):
|
|
- return os.listdir(cls.data(*paths))
|
|
|
|
|
|
+ stuff = []
|
|
|
|
+ tgt = f'{os.path.join(*paths)}/'
|
|
|
|
+ for path in sys.argv[2:]:
|
|
|
|
+ if tgt in path:
|
|
|
|
+ print(f'{tgt} in {path}')
|
|
|
|
+ chunks = path.split('/')
|
|
|
|
+ idx = chunks.index(paths[-1])
|
|
|
|
+ stuff.append(chunks[idx +1])
|
|
|
|
+ return stuff
|
|
|
|
|
|
class Template:
|
|
class Template:
|
|
renderer = pystache.Renderer(search_dirs="templates")
|
|
renderer = pystache.Renderer(search_dirs="templates")
|
|
@@ -79,6 +92,8 @@ class Template:
|
|
|
|
|
|
|
|
|
|
def main():
|
|
def main():
|
|
|
|
+ out_file = sys.argv[1]
|
|
|
|
+
|
|
year = datetime.datetime.now().year
|
|
year = datetime.datetime.now().year
|
|
std_copy = f'© Getty Ritter {year}'
|
|
std_copy = f'© Getty Ritter {year}'
|
|
no_copy = 'all rights reversed'
|
|
no_copy = 'all rights reversed'
|
|
@@ -143,10 +158,10 @@ def main():
|
|
}))
|
|
}))
|
|
|
|
|
|
# create each category page
|
|
# create each category page
|
|
- for slug in os.listdir(Path.data('works')):
|
|
|
|
|
|
+ for slug in Path.list('works'):
|
|
# we need to know what works exist in the category
|
|
# we need to know what works exist in the category
|
|
works = []
|
|
works = []
|
|
- for work in os.listdir(Path.data('works', slug)):
|
|
|
|
|
|
+ for work in Path.list('works', slug):
|
|
# grab the metadata for this work
|
|
# grab the metadata for this work
|
|
with open(Path.data('works', slug, work, 'metadata.yaml')) as f:
|
|
with open(Path.data('works', slug, work, 'metadata.yaml')) as f:
|
|
meta = yaml.safe_load(f)
|
|
meta = yaml.safe_load(f)
|
|
@@ -198,6 +213,10 @@ def main():
|
|
shutil.copy('static/main.css', Path.out('static', 'main.css'))
|
|
shutil.copy('static/main.css', Path.out('static', 'main.css'))
|
|
shutil.copy('static/icon.png', Path.out('static', 'icon.png'))
|
|
shutil.copy('static/icon.png', Path.out('static', 'icon.png'))
|
|
|
|
|
|
|
|
+ print(f'writing to {out_file}')
|
|
|
|
+ shutil.make_archive('output', 'zip', Path.OUTDIR.name)
|
|
|
|
+ shutil.move('output.zip', out_file)
|
|
|
|
+ Path.OUTDIR.cleanup()
|
|
|
|
|
|
if __name__ == '__main__':
|
|
if __name__ == '__main__':
|
|
main()
|
|
main()
|