From: Vladimír Vondruš Date: Sun, 3 Dec 2017 13:32:08 +0000 (+0100) Subject: css: ability to skip imports and redirect output of postprocess.py. X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~cjwatson/git?a=commitdiff_plain;h=d29c58c9ba5a49978190c35ee6801e57897840ef;p=blog.git css: ability to skip imports and redirect output of postprocess.py. --- diff --git a/css/postprocess.py b/css/postprocess.py index 968d62e1..0098e32a 100755 --- a/css/postprocess.py +++ b/css/postprocess.py @@ -38,10 +38,12 @@ comment_end_rx = re.compile("^\\s*(.*\\*/)\\s*$") variable_declaration_rx = re.compile("^\\s*(?P--[a-z-]+)\\s*:\\s*(?P[^;]+)\\s*;\\s*$") variable_use_rx = re.compile("^(?P.+)var\\((?P--[a-z-]+)\\)(?P.+)$") -def postprocess(files): +def postprocess(files, process_imports, out_file): directory = os.path.dirname(files[0]) - basename, ext = os.path.splitext(files[0]) - out_file = basename + ".compiled" + ext + + if not out_file: + basename, ext = os.path.splitext(files[0]) + out_file = basename + ".compiled" + ext with open(out_file, mode='w') as out: variables = {} @@ -88,10 +90,12 @@ def postprocess(files): in_comment = False continue - # Import statement: add the file at the beginning of th + # Import statement: add the file to additionally processed + # files unless it's disabled match = import_rx.match(line) if match: - imported_files += [match['file']] + if process_imports: + imported_files += [match['file']] continue # Opening brace of variable declaration block @@ -183,8 +187,11 @@ if __name__ == "__main__": Postprocessor for removing @import statements and variables from CSS files. Combines all files into a new *.compiled.css file. The basename is taken -implicitly from the first argument.""") - parser.add_argument('files', nargs='+', help='input CSS file(s)') +implicitly from the first argument. The -o option can override the output +filename.""") + parser.add_argument('files', nargs='+', help="input CSS file(s)") + parser.add_argument('--no-import', help="ignore @import statements", action='store_true') + parser.add_argument('-o', '--output', help="output file", default='') args = parser.parse_args() - exit(postprocess(args.files)) + exit(postprocess(args.files, not args.no_import, args.output))