commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] r3519 - usemod2trac


From: eb
Subject: [Commit-gnuradio] r3519 - usemod2trac
Date: Sun, 10 Sep 2006 22:25:45 -0600 (MDT)

Author: eb
Date: 2006-09-10 22:25:45 -0600 (Sun, 10 Sep 2006)
New Revision: 3519

Modified:
   usemod2trac/convert_usemod_to_trac.py
   usemod2trac/extract_pages_from_usemod.py
Log:
work-in-progress

Modified: usemod2trac/convert_usemod_to_trac.py
===================================================================
--- usemod2trac/convert_usemod_to_trac.py       2006-09-11 01:07:07 UTC (rev 
3518)
+++ usemod2trac/convert_usemod_to_trac.py       2006-09-11 04:25:45 UTC (rev 
3519)
@@ -1,4 +1,23 @@
 #!/usr/bin/env python
+#
+# Copyright 2006 Free Software Foundation, Inc.
+# 
+# This file is part of GNU Radio
+# 
+# GNU Radio is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+# 
+# GNU Radio is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+#
 
 import sys
 import os
@@ -6,6 +25,11 @@
 import re
 from optparse import OptionParser
 
+# field separator
+FS = '\xb3'
+
+text_stash = []
+
 def dequote(s):
     s = s.replace('&',  '&')
     s = s.replace('&lt;' ,  '<')
@@ -14,6 +38,43 @@
     return s
 
 
+def mo_group(n, f):
+    return lambda match_object: f(match_object.group(n))
+
+
+def store_raw(text):
+    r = len(text_stash)
+    text_stash.append(text)
+    return FS + str(r) + FS
+    
+
+def store_pre(text):
+    return store_raw('{{{' + text + '}}}')
+
+
+def restore_saved_text(s):
+    pat = re.compile(FS + r'(\d+)' + FS)
+    while 1:
+        s, n = pat.subn(mo_group(1, lambda digits: text_stash[int(digits)]), s)
+        if n == 0:     # no substitutions made
+            return s
+
+
+
+nowiki_re = re.compile(r'<nowiki>(.*?)</nowiki>', re.IGNORECASE | re.DOTALL)
+code_re   = re.compile(r'<code>(.*?)</code>',     re.IGNORECASE | re.DOTALL)
+pre_re    = re.compile(r'<pre>(.*?)</pre>',       re.IGNORECASE | re.DOTALL)
+
+def handle_multiline_markup(s):
+    # The <nowiki> tag stores text with no markup
+    s = nowiki_re.sub(mo_group(1, store_raw), s)
+    # The <code> tag stores text with no {{{ markup }}}
+    s = code_re.sub(mo_group(1, store_pre), s)
+    # The <pre> tag stores text with no {{{ markup }}}
+    s = pre_re.sub(mo_group(1, store_pre), s)
+    return s
+
+
 def convert_1(input_filename, output_filename):
     ifile = open(input_filename, 'r')
     ofile = open(output_filename, 'w')
@@ -23,6 +84,9 @@
     # join lines with a backslash at the end
     s = re.sub(r'\\ *\n', ' ', s)
 
+    s = handle_multiline_markup(s)
+
+    s = restore_saved_text(s)
     ofile.write(s)
 
 
@@ -45,7 +109,7 @@
     for input_filename in args:
         convert_1(input_filename,
                   os.path.join(output_directory,
-                               os.path.splitext(input_filename)[0]))
+                               
os.path.basename(os.path.splitext(input_filename)[0])))
 
 if __name__ == '__main__':
     main()

Modified: usemod2trac/extract_pages_from_usemod.py
===================================================================
--- usemod2trac/extract_pages_from_usemod.py    2006-09-11 01:07:07 UTC (rev 
3518)
+++ usemod2trac/extract_pages_from_usemod.py    2006-09-11 04:25:45 UTC (rev 
3519)
@@ -1,4 +1,23 @@
 #!/usr/bin/env python
+#
+# Copyright 2006 Free Software Foundation, Inc.
+# 
+# This file is part of GNU Radio
+# 
+# GNU Radio is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+# 
+# GNU Radio is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+#
 
 import os
 import os.path





reply via email to

[Prev in Thread] Current Thread [Next in Thread]