|
1 | 1 | from pathlib import Path |
2 | 2 | import sys |
| 3 | +import frontmatter |
3 | 4 |
|
4 | 5 | existing_0xxx = {'0006', '01C0', '0007', '053A', '0256', '0008', '000F', '0BAB', '0009', '0001', '000A', |
5 | 6 | '0010', '01CB', '000C', '0002', '000E', '0CBD', '000D', '000B', '0003', '0004', '0514', |
6 | 7 | '0005', '0070', '0D32'} |
7 | 8 | existing_1xxx = {'1AB6', '1005', '1776', '1001', '1007', '1AB5', '1002', '1006', '1004', '1003', '1986'} |
8 | 9 |
|
| 10 | +required_keys = ['title', 'license'] |
| 11 | + |
9 | 12 | vid_1209 = Path("1209") |
10 | 13 | pid1xxx = vid_1209.glob("1*") |
11 | 14 | pid1xxx = set([x.name for x in pid1xxx]) |
|
42 | 45 | ok = False |
43 | 46 | print("Pid is too long: '" + pid + "'") |
44 | 47 |
|
| 48 | + try: |
| 49 | + pid_path = vid_1209 / pid / "index.md" |
| 50 | + post = frontmatter.load(pid_path) |
| 51 | + layout = post.get('layout') |
| 52 | + if layout != "pid": |
| 53 | + print(f"{pid_path}:0: Layout must be 'pid'. Note: File may not contain a Byte Order Mark (BOM)") |
| 54 | + ok = False |
| 55 | + owner = post.get('owner') |
| 56 | + if owner is None: |
| 57 | + print(f"{pid_path}:0: No owner specified") |
| 58 | + ok = False |
| 59 | + continue |
| 60 | + owner_path = Path("org") / owner / "index.md" |
| 61 | + if not owner_path.exists(): |
| 62 | + print(f"{pid_path}:0: Owner file {owner} does not exist") |
| 63 | + ok = False |
| 64 | + for k in required_keys: |
| 65 | + if k not in post.metadata: |
| 66 | + print(f"{pid_path}:0: Required key {k} not present in front matter") |
| 67 | + ok = False |
| 68 | + except Exception as e: |
| 69 | + print(f"{pid_path}: Failure parsing front matter: {e}") |
| 70 | + ok = False |
45 | 71 | if pid1xxx - existing_1xxx: |
46 | 72 | print("Cannot claim 1xxx PID:", pid1xxx - existing_1xxx) |
47 | 73 | print("See here for more info: http://pid.codes/1209/") |
|
54 | 80 |
|
55 | 81 |
|
56 | 82 | if not ok: |
| 83 | + print("Error(s) found") |
57 | 84 | sys.exit(-1) |
58 | 85 |
|
59 | 86 | print("No errors found!") |
0 commit comments