2019-04-26 01:05:06 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
import os
|
|
|
|
import sys
|
2025-01-03 17:49:39 +00:00
|
|
|
from argparse import ArgumentParser
|
|
|
|
from pathlib import Path as P
|
|
|
|
import json
|
2019-04-26 01:05:06 +00:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2025-01-03 17:49:39 +00:00
|
|
|
parser = ArgumentParser()
|
|
|
|
parser.add_argument('--input-sitemap', type=P)
|
|
|
|
parser.add_argument('--output-sitemap', type=P)
|
|
|
|
parser.add_argument('--markdown-index', type=P)
|
|
|
|
parser.add_argument('--libs', type=str)
|
|
|
|
parser.add_argument('--plugins', type=str)
|
|
|
|
parser.add_argument('--plugin-configs', nargs='*', default=[])
|
2025-01-15 16:36:00 +00:00
|
|
|
parser.add_argument('--lib-configs', nargs='*', default=[])
|
2025-01-03 17:49:39 +00:00
|
|
|
|
|
|
|
args = parser.parse_args()
|
2019-05-26 22:32:55 +00:00
|
|
|
|
2025-01-03 17:49:39 +00:00
|
|
|
in_ = args.input_sitemap
|
|
|
|
out = args.output_sitemap
|
|
|
|
index_md = args.markdown_index
|
|
|
|
plugins = args.plugins
|
|
|
|
plugin_configs = args.plugin_configs
|
2025-01-15 16:36:00 +00:00
|
|
|
lib_configs = args.lib_configs
|
2025-01-03 17:49:39 +00:00
|
|
|
|
|
|
|
with open(in_) as f:
|
2019-04-26 01:05:06 +00:00
|
|
|
index = f.read()
|
2025-01-03 17:49:39 +00:00
|
|
|
index = '\n'.join(line for line in index.splitlines())
|
2019-05-26 22:32:55 +00:00
|
|
|
|
2025-01-15 16:36:00 +00:00
|
|
|
if args.libs is None:
|
|
|
|
libs = []
|
|
|
|
else:
|
|
|
|
libs = args.libs.split(os.pathsep)
|
|
|
|
for config in lib_configs:
|
|
|
|
with open(config) as f:
|
|
|
|
libs += json.load(f)
|
|
|
|
plugins = plugins.replace('\n', '').split(os.pathsep)
|
|
|
|
for config in plugin_configs:
|
|
|
|
with open(config) as f:
|
|
|
|
plugins += json.load(f)
|
|
|
|
plugins = sorted(plugins, key=lambda x: os.path.basename(x))
|
|
|
|
|
2025-01-03 17:49:39 +00:00
|
|
|
if libs:
|
2019-05-26 22:32:55 +00:00
|
|
|
index += '\n\tlibs.md'
|
2019-04-26 01:05:06 +00:00
|
|
|
for lib in libs:
|
|
|
|
if not lib:
|
|
|
|
continue
|
2025-01-15 16:36:00 +00:00
|
|
|
name = lib
|
|
|
|
if not name.endswith('.json'):
|
|
|
|
name += '.json'
|
|
|
|
index += "\n\t\t" + name
|
|
|
|
if plugins:
|
2019-05-26 22:32:55 +00:00
|
|
|
index += '\n\tgst-index'
|
2019-04-26 01:05:06 +00:00
|
|
|
for plugin in plugins:
|
|
|
|
if not plugin:
|
|
|
|
continue
|
2023-03-19 18:35:29 +00:00
|
|
|
fname = plugin
|
|
|
|
if not fname.endswith('.json'):
|
|
|
|
fname += '.json'
|
|
|
|
index += "\n\t\t" + fname
|
2019-05-26 22:32:55 +00:00
|
|
|
|
|
|
|
index = '%s\n%s' % (index_md, index)
|
|
|
|
|
2019-04-26 01:05:06 +00:00
|
|
|
with open(out, 'w') as fw:
|
|
|
|
fw.write(index)
|