]> projects.mako.cc - mw/commitdiff
Centralize pagename/filename conversions
authorIan Weller <ian@ianweller.org>
Tue, 22 Dec 2009 07:41:07 +0000 (01:41 -0600)
committerIan Weller <ian@ianweller.org>
Tue, 22 Dec 2009 07:41:07 +0000 (01:41 -0600)
src/mw/api.py
src/mw/clicommands.py

index bd12bb0ffd2f15f5011398d6f4d14b4f6594de81..8961f5d8a00d14cc408146f237c5c44570de92c4 100644 (file)
@@ -55,3 +55,14 @@ class API(object):
             return high
         else:
             return low
             return high
         else:
             return low
+
+
+def pagename_to_filename(name):
+    name.replace(' ', '_')
+    name.replace('/', '!')
+    return name
+
+def filename_to_pagename(name):
+    name.replace('!', '/')
+    name.replace('_', ' ')
+    return name
index ccfc9cb3f7fc2b574bfa37c3a7d414fc34112921..1d5f5c8589173e5a4e7bdf91a279d072e424e7c0 100644 (file)
@@ -91,17 +91,16 @@ class FetchCommand(CommandBase):
             }
             response = self.api.call(data)['query']['pages']
             for pageid in response.keys():
             }
             response = self.api.call(data)['query']['pages']
             for pageid in response.keys():
+                pagename = response[pageid]['title']
                 if 'missing' in response[pageid].keys():
                     print '%s: %s: page does not exist, file not created' % \
                 if 'missing' in response[pageid].keys():
                     print '%s: %s: page does not exist, file not created' % \
-                            (self.me, response[pageid]['title'])
+                            (self.me, pagename)
                     continue
                 revid = [x['revid'] for x in response[pageid]['revisions']]
                     continue
                 revid = [x['revid'] for x in response[pageid]['revisions']]
-                self.metadir.pagedict_add(response[pageid]['title'],
-                                          int(pageid))
+                self.metadir.pagedict_add(pagename, int(pageid))
                 self.metadir.pages_add_rev(int(pageid),
                                            response[pageid]['revisions'][0])
                 self.metadir.pages_add_rev(int(pageid),
                                            response[pageid]['revisions'][0])
-                filename = response[pageid]['title'].replace(' ', '_')
-                filename = filename.replace('/', '!')
+                filename = mw.api.pagename_to_filename(pagename)
                 fd = file(os.path.join(self.metadir.root, filename + '.wiki'),
                           'w')
                 fd.write(response[pageid]['revisions'][0]['*'].encode('utf-8'))
                 fd = file(os.path.join(self.metadir.root, filename + '.wiki'),
                           'w')
                 fd.write(response[pageid]['revisions'][0]['*'].encode('utf-8'))

Benjamin Mako Hill || Want to submit a patch?