Mercurial > hg > config
comparison python/stripirssi.py @ 442:3982b7ad596b
python/stripirssi.py
| author | Jeff Hammel <jhammel@mozilla.com> |
|---|---|
| date | Fri, 09 Aug 2013 15:23:59 -0700 |
| parents | f81fdc6926fd |
| children |
comparison
equal
deleted
inserted
replaced
| 441:f81fdc6926fd | 442:3982b7ad596b |
|---|---|
| 37 length = None # length of first column | 37 length = None # length of first column |
| 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 try: |
| 43 prefix, rest = line.split(separator, 1) | |
| 44 except ValueError: | |
| 45 import pdb; pdb.set_trace() | |
| 46 prefix, rest = None, None | |
| 43 if length is None: | 47 if length is None: |
| 44 length = len(prefix) | 48 length = len(prefix) |
| 45 else: | 49 else: |
| 46 if len(prefix) != length: | 50 if len(prefix) != length: |
| 47 if not line[:len(prefix)].isspace(): | 51 if not line[:len(prefix)].isspace(): |
| 54 return [line for line in lines | 58 return [line for line in lines |
| 55 if line.startswith(startswith)] | 59 if line.startswith(startswith)] |
| 56 # really, one could take most functions for str and map -> lines | 60 # really, one could take most functions for str and map -> lines |
| 57 | 61 |
| 58 @splitlines | 62 @splitlines |
| 59 def remove_time(lines): | 63 def remove_prefix_stamp(lines, stamp): |
| 60 """removes leading 24 hour timestamp: HH:MM""" | 64 """removes leading stamp: HH:MM""" |
| 61 # XXX :ss? | 65 return [line[len(stamp):] for line in lines] |
| 62 | 66 |
| 63 @splitlines | 67 @splitlines |
| 64 def join(lines): | 68 def join(lines): |
| 65 """DOCUMENT ME!""" | 69 """DOCUMENT ME!""" |
| 66 last = None | 70 last = None |
| 86 joined.append(last) | 90 joined.append(last) |
| 87 return joined | 91 return joined |
| 88 | 92 |
| 89 ### CLI | 93 ### CLI |
| 90 | 94 |
| 95 | |
| 96 | |
| 91 def main(args=sys.argv[1:]): | 97 def main(args=sys.argv[1:]): |
| 92 | 98 |
| 99 # parse command line | |
| 93 usage = '%prog [options]' | 100 usage = '%prog [options]' |
| 94 parser = optparse.OptionParser(usage=usage, description=__doc__) | 101 parser = optparse.OptionParser(usage=usage, description=__doc__) |
| 95 parser.add_option('-i', '--in-place', dest='in_place', | 102 parser.add_option('-i', '--in-place', dest='in_place', |
| 96 help="rewrite files in place") | 103 help="rewrite files in place") |
| 97 # parser.add_option - strip timestamps only | 104 # parser.add_option - strip timestamps only |
| 102 | 109 |
| 103 # strip timestamps | 110 # strip timestamps |
| 104 lines = strip_first_column(log) | 111 lines = strip_first_column(log) |
| 105 | 112 |
| 106 import pdb; pdb.set_trace() | 113 import pdb; pdb.set_trace() |
| 114 | |
| 107 | 115 |
| 108 print '\n'.join(lines) | 116 print '\n'.join(lines) |
| 109 | 117 |
| 110 if __name__ == '__main__': | 118 if __name__ == '__main__': |
| 111 main() | 119 main() |
