diff --git a/scripts/make-sfx.sh b/scripts/make-sfx.sh index 08f8df42..c811fc51 100755 --- a/scripts/make-sfx.sh +++ b/scripts/make-sfx.sh @@ -169,6 +169,15 @@ done sed -r '/edit2">edit \(fancy/d' <$f >t && tmv "$f" } +find | grep -E '\.py$' | + grep -vE '__version__' | + tr '\n' '\0' | + xargs -0 python ../scripts/uncomment.py + +f=dep-j2/jinja2/constants.py +awk '/^LOREM_IPSUM_WORDS/{o=1;print "LOREM_IPSUM_WORDS = u\"a\"";next} !o; /"""/{o=0}' <$f >t +tmv "$f" + # up2k goes from 28k to 22k laff echo entabbening find | grep -E '\.(js|css|html|py)$' | while IFS= read -r f; do diff --git a/scripts/uncomment.py b/scripts/uncomment.py new file mode 100644 index 00000000..56153ea7 --- /dev/null +++ b/scripts/uncomment.py @@ -0,0 +1,77 @@ +#!/usr/bin/env python +# coding: utf-8 +from __future__ import print_function, unicode_literals + +import io +import sys +import tokenize + + +def uncomment(fpath): + """ modified https://stackoverflow.com/a/62074206 """ + + with open(fpath, "rb") as f: + orig = f.read().decode("utf-8") + + out = "" + for ln in orig.split("\n"): + if not ln.startswith("#"): + break + + out += ln + "\n" + + io_obj = io.StringIO(orig) + prev_toktype = tokenize.INDENT + last_lineno = -1 + last_col = 0 + for tok in tokenize.generate_tokens(io_obj.readline): + # print(repr(tok)) + token_type = tok[0] + token_string = tok[1] + start_line, start_col = tok[2] + end_line, end_col = tok[3] + + if start_line > last_lineno: + last_col = 0 + + if start_col > last_col: + out += " " * (start_col - last_col) + + is_legalese = ( + "copyright" in token_string.lower() or "license" in token_string.lower() + ) + + if token_type == tokenize.STRING: + if ( + prev_toktype != tokenize.INDENT + and prev_toktype != tokenize.NEWLINE + and start_col > 0 + or is_legalese + ): + out += token_string + else: + out += '"a"' + elif token_type != tokenize.COMMENT or is_legalese: + out += token_string + + prev_toktype = token_type + last_lineno = end_line + last_col = end_col + + # out = "\n".join(x for x in out.splitlines() if x.strip()) + + with open(fpath, "wb") as f: + f.write(out.encode("utf-8")) + + +def main(): + print("uncommenting", end="") + for f in sys.argv[1:]: + print(".", end="") + uncomment(f) + + print("k") + + +if __name__ == "__main__": + main()