Changeset 3519

Show
Ignore:
Timestamp:
09/10/06 22:25:45
Author:
eb
Message:

work-in-progress

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • usemod2trac/convert_usemod_to_trac.py

    r3518 r3519  
    11#!/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# 
    221 
    322import sys 
     
    726from optparse import OptionParser 
    827 
     28# field separator 
     29FS = '\xb3' 
     30 
     31text_stash = [] 
     32 
    933def dequote(s): 
    1034    s = s.replace('&',  '&') 
     
    1236    s = s.replace('>' ,  '>') 
    1337    s = s.replace('"', '"') 
     38    return s 
     39 
     40 
     41def mo_group(n, f): 
     42    return lambda match_object: f(match_object.group(n)) 
     43 
     44 
     45def store_raw(text): 
     46    r = len(text_stash) 
     47    text_stash.append(text) 
     48    return FS + str(r) + FS 
     49     
     50 
     51def store_pre(text): 
     52    return store_raw('{{{' + text + '}}}') 
     53 
     54 
     55def 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 
     64nowiki_re = re.compile(r'<nowiki>(.*?)</nowiki>', re.IGNORECASE | re.DOTALL) 
     65code_re   = re.compile(r'<code>(.*?)</code>',     re.IGNORECASE | re.DOTALL) 
     66pre_re    = re.compile(r'<pre>(.*?)</pre>',       re.IGNORECASE | re.DOTALL) 
     67 
     68def 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) 
    1475    return s 
    1576 
     
    2485    s = re.sub(r'\\ *\n', ' ', s) 
    2586 
     87    s = handle_multiline_markup(s) 
     88 
     89    s = restore_saved_text(s) 
    2690    ofile.write(s) 
    2791 
     
    46110        convert_1(input_filename, 
    47111                  os.path.join(output_directory, 
    48                                os.path.splitext(input_filename)[0])) 
     112                               os.path.basename(os.path.splitext(input_filename)[0]))) 
    49113 
    50114if __name__ == '__main__': 
  • usemod2trac/extract_pages_from_usemod.py

    r3518 r3519  
    11#!/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# 
    221 
    322import os