Mercurial > hg > config
comparison python/stripirssi.py @ 440:5c62ebf2dd47
python/stripirssi.py
| author | Jeff Hammel <jhammel@mozilla.com> |
|---|---|
| date | Fri, 09 Aug 2013 14:21:49 -0700 |
| parents | 364ddd44fd82 |
| children | f81fdc6926fd |
comparison
equal
deleted
inserted
replaced
| 439:a00edb8cf3d7 | 440:5c62ebf2dd47 |
|---|---|
| 38 stripped = [] | 38 stripped = [] |
| 39 for line in lines: | 39 for line in lines: |
| 40 if not line: | 40 if not line: |
| 41 continue # XXX desirable? | 41 continue # XXX desirable? |
| 42 prefix, rest = line.split(separator, 1) | 42 prefix, rest = line.split(separator, 1) |
| 43 if length is not None: | 43 if length is None: |
| 44 length = len(prefix) | 44 length = len(prefix) |
| 45 else: | 45 else: |
| 46 if len(prefix) != length: | 46 if len(prefix) != length: |
| 47 if not line[:len(prefix)].isspace(): | 47 if not line[:len(prefix)].isspace(): |
| 48 raise AssertionError # XXX | 48 raise AssertionError("Non whitespace found below pre (%s) in line %s" % (length, line)) |
| 49 stripped.append(line[length:]) | 49 stripped.append(line[length:]) |
| 50 return stripped | 50 return stripped |
| 51 | 51 |
| 52 @splitlines | 52 @splitlines |
| 53 def remove_lines(lines, startswith): | 53 def remove_lines(lines, startswith): |
| 74 joined.append(last) | 74 joined.append(last) |
| 75 continue | 75 continue |
| 76 if last: | 76 if last: |
| 77 last = '%s %s' % (last, line.strip()) | 77 last = '%s %s' % (last, line.strip()) |
| 78 else: | 78 else: |
| 79 joined.append(line.strip() | 79 joined.append(line.strip()) |
| 80 else: | 80 else: |
| 81 if last: | 81 if last: |
| 82 joined.append(last) | 82 joined.append(last) |
| 83 last = line.rstrip() | 83 last = line.rstrip() |
| 84 else: | 84 else: |
| 96 help="rewrite files in place") | 96 help="rewrite files in place") |
| 97 # parser.add_option - strip timestamps only | 97 # parser.add_option - strip timestamps only |
| 98 # parser.add_option - strip nicks | 98 # parser.add_option - strip nicks |
| 99 options, args = parser.parse_args(args) | 99 options, args = parser.parse_args(args) |
| 100 | 100 |
| 101 log = sys.stdin.read().strip() | |
| 102 | |
| 103 # strip timestamps | |
| 104 lines = strip_first_column(log) | |
| 105 | |
| 106 print '\n'.join(lines) | |
| 107 | |
| 101 if __name__ == '__main__': | 108 if __name__ == '__main__': |
| 102 main() | 109 main() |
