Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorflorent <florent@toopy.org>2012-04-14 18:04:29 (GMT)
committer florent <florent@toopy.org>2012-04-14 18:04:29 (GMT)
commitb92af2e1a372f71fb2908d917b40ee244a8c8fb6 (patch)
tree38cb30e4f71ae1272ba76fa6732d6fafeace58bc
parent4913218ef26b6051067c3f712b51c2567be903e2 (diff)
add simple rst cleaner script
-rw-r--r--utils/rst-clean.py46
1 files changed, 46 insertions, 0 deletions
diff --git a/utils/rst-clean.py b/utils/rst-clean.py
new file mode 100644
index 0000000..840bbc7
--- /dev/null
+++ b/utils/rst-clean.py
@@ -0,0 +1,46 @@
+import codecs, optparse, os
+
+parser = optparse.OptionParser()
+parser.add_option("-f", "--file", dest="src_path",
+ help="Path to the .rst file to clean")
+parser.add_option("-r", "--replace", dest="replace", default=False,
+ help="Replace previous file with clean one?")
+
+(options, args) = parser.parse_args()
+
+if not options.src_path:
+ print '-f option is required'
+ exit(0)
+elif not os.path.exists(options.src_path):
+ print 'source path not found'
+ exit(0)
+
+if options.replace:
+ dest_path = options.src_path
+else:
+ dest_path = '__clean.rst'
+
+content = None
+
+with codecs.open(options.src_path, 'rb', 'utf-8') as f:
+ content = f.read().split('\n\n')
+
+
+def _join(lines):
+ row = ''
+ for l in lines.split('\n'):
+ l = l.strip()
+ if l.startswith('==')\
+ or l.startswith('--')\
+ or l.startswith('^^'):
+ row += '\n%s' % l
+ elif l.endswith('-'):
+ row += l.replace('-', '')
+ else:
+ row += '%s ' % l
+ return row
+
+
+with codecs.open(dest_path, 'wb', 'utf-8') as f:
+ f.write('\n\n'.join([_join(lines.strip()) for lines in content]))
+