testfamily.py :  » Network » Python-Wikipedia-Robot-Framework » pywikipedia » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Network » Python Wikipedia Robot Framework 
Python Wikipedia Robot Framework » pywikipedia » testfamily.py
#!/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
#
# Distributed under the terms of the MIT license.
#
__version__ = '$Id: testfamily.py 6540 2009-03-24 01:15:50Z nicdumz $'
#

import sys, wikipedia, traceback


#===========

def testSite(site):
    try:
        wikipedia.getall(site, [wikipedia.Page(site, 'Any page name')])
    except KeyboardInterrupt:
        raise
    except wikipedia.NoSuchSite:
        wikipedia.output( u'No such language %s' % site.lang )
    except:
        wikipedia.output( u'Error processing language %s' % site.lang )
        wikipedia.output( u''.join(traceback.format_exception(*sys.exc_info())))

def main():
    all = False
    language = None
    fam = None
    wikimedia = False
    for arg in wikipedia.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 = wikipedia.getSite()
    if language is None:
        language = mySite.lang
    if wikimedia:
        families = ['wikipedia', 'wiktionary', 'wikiquote', 'wikisource', 'wikibooks', 'wikinews', 'wikiversity', 'meta', 'commons', 'mediawiki', 'species', 'incubator', 'test']
    elif fam is not None:
        families = fam.split(',')
    else:
        families = [mySite.family.name,]

    for family in families:
        try:
            fam = wikipedia.Family(family)
        except ValueError:
            wikipedia.output(u'No such family %s' % family)
            continue
        if all:
            for lang in fam.langs.iterkeys():
                testSite(wikipedia.getSite(lang, family))
        else:
            languages = language.split(',')
            for lang in languages:
                try:
                    testSite(wikipedia.getSite(lang, family))
                except wikipedia.NoSuchSite:
                    wikipedia.output(u'No such language %s in family %s' % (lang, family))

if __name__ == "__main__":
    try:
        main()
    finally:
        wikipedia.stopme()
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.