Revision: 5138 Author: russblau Date: 2008-03-17 14:27:11 +0000 (Mon, 17 Mar 2008)
Log Message: ----------- Tabify files, cleanup docstrings, suppress some non-critical messages in solve_disambiguation.py
Modified Paths: -------------- trunk/pywikipedia/maintenance/family_check.py trunk/pywikipedia/replace.py trunk/pywikipedia/solve_disambiguation.py trunk/pywikipedia/warnfile.py
Modified: trunk/pywikipedia/maintenance/family_check.py =================================================================== --- trunk/pywikipedia/maintenance/family_check.py 2008-03-16 20:02:16 UTC (rev 5137) +++ trunk/pywikipedia/maintenance/family_check.py 2008-03-17 14:27:11 UTC (rev 5138) @@ -7,56 +7,59 @@ import simplejson
def check_namespaces(site): - if not site.apipath(): - output(u'Warning! %s has no apipath() defined!' % site) - return - predata = {'action': 'query', - 'meta': 'siteinfo', - 'siprop': 'namespaces', - 'format': 'json'} - try: - response, json = site.postForm(site.apipath(), predata) - except wikipedia.ServerError, e: - output(u'Warning! %s: %s' % (site, e)) - return - try: - data = simplejson.loads(json) - except ValueError: - output(u'Warning! %s is defined but does not exist!' % site) - return - - result = [] - for namespace in data['query']['namespaces'].itervalues(): - try: - defined_namespace = site.namespace(namespace['id']) - except KeyError: - output(u'Warning! %s has no _default for namespace %s' % \ - (site, namespace['id'])) - defined_namespace = None - - if defined_namespace != namespace['*'] and namespace['*']: - result.append((namespace['id'], namespace['*'], defined_namespace)) - return result - + if not site.apipath(): + output(u'Warning! %s has no apipath() defined!' % site) + return + predata = { 'action': 'query', + 'meta': 'siteinfo', + 'siprop': 'namespaces', + 'format': 'json'} + try: + response, json = site.postForm(site.apipath(), predata) + except wikipedia.ServerError, e: + output(u'Warning! %s: %s' % (site, e)) + return + try: + data = simplejson.loads(json) + except ValueError: + output(u'Warning! %s is defined but does not exist!' % site) + return + + result = [] + for namespace in data['query']['namespaces'].itervalues(): + try: + defined_namespace = site.namespace(namespace['id']) + except KeyError: + output(u'Warning! %s has no _default for namespace %s' % \ + (site, namespace['id'])) + defined_namespace = None + + if defined_namespace != namespace['*'] and namespace['*']: + result.append((namespace['id'], namespace['*'], defined_namespace)) + return result + def check_family(family): - output(u'Checking namespaces for %s' % family.name) - result = {} - for lang in family.langs: - if not family.obsolete.has_key(lang): - site = wikipedia.getSite(lang, family) - output(u'Checking %s' % site) - namespaces = check_namespaces(site) - if namespaces: - for id, name, defined_namespace in namespaces: - output(u'Namespace %s for %s is %s, %s is defined in family file.' % \ - (id, site, name, defined_namespace)) - result[lang] = namespaces - return result - + output(u'Checking namespaces for %s' % family.name) + result = {} + for lang in family.langs: + if not family.obsolete.has_key(lang): + site = wikipedia.getSite(lang, family) + output(u'Checking %s' % site) + namespaces = check_namespaces(site) + if namespaces: + for id, name, defined_namespace in namespaces: + output(u'Namespace %s for %s is %s, %s is defined in family file.' % \ + (id, site, name, defined_namespace)) + result[lang] = namespaces + return result + if __name__ == '__main__': - wikipedia.handleArgs() - family = wikipedia.Family(wikipedia.default_family) - result = check_family(family) - output(u'Writing raw Python dictionary to stdout.') - output(u'Format is: (namespace_id, namespace_name, predefined_namespace)') - print result + try: + wikipedia.handleArgs() + family = wikipedia.Family(wikipedia.default_family) + result = check_family(family) + output(u'Writing raw Python dictionary to stdout.') + output(u'Format is: (namespace_id, namespace_name, predefined_namespace)') + print result + finally: + wikipedia.stopme()
Modified: trunk/pywikipedia/replace.py =================================================================== --- trunk/pywikipedia/replace.py 2008-03-16 20:02:16 UTC (rev 5137) +++ trunk/pywikipedia/replace.py 2008-03-17 14:27:11 UTC (rev 5138) @@ -27,19 +27,21 @@ before the one specified (may also be given as -xmlstart:Article).
--excepttitle:XYZ Skip pages with titles that contain XYZ. If the -regex argument - is given, XYZ will be regarded as a regular expression. +-excepttitle:XYZ Skip pages with titles that contain XYZ. If the -regex + argument is given, XYZ will be regarded as a regular + expression.
--excepttext:XYZ Skip pages which contain the text XYZ. If the -regex argument is - given, XYZ will be regarded as a regular expression. - --exceptinside:XYZ Skip occurences of the to-be-replaced text which lie within XYZ. - If the -regex argument is given, XYZ will be regarded as a regular +-excepttext:XYZ Skip pages which contain the text XYZ. If the -regex + argument is given, XYZ will be regarded as a regular expression.
--exceptinsidetag:XYZ Skip occurences of the to-be-replaced text which lie within an - XYZ tag. +-exceptinside:XYZ Skip occurences of the to-be-replaced text which lie + within XYZ. If the -regex argument is given, XYZ will be + regarded as a regular expression.
+-exceptinsidetag:XYZ Skip occurences of the to-be-replaced text which lie + within an XYZ tag. + -summary:XYZ Set the summary message text for the edit to XYZ, bypassing the predefined message texts with original and replacements inserted.
Modified: trunk/pywikipedia/solve_disambiguation.py =================================================================== --- trunk/pywikipedia/solve_disambiguation.py 2008-03-16 20:02:16 UTC (rev 5137) +++ trunk/pywikipedia/solve_disambiguation.py 2008-03-17 14:27:11 UTC (rev 5138) @@ -414,7 +414,9 @@ for ig in ignore_title[self.disambPage.site().family.name][self.disambPage.site().lang]: for i in range(len(refs)-1, -1, -1): if re.match(ig, refs[i].title()): - wikipedia.output('Ignoring page %s' % refs[i].title()) + if wikipedia.verbose: + wikipedia.output('Ignoring page %s' + % refs[i].title()) del refs[i] elif self.primaryIgnoreManager.isIgnored(refs[i]): #wikipedia.output('Ignoring page %s because it was skipped before' % refs[i].title())
Modified: trunk/pywikipedia/warnfile.py =================================================================== --- trunk/pywikipedia/warnfile.py 2008-03-16 20:02:16 UTC (rev 5137) +++ trunk/pywikipedia/warnfile.py 2008-03-17 14:27:11 UTC (rev 5138) @@ -27,7 +27,7 @@
def getHints(self): print "Parsing warnfile..." - R=re.compile(r'WARNING: (?P<family>.+?): [[(?P<locallang>.+?):(?P<localtitle>.+?)]](?P<warningtype>.+?)[[(?P<targetlang>.+?):(?P<targettitle>.+?)]]') + R=re.compile(r'WARNING: (?P<family>.+?): [[(?P<locallang>.+?):(?P<localtitle>.+?)]](?P<warningtype>.+?)[[(?P<targetlang>.+?):(?P<targettitle>.+?)]]') import codecs f = codecs.open(self.filename, 'r', 'utf-8') hints={}