|
| 1 | +#!/usr/bin/env -S uv run --script |
| 2 | +# /// script |
| 3 | +# dependencies = ["argparse", "python-frontmatter"] |
| 4 | +# /// |
| 5 | +# |
| 6 | +# copy from archive into proper directories |
| 7 | +# |
| 8 | + |
| 9 | +import argparse |
| 10 | +import datetime |
| 11 | +import json |
| 12 | +import frontmatter |
| 13 | +import os |
| 14 | +import pathlib |
| 15 | +import re |
| 16 | +import sys |
| 17 | +import time |
| 18 | + |
| 19 | +default_path = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "www")) |
| 20 | + |
| 21 | +parser = argparse.ArgumentParser() |
| 22 | +parser.add_argument("-q", "--quiet", help="hide status messages", default=True, dest='verbose', action="store_false") |
| 23 | +parser.add_argument("-d", "--directory", help="directory to search", default=default_path, dest='directory') |
| 24 | +parser.add_argument("-f", "--filenames", help="only print failing filenames", default=False, dest='filenames', action="store_true") |
| 25 | +parser.add_argument("-v", "--verbose", help="verbose output", default=False, dest='debug', action="store_true") |
| 26 | + |
| 27 | +args = parser.parse_args() |
| 28 | + |
| 29 | +if args.verbose: |
| 30 | + sys.stdout.write("INFO: full data generation starting at %s\n" % datetime.datetime.fromtimestamp(time.time()).strftime('%Y-%m-%d %H:%M:%S')) |
| 31 | + |
| 32 | +found_files = list(pathlib.Path(os.path.join(args.directory, "logos")).glob('**/index.md')) |
| 33 | +found_files.sort() # only so debug output is consistent |
| 34 | + |
| 35 | +idxCount = 0 |
| 36 | +errCount = 0 |
| 37 | + |
| 38 | +fulldata = [] |
| 39 | + |
| 40 | +for indexfn in found_files: |
| 41 | + idxCount += 1 |
| 42 | + if args.debug: |
| 43 | + sys.stdout.write("DEBUG: checking %s\n" % (indexfn)) |
| 44 | + |
| 45 | + indexmd = frontmatter.load(indexfn) |
| 46 | + |
| 47 | + if 'logohandle' not in indexmd: |
| 48 | + sys.stdout.write("ERROR: %s: missing logohandle\n" % indexfn) |
| 49 | + errCount += 1 |
| 50 | + continue |
| 51 | + |
| 52 | + if 'noindex' in indexmd: |
| 53 | + if args.verbose: |
| 54 | + sys.stdout.write("INFO: %s: noindex found, skipping\n" % indexfn) |
| 55 | + continue |
| 56 | + |
| 57 | + fulldata.append(indexmd.metadata) |
| 58 | + |
| 59 | +retVal = { |
| 60 | + "success": True, |
| 61 | + "lastmod": datetime.datetime.fromtimestamp(time.time()).strftime('%Y-%m-%d %H:%M:%S'), |
| 62 | + "count": len(fulldata), |
| 63 | + "sites": fulldata |
| 64 | +} |
| 65 | + |
| 66 | +fulldatafn = os.path.join(args.directory, "util", "fulldata.json") |
| 67 | +f = open(fulldatafn, 'w') |
| 68 | +f.write(json.dumps(retVal, indent=2)) |
| 69 | +f.close() |
| 70 | + |
| 71 | +if args.verbose: |
| 72 | + sys.stdout.write("INFO: files checked: %5d\n" % idxCount) |
| 73 | + sys.stdout.write("INFO: errors : %5d\n" % errCount) |
| 74 | + sys.stdout.write("INFO: full data generation complete at %s\n" % datetime.datetime.fromtimestamp(time.time()).strftime('%Y-%m-%d %H:%M:%S')) |
| 75 | + |
| 76 | +sys.exit(errCount) |
0 commit comments