http://www.mediawiki.org/wiki/Special:Code/pywikipedia/11129
Revision: 11129 Author: xqt Date: 2013-02-25 13:04:55 +0000 (Mon, 25 Feb 2013) Log Message: ----------- rename testfamily to test_namespaces (like given update_namespaces) which is more describing what it does.
Added Paths: ----------- trunk/pywikipedia/maintenance/test_namespaces.py
Removed Paths: ------------- trunk/pywikipedia/maintenance/testfamily.py
Copied: trunk/pywikipedia/maintenance/test_namespaces.py (from rev 11128, trunk/pywikipedia/maintenance/testfamily.py) =================================================================== --- trunk/pywikipedia/maintenance/test_namespaces.py (rev 0) +++ trunk/pywikipedia/maintenance/test_namespaces.py 2013-02-25 13:04:55 UTC (rev 11129) @@ -0,0 +1,102 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +""" +This utility's primary use is to find all mismatches between the namespace +naming in the family files and the language files on the wiki servers. + +If the -all parameter is used, it runs through all known languages in a family. + +-langs and -families parameters may be used to check comma-seperated languages/families. + +If the -wikimedia parameter is used, all Wikimedia families are checked. + +Examples: + + python testfamily.py -family:wiktionary -lang:en + + python testfamily.py -family:wikipedia -all -log:logfilename.txt + + python testfamily.py -families:wikipedia,wiktionary -langs:en,fr + + python testfamily.py -wikimedia -all + +""" +# +# (C) Yuri Astrakhan, 2005 +# (C) Pywikipedia bot team, 2006-2013 +# +# Distributed under the terms of the MIT license. +# +__version__ = '$Id$' +# + +import sys +sys.path.insert(1, '..') + +import wikipedia as pywikibot +import traceback + +def testSite(site): + try: + pywikibot.getall(site, [pywikibot.Page(site, 'Any page name')]) + except KeyboardInterrupt: + raise + except pywikibot.NoSuchSite: + pywikibot.output( u'No such language %s' % site.lang ) + except: + pywikibot.output( u'Error processing language %s' % site.lang ) + pywikibot.output( u''.join(traceback.format_exception(*sys.exc_info()))) + +def main(): + all = False + language = None + fam = None + wikimedia = False + for arg in pywikibot.handleArgs(): + if arg == '-all': + all = True + elif arg[0:7] == '-langs:': + language = arg[7:] + elif arg[0:10] == '-families:': + fam = arg[10:] + elif arg[0:10] == '-wikimedia': + wikimedia = True + + mySite = pywikibot.getSite() + if wikimedia: + families = ['commons', 'incubator', 'mediawiki', 'meta', 'species', + 'test', 'wikibooks', 'wikidata', 'wikinews', 'wikiquote', + 'wikisource', 'wikiversity', 'wikivoyage', 'wiktionary'] + elif fam is not None: + families = fam.split(',') + else: + families = [mySite.family.name,] + + for family in families: + try: + fam = pywikibot.Family(family) + except ValueError: + pywikibot.output(u'No such family %s' % family) + continue + if all: + for lang in fam.langs.iterkeys(): + testSite(pywikibot.getSite(lang, family)) + elif language is None: + lang = mySite.lang + if not lang in fam.langs.keys(): + lang = fam.langs.keys()[-1] + testSite(pywikibot.getSite(lang, family)) + else: + languages = language.split(',') + for lang in languages: + try: + testSite(pywikibot.getSite(lang, family)) + except pywikibot.NoSuchSite: + pywikibot.output(u'No such language %s in family %s' + % (lang, family)) + +if __name__ == "__main__": + try: + main() + finally: + pywikibot.stopme()
Deleted: trunk/pywikipedia/maintenance/testfamily.py =================================================================== --- trunk/pywikipedia/maintenance/testfamily.py 2013-02-25 13:02:36 UTC (rev 11128) +++ trunk/pywikipedia/maintenance/testfamily.py 2013-02-25 13:04:55 UTC (rev 11129) @@ -1,102 +0,0 @@ -#!/usr/bin/python -# -*- coding: utf-8 -*- -""" -This utility's primary use is to find all mismatches between the namespace -naming in the family files and the language files on the wiki servers. - -If the -all parameter is used, it runs through all known languages in a family. - --langs and -families parameters may be used to check comma-seperated languages/families. - -If the -wikimedia parameter is used, all Wikimedia families are checked. - -Examples: - - python testfamily.py -family:wiktionary -lang:en - - python testfamily.py -family:wikipedia -all -log:logfilename.txt - - python testfamily.py -families:wikipedia,wiktionary -langs:en,fr - - python testfamily.py -wikimedia -all - -""" -# -# (C) Yuri Astrakhan, 2005 -# (C) Pywikipedia bot team, 2006-2013 -# -# Distributed under the terms of the MIT license. -# -__version__ = '$Id$' -# - -import sys -sys.path.insert(1, '..') - -import wikipedia as pywikibot -import traceback - -def testSite(site): - try: - pywikibot.getall(site, [pywikibot.Page(site, 'Any page name')]) - except KeyboardInterrupt: - raise - except pywikibot.NoSuchSite: - pywikibot.output( u'No such language %s' % site.lang ) - except: - pywikibot.output( u'Error processing language %s' % site.lang ) - pywikibot.output( u''.join(traceback.format_exception(*sys.exc_info()))) - -def main(): - all = False - language = None - fam = None - wikimedia = False - for arg in pywikibot.handleArgs(): - if arg == '-all': - all = True - elif arg[0:7] == '-langs:': - language = arg[7:] - elif arg[0:10] == '-families:': - fam = arg[10:] - elif arg[0:10] == '-wikimedia': - wikimedia = True - - mySite = pywikibot.getSite() - if wikimedia: - families = ['commons', 'incubator', 'mediawiki', 'meta', 'species', - 'test', 'wikibooks', 'wikidata', 'wikinews', 'wikiquote', - 'wikisource', 'wikiversity', 'wikivoyage', 'wiktionary'] - elif fam is not None: - families = fam.split(',') - else: - families = [mySite.family.name,] - - for family in families: - try: - fam = pywikibot.Family(family) - except ValueError: - pywikibot.output(u'No such family %s' % family) - continue - if all: - for lang in fam.langs.iterkeys(): - testSite(pywikibot.getSite(lang, family)) - elif language is None: - lang = mySite.lang - if not lang in fam.langs.keys(): - lang = fam.langs.keys()[-1] - testSite(pywikibot.getSite(lang, family)) - else: - languages = language.split(',') - for lang in languages: - try: - testSite(pywikibot.getSite(lang, family)) - except pywikibot.NoSuchSite: - pywikibot.output(u'No such language %s in family %s' - % (lang, family)) - -if __name__ == "__main__": - try: - main() - finally: - pywikibot.stopme()
pywikipedia-svn@lists.wikimedia.org