|
1 | 1 | #!/usr/bin/env python |
2 | | -import os |
| 2 | + |
| 3 | +from pathlib import Path |
3 | 4 | import pprint |
4 | 5 |
|
5 | 6 | from jinja2 import Template |
6 | 7 | from yaml import safe_load |
7 | 8 | from markdown import markdown |
8 | | -import glob |
9 | 9 | import requests |
10 | 10 |
|
11 | 11 | # concatenate yml files... |
12 | 12 |
|
13 | | -here = os.path.abspath(os.path.dirname(__file__)) |
14 | | - |
15 | | -try: |
16 | | - os.remove(os.path.join(here, '../packages/all.yml')) |
17 | | -except: |
18 | | - pass |
19 | | -packages = glob.glob(os.path.join(here, '../packages/*')) |
| 13 | +here = Path(__file__).parent.resolve() |
20 | 14 |
|
| 15 | +all_path = here.parent / 'packages/all.yml' |
| 16 | +all_path.unlink(missing_ok=True) |
| 17 | +packages = (here.parent / 'packages').glob('*') |
21 | 18 |
|
22 | 19 |
|
23 | 20 | print("Opening section names file") |
24 | | -with open(os.path.join(here, '../section_names.yml')) as f: |
| 21 | +with (here.parent / 'section_names.yml').open() as f: |
25 | 22 | section_names = safe_load(f) |
26 | 23 |
|
27 | 24 | section_names = section_names['section_names'] |
|
30 | 27 | packs = dict() |
31 | 28 | # divide the yml files into sections based on teh section tag... |
32 | 29 | for package in packages: |
33 | | - with open(package, 'r') as fin: |
| 30 | + with package.open('r') as fin: |
34 | 31 | pack = safe_load(fin) |
35 | 32 | if 'section' not in pack: |
36 | 33 | pack['section'] = 'miscellaneous' |
|
41 | 38 |
|
42 | 39 | pprint.pprint(packs) |
43 | 40 |
|
44 | | - |
45 | | -with open(os.path.join(here, '../packages/all.yml'), 'w') as out: |
| 41 | +with all_path.open('w') as out: |
46 | 42 | for secname in sorted(packs.keys()): |
47 | 43 | packs_sec = sorted(packs[secname], key= lambda i: i['repo'].split('/')[1]) |
48 | 44 |
|
|
58 | 54 |
|
59 | 55 |
|
60 | 56 | print("Opening config file") |
61 | | -with open(os.path.join(here, '../packages/all.yml')) as f: |
| 57 | +with all_path.open() as f: |
62 | 58 | config = safe_load(f) |
63 | 59 | pprint.pprint(config) |
64 | 60 | print() |
|
130 | 126 | else: |
131 | 127 | package['site_protocol'], package['site'] = package['site'].rstrip('/').split('://') |
132 | 128 |
|
133 | | -template = Template(open(os.path.join(here, 'template.rst'), 'r').read()) |
| 129 | +template = Template((here / 'template.rst').read_text()) |
134 | 130 |
|
135 | 131 | config = sorted(config, key = lambda i: i['name']) |
136 | 132 |
|
137 | 133 |
|
138 | | -with open(os.path.join(here, '../docs/source/packages.rst'), 'w') as f: |
139 | | - f.write("Third-party and user-contributed packages\n") |
140 | | - f.write("=========================================\n\n") |
141 | | - f.write(".. include:: intro.rst\n\n") |
142 | | - # f.write(".. include:: html\n\n") |
143 | | - f.write(template.render(config=config)) |
| 134 | +(here.parent / 'docs/source/packages.rst').write_text(f"""\ |
| 135 | +Third-party and user-contributed packages |
| 136 | +========================================= |
| 137 | +
|
| 138 | +.. include:: intro.rst |
| 139 | +
|
| 140 | +{template.render(config=config)} |
| 141 | +""") |
0 commit comments