diff options
author | Juan J. Martinez <jjm@usebox.net> | 2019-08-04 06:58:20 +0100 |
---|---|---|
committer | Juan J. Martinez <jjm@usebox.net> | 2019-08-04 06:59:01 +0100 |
commit | 0db66e1d88e9f877c55e30eb54f1b2431774221c (patch) | |
tree | a6b2b5ac71ad78520645537b03c11e144a63516d | |
parent | b39f7395fe7b3db804b505c0dee353f228410dcd (diff) | |
download | z80count-0db66e1d88e9f877c55e30eb54f1b2431774221c.tar.gz z80count-0db66e1d88e9f877c55e30eb54f1b2431774221c.zip |
Changed update to not update
This makes updating the comments the default.
Also some changes for PEP8.
Closes issue #10.
-rw-r--r-- | README.md | 2 | ||||
-rw-r--r-- | z80count/z80count.py | 29 |
2 files changed, 22 insertions, 9 deletions
@@ -33,7 +33,7 @@ You can use it with: Or inside `vim` you can: - :% !z80count -su + :% !z80count -s With `-s` the tool adds a subtotal to the comments and `-u` tries to update existing comments generated by the tool. diff --git a/z80count/z80count.py b/z80count/z80count.py index 1ef1ee7..697450d 100644 --- a/z80count/z80count.py +++ b/z80count/z80count.py @@ -32,7 +32,15 @@ version = "0.6.0" OUR_COMMENT = re.compile(r"(\[[0-9.\s/]+\])") -def z80count(line, parser, total, total_cond, subt, update, tabstop=2, debug=False): +def z80count(line, + parser, + total, + total_cond, + subt, + no_update, + tabstop=2, + debug=False, + ): out = line.rstrip() + "\n" entry = parser.lookup(line) if entry: @@ -61,7 +69,7 @@ def z80count(line, parser, total, total_cond, subt, update, tabstop=2, debug=Fal comment = "\t" * tabstop + comment out = line[0] + comment if len(line) > 1: - if update: + if not no_update: m = OUR_COMMENT.search(line[1]) if m: line[1] = line[1].replace(m.group(0), "") @@ -74,7 +82,8 @@ def z80count(line, parser, total, total_cond, subt, update, tabstop=2, debug=Fal def parse_command_line(): parser = argparse.ArgumentParser( - description='Z80 Cycle Count', epilog="Copyright (C) 2019 Juan J Martinez <jjm@usebox.net>") + description='Z80 Cycle Count', + epilog="Copyright (C) 2019 Juan J Martinez <jjm@usebox.net>") parser.add_argument( "--version", action="version", version="%(prog)s " + version) @@ -82,8 +91,8 @@ def parse_command_line(): help="Enable debug (show the matched case)") parser.add_argument('-s', dest='subt', action='store_true', help="Include subtotal") - parser.add_argument('-u', dest='update', action='store_true', - help="Update existing count if available") + parser.add_argument('-n', dest='no_update', action='store_true', + help="Do not update existing count if available") parser.add_argument('-t', dest='tabstop', type=int, help="Number of tabs for new comments", default=2) parser.add_argument( @@ -97,6 +106,7 @@ def parse_command_line(): class Parser(object): + """Simple parser based on a table of regexes. """ @@ -113,14 +123,16 @@ class Parser(object): return None for entry in self._table[mnemo]: if "cregex" not in entry: - entry["cregex"] = re.compile(r"^\s*" + entry["regex"] + r"\s*(;.*)?$", re.I) + entry["cregex"] = re.compile( + r"^\s*" + entry["regex"] + r"\s*(;.*)?$", re.I) if entry["cregex"].search(line): return entry return None @classmethod def _load_table(cls): - table_file = path.join(path.dirname(path.realpath(__file__)), "z80table.json") + table_file = path.join( + path.dirname(path.realpath(__file__)), "z80table.json") with open(table_file, "rt") as fd: table = json.load(fd) @@ -150,5 +162,6 @@ def main(): total = total_cond = 0 for line in in_f: output, total, total_cond = z80count( - line, parser, total, total_cond, args.subt, args.update, args.tabstop, args.debug) + line, parser, total, total_cond, + args.subt, args.no_update, args.tabstop, args.debug) out_f.write(output) |