diff options
author | ben <ben@2b77aa54-bcbc-44c9-a7ec-4f6cf2b41109> | 2002-03-21 07:22:43 +0000 |
---|---|---|
committer | ben <ben@2b77aa54-bcbc-44c9-a7ec-4f6cf2b41109> | 2002-03-21 07:22:43 +0000 |
commit | 8c37a5bdfdd46d5cfad6e9d67925ddef9ca382bf (patch) | |
tree | 8f19be83962ef31d8ad58429d575c6f17d89c0ea /rdiff-backup/misc/remove-comments.py | |
parent | 8259a0d8a9ad1396a93cd6320943dc33446ac6ed (diff) | |
download | rdiff-backup-8c37a5bdfdd46d5cfad6e9d67925ddef9ca382bf.tar.gz |
First checkin
git-svn-id: http://svn.savannah.nongnu.org/svn/rdiff-backup/trunk@2 2b77aa54-bcbc-44c9-a7ec-4f6cf2b41109
Diffstat (limited to 'rdiff-backup/misc/remove-comments.py')
-rw-r--r-- | rdiff-backup/misc/remove-comments.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/rdiff-backup/misc/remove-comments.py b/rdiff-backup/misc/remove-comments.py new file mode 100644 index 0000000..e24e3ba --- /dev/null +++ b/rdiff-backup/misc/remove-comments.py @@ -0,0 +1,32 @@ +#!/usr/bin/env python + +"""remove-comments.py + +Given a python program on standard input, spit one out on stdout that +should work the same, but has blank and comment lines removed. + +""" + +import sys, re + +triple_regex = re.compile('"""') + +def eattriple(initial_line_stripped): + """Keep reading until end of doc string""" + assert initial_line_stripped.startswith('"""') + if triple_regex.search(initial_line_stripped[3:]): return + while 1: + line = sys.stdin.readline() + if not line or triple_regex.search(line): break + +while 1: + line = sys.stdin.readline() + if not line: break + stripped = line.strip() + if not stripped: continue + if stripped[0] == "#": continue + if stripped.startswith('"""'): + eattriple(stripped) + continue + sys.stdout.write(line) + |