commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] r3518 - usemod2trac


From: eb
Subject: [Commit-gnuradio] r3518 - usemod2trac
Date: Sun, 10 Sep 2006 19:07:07 -0600 (MDT)

Author: eb
Date: 2006-09-10 19:07:07 -0600 (Sun, 10 Sep 2006)
New Revision: 3518

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

Added: usemod2trac/README
===================================================================
--- usemod2trac/README                          (rev 0)
+++ usemod2trac/README  2006-09-11 01:07:07 UTC (rev 3518)
@@ -0,0 +1,39 @@
+#
+# 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.
+#
+
+Here are two tools to facilitate converting usemod wiki format to trac
+format:
+
+extract_pages_from_usemod.py: extracts the current version of each
+usemod wiki page and writes it to <pagename>.um.  You'll need to edit
+the path to the usemod wiki database at the top of the script.
+
+convert_usemod_to_trac.py: the command line args are the files
+containing usemod pages that are to be converted to trac wiki format.
+The -o <output-dir> option specifies the output directory for the
+converted pages.  convert_usemod_to_trac.py does not handle usemod
+table syntax, and probably some other things too.  It worked well
+enough for my purposes.  Perhaps it will for you too ;)
+
+Patches are welcome.  Send them to address@hidden
+
+
+
+

Added: usemod2trac/convert_usemod_to_trac.py
===================================================================
--- usemod2trac/convert_usemod_to_trac.py                               (rev 0)
+++ usemod2trac/convert_usemod_to_trac.py       2006-09-11 01:07:07 UTC (rev 
3518)
@@ -0,0 +1,52 @@
+#!/usr/bin/env python
+
+import sys
+import os
+import os.path
+import re
+from optparse import OptionParser
+
+def dequote(s):
+    s = s.replace('&amp;',  '&')
+    s = s.replace('&lt;' ,  '<')
+    s = s.replace('&gt;' ,  '>')
+    s = s.replace('&quot;', '"')
+    return s
+
+
+def convert_1(input_filename, output_filename):
+    ifile = open(input_filename, 'r')
+    ofile = open(output_filename, 'w')
+    s = ifile.read()
+    s = dequote(s)
+
+    # join lines with a backslash at the end
+    s = re.sub(r'\\ *\n', ' ', s)
+
+    ofile.write(s)
+
+
+def main():
+    usage = '%prog: [options] [file1.um]...'
+    parser = OptionParser()
+    parser.add_option('-o', '--output-directory', default='trac',
+                      help='specify output directory [default=%default]')
+    (options, args) = parser.parse_args()
+
+    output_directory = options.output_directory
+    if not os.path.isdir(output_directory):
+        try:
+            os.mkdir(output_directory, 0775)
+        except:
+            sys.stderr.write('failed to create directory \'%s\'' % (
+                output_directory,))
+            raise
+            
+    for input_filename in args:
+        convert_1(input_filename,
+                  os.path.join(output_directory,
+                               os.path.splitext(input_filename)[0]))
+
+if __name__ == '__main__':
+    main()
+    


Property changes on: usemod2trac/convert_usemod_to_trac.py
___________________________________________________________________
Name: svn:executable
   + *
Name: svn:eol-style
   + native

Added: usemod2trac/extract_pages_from_usemod.py
===================================================================
--- usemod2trac/extract_pages_from_usemod.py                            (rev 0)
+++ usemod2trac/extract_pages_from_usemod.py    2006-09-11 01:07:07 UTC (rev 
3518)
@@ -0,0 +1,79 @@
+#!/usr/bin/env python
+
+import os
+import os.path
+from pprint import pprint
+
+# FIXME set data_dir to the path to your usemod database
+data_dir = '/home/eb/build/wiki-snapshot/gnuradio_wikidb'
+
+page_dir = os.path.join(data_dir, 'page')
+
+# field separators
+
+FS = '\xb3'
+FS1 = FS + '1'
+FS2 = FS + '2'
+FS3 = FS + '3'
+
+def make_dict(sep, string):
+    L = string.split(sep)
+    assert len(L) % 2 == 0
+    d = {}
+    for i in range(0,len(L), 2):
+        d[L[i]] = L[i+1]
+    return d
+
+def open_page(page_id):
+    """
+    Return directory containing named sections
+    """
+    filename = os.path.join(page_dir, page_id[0], page_id + '.db')
+    f = open(filename, 'r')
+    page = f.read()
+    return make_dict(FS1, page)
+    
+def open_section(page_dir, section_id):
+    """
+    Return directory containing named subsections
+    """
+    return make_dict(FS2, page_dir[section_id])
+
+def open_subsection(section_dir, subsection_id):
+    """
+    Return directory containing named items
+    """
+    return make_dict(FS3, section_dir[subsection_id])
+
+
+def get_default_text(page_id):
+    page_dir = open_page(page_id)
+    section_dir = open_section(page_dir, 'text_default')
+    subsection_dir = open_subsection(section_dir, 'data')
+    return subsection_dir['text']
+    
+
+def visit(all_pages, dirname, names):
+    for n in names:
+        if n.endswith('.db'):
+            all_pages.append(n[0:-3])
+
+def generate_all_pages_list():
+    all_pages = []
+    os.path.walk(page_dir, visit, all_pages)
+    return all_pages
+
+def main():
+    all_pages = generate_all_pages_list()
+    #pprint(all_pages)
+    #pprint(open_page(all_pages[0]))
+    #pprint(get_default_text(all_pages[0]))
+
+    for page_id in all_pages:
+        text = get_default_text(page_id)
+        text = text.replace('\r\n', '\n')
+        fout = open(page_id + '.um', 'w')
+        fout.write(text)
+
+if __name__ == '__main__':
+    main()


Property changes on: usemod2trac/extract_pages_from_usemod.py
___________________________________________________________________
Name: svn:executable
   + *
Name: svn:eol-style
   + native





reply via email to

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