| 1 |
#!/usr/bin/env python3 |
| 2 |
# Yes, this is a Bad YAML Parser, but at this stage we are not in the |
| 3 |
# venv and do not know what modules the user has available, so for |
| 4 |
# maximum compatibility, we are just assuming a plain Python distribution. |
| 5 |
import argparse |
| 6 |
import re |
| 7 |
import sys |
| 8 |
import os |
| 9 |
|
| 10 |
parser = argparse.ArgumentParser() |
| 11 |
group = parser.add_mutually_exclusive_group(required=True) |
| 12 |
group.add_argument("--sources", action="store_true") |
| 13 |
group.add_argument("--family", action="store_true") |
| 14 |
args = parser.parse_args() |
| 15 |
|
| 16 |
with open(os.path.join("sources", "config.yaml")) as config: |
| 17 |
data = config.read() |
| 18 |
|
| 19 |
if args.family: |
| 20 |
m = re.search(r"(?m)^familyName: (.*)", data) |
| 21 |
if m: |
| 22 |
print(m[1]) |
| 23 |
sys.exit(0) |
| 24 |
else: |
| 25 |
print("Could not determine family name from config file!") |
| 26 |
sys.exit(1) |
| 27 |
|
| 28 |
toggle = False |
| 29 |
sources = [] |
| 30 |
for line in data.splitlines(): |
| 31 |
if re.match("^sources:", line): |
| 32 |
toggle = True |
| 33 |
continue |
| 34 |
if toggle: |
| 35 |
m = re.match(r"^\s*-\s*(.*)", line) |
| 36 |
if m: |
| 37 |
sources.append("sources/" + m[1]) |
| 38 |
else: |
| 39 |
toggle = False |
| 40 |
if sources: |
| 41 |
print(" ".join(sources)) |
| 42 |
sys.exit(0) |
| 43 |
else: |
| 44 |
print("Could not determine sources from config file!") |
| 45 |
sys.exit(1) |