diff --git a/main.py b/main.py old mode 100644 new mode 100755 index 5a07b29..97ccd02 --- a/main.py +++ b/main.py @@ -1,3 +1,4 @@ +#!/usr/bin/env python3 """ Compound HTML Transclusion Compiler Copyright (C) 2016 Damian Heaton @@ -18,6 +19,7 @@ import bs4 import sys +import os minify = False nocomm = False @@ -40,72 +42,82 @@ print("""Compound should be used with syntax thus: python(3) main.py [any optional parameters (see docs)]""") else: - output = ".".join(sys.argv[1].split(".")[:-2]) + ".html" - if "-o" in sys.argv: - output = sys.argv[sys.argv.index("-o") + 1] - elif "--output" in sys.argv: - output = sys.argv[sys.argv.index("--output") + 1] - - if "-b" in sys.argv: - output = sys.argv[sys.argv.index("-b") + 1] + output - elif "--build-dir" in sys.argv: - output = sys.argv[sys.argv.index("-b") + 1] + output - - try: - if(".c.html" not in sys.argv[1]): - print("WARNING: CHTML input file does not contain '.c.html' in its name; are you sure that it's the correct format?") - chtml = bs4.BeautifulSoup(open(sys.argv[1]), "html.parser") - - # index all of the tags that we deal with - transcludes = chtml.find_all("link", rel="transclusion") - csslinks = chtml.find_all("link", rel="stylesheet") - scriptlinks = chtml.find_all("script", src=True) - - for transclusion in transcludes: - try: - transclusion.replaceWith(bs4.BeautifulSoup(open(transclusion["href"]), "html.parser")) - except IOError as e: - print("Transclusion failure: file %s could not be found -- perhaps it's misspelt?" % transclusion["href"]) - del transclusion - except Exception as e: - print("Transclusion failure:", e) - - if "-v" in sys.argv or "--verbose" in sys.argv: - # they passed the verbose flag; embed script and css files - - # css files - for cssfile in csslinks: - # create a new