From: Ian Weller Date: Tue, 22 Dec 2009 07:41:07 +0000 (-0600) Subject: Centralize pagename/filename conversions X-Git-Url: https://projects.mako.cc/source/mw/commitdiff_plain/0a1a538268a9a63fa3014b9b2534ee01dd8eefd4?hp=0e4d5bae708769d63d12270f1309d13e81cfbbfb Centralize pagename/filename conversions --- diff --git a/src/mw/api.py b/src/mw/api.py index bd12bb0..8961f5d 100644 --- a/src/mw/api.py +++ b/src/mw/api.py @@ -55,3 +55,14 @@ class API(object): 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 diff --git a/src/mw/clicommands.py b/src/mw/clicommands.py index ccfc9cb..1d5f5c8 100644 --- a/src/mw/clicommands.py +++ b/src/mw/clicommands.py @@ -91,17 +91,16 @@ class FetchCommand(CommandBase): } 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' % \ - (self.me, response[pageid]['title']) + (self.me, pagename) 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]) - 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'))