Changeset 3519
- Timestamp:
- 09/10/06 22:25:45
- Files:
-
- usemod2trac/convert_usemod_to_trac.py (modified) (5 diffs)
- usemod2trac/extract_pages_from_usemod.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
usemod2trac/convert_usemod_to_trac.py
r3518 r3519 1 1 #!/usr/bin/env python 2 # 3 # Copyright 2006 Free Software Foundation, Inc. 4 # 5 # This file is part of GNU Radio 6 # 7 # GNU Radio is free software; you can redistribute it and/or modify 8 # it under the terms of the GNU General Public License as published by 9 # the Free Software Foundation; either version 2, or (at your option) 10 # any later version. 11 # 12 # GNU Radio is distributed in the hope that it will be useful, 13 # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 # GNU General Public License for more details. 16 # 17 # You should have received a copy of the GNU General Public License along 18 # with this program; if not, write to the Free Software Foundation, Inc., 19 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20 # 2 21 3 22 import sys … … 7 26 from optparse import OptionParser 8 27 28 # field separator 29 FS = '\xb3' 30 31 text_stash = [] 32 9 33 def dequote(s): 10 34 s = s.replace('&', '&') … … 12 36 s = s.replace('>' , '>') 13 37 s = s.replace('"', '"') 38 return s 39 40 41 def mo_group(n, f): 42 return lambda match_object: f(match_object.group(n)) 43 44 45 def store_raw(text): 46 r = len(text_stash) 47 text_stash.append(text) 48 return FS + str(r) + FS 49 50 51 def store_pre(text): 52 return store_raw('{{{' + text + '}}}') 53 54 55 def restore_saved_text(s): 56 pat = re.compile(FS + r'(\d+)' + FS) 57 while 1: 58 s, n = pat.subn(mo_group(1, lambda digits: text_stash[int(digits)]), s) 59 if n == 0: # no substitutions made 60 return s 61 62 63 64 nowiki_re = re.compile(r'<nowiki>(.*?)</nowiki>', re.IGNORECASE | re.DOTALL) 65 code_re = re.compile(r'<code>(.*?)</code>', re.IGNORECASE | re.DOTALL) 66 pre_re = re.compile(r'<pre>(.*?)</pre>', re.IGNORECASE | re.DOTALL) 67 68 def handle_multiline_markup(s): 69 # The <nowiki> tag stores text with no markup 70 s = nowiki_re.sub(mo_group(1, store_raw), s) 71 # The <code> tag stores text with no {{{ markup }}} 72 s = code_re.sub(mo_group(1, store_pre), s) 73 # The <pre> tag stores text with no {{{ markup }}} 74 s = pre_re.sub(mo_group(1, store_pre), s) 14 75 return s 15 76 … … 24 85 s = re.sub(r'\\ *\n', ' ', s) 25 86 87 s = handle_multiline_markup(s) 88 89 s = restore_saved_text(s) 26 90 ofile.write(s) 27 91 … … 46 110 convert_1(input_filename, 47 111 os.path.join(output_directory, 48 os.path. splitext(input_filename)[0]))112 os.path.basename(os.path.splitext(input_filename)[0]))) 49 113 50 114 if __name__ == '__main__': usemod2trac/extract_pages_from_usemod.py
r3518 r3519 1 1 #!/usr/bin/env python 2 # 3 # Copyright 2006 Free Software Foundation, Inc. 4 # 5 # This file is part of GNU Radio 6 # 7 # GNU Radio is free software; you can redistribute it and/or modify 8 # it under the terms of the GNU General Public License as published by 9 # the Free Software Foundation; either version 2, or (at your option) 10 # any later version. 11 # 12 # GNU Radio is distributed in the hope that it will be useful, 13 # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 # GNU General Public License for more details. 16 # 17 # You should have received a copy of the GNU General Public License along 18 # with this program; if not, write to the Free Software Foundation, Inc., 19 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20 # 2 21 3 22 import os
