return items
-def get_all_services():
+import sys
+import argparse
+
+def get_all_services(custom_config_path=None):
# Regex to find "Version X: Description" lines
version_pattern = re.compile(r"^\s*#\s*Version\s+(\w+):\s*(.+)$", re.MULTILINE)
service_pattern = re.compile(r"^\s*#\s*Service:\s*(.+?)\s*\|\s*(.+)$", re.MULTILINE)
services_git = parse_file(NGINX_CONF, version_pattern, is_version=True)
- # Locate default.conf
- # On Server: Read the live deployed config
- live_default = Path("/etc/nginx/conf.d/default.conf")
- # On Local: Read default.dev.conf
- local_dev = REPO_ROOT / "etc/nginx/conf.d/default.dev.conf"
-
- if live_default.exists():
- DEFAULT_CONF = live_default
- print(f"Using live config: {DEFAULT_CONF}")
+ DEFAULT_CONF = None
+ if custom_config_path:
+ p = Path(custom_config_path)
+ if p.exists():
+ DEFAULT_CONF = p
+ print(f"Using custom config: {DEFAULT_CONF}")
+ else:
+ print(f"Error: Custom config not found at {p}")
+ sys.exit(1)
else:
- DEFAULT_CONF = local_dev
- print(f"Using local config: {DEFAULT_CONF}")
+ # Locate default.conf fallback (old logic)
+ # On Server: Read the live deployed config
+ live_default = Path("/etc/nginx/conf.d/default.conf")
+ # On Local: Read default.dev.conf
+ local_dev = REPO_ROOT / "etc/nginx/conf.d/default.dev.conf"
+
+ if live_default.exists():
+ DEFAULT_CONF = live_default
+ print(f"Using live config: {DEFAULT_CONF}")
+ else:
+ DEFAULT_CONF = local_dev
+ print(f"Using local config: {DEFAULT_CONF}")
services_other = parse_file(DEFAULT_CONF, service_pattern, is_version=False)
return services_git, services_other
+
def generate_html(title, groups):
"""
groups: list of tuples (header_name, services_list)
return HTML_TEMPLATE.format(title=title, content=content_html)
+
def main():
+ parser = argparse.ArgumentParser(description="Generate HTML services map from Nginx config")
+ parser.add_argument("config_path", nargs="?", help="Path to the Nginx configuration file")
+ args = parser.parse_args()
+
print(f"Reading configs...")
- services_git, services_other = get_all_services()
+ services_git, services_other = get_all_services(args.config_path)
+
+ # Prefix Git services with the correct domain
+ for s in services_git:
+ if s["url"].startswith("/"):
+ s["url"] = f"https://git.nutra.tk{s['url']}"
# Output 1: Git Services Only
print(f"Generating Git Services map with {len(services_git)} items...")
if __name__ == "__main__":
main()
+