Revision: 4579 Author: btongminh Date: 2007-11-21 09:48:11 +0000 (Wed, 21 Nov 2007)
Log Message: ----------- Fixing eol style
Modified Paths: -------------- trunk/pywikipedia/maintenance/family_check.py trunk/pywikipedia/maintenance/setmail.py trunk/pywikipedia/maintenance/update_namespaces.py
Property Changed: ---------------- trunk/pywikipedia/maintenance/family_check.py trunk/pywikipedia/maintenance/preferences.py trunk/pywikipedia/maintenance/setmail.py trunk/pywikipedia/maintenance/update_namespaces.py
Modified: trunk/pywikipedia/maintenance/family_check.py =================================================================== --- trunk/pywikipedia/maintenance/family_check.py 2007-11-21 09:45:28 UTC (rev 4578) +++ trunk/pywikipedia/maintenance/family_check.py 2007-11-21 09:48:11 UTC (rev 4579) @@ -1,61 +1,61 @@ -import sys -sys.path.append('..') - -import wikipedia, config -from wikipedia import output - -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 - -def check_family(family): - output(u'Checking namespaces for %s' % family.name) - result = {} - for lang in family.langs: - 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)') +import sys +sys.path.append('..') + +import wikipedia, config +from wikipedia import output + +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 + +def check_family(family): + output(u'Checking namespaces for %s' % family.name) + result = {} + for lang in family.langs: + 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 \ No newline at end of file
Property changes on: trunk/pywikipedia/maintenance/family_check.py ___________________________________________________________________ Name: svn:eol-style + native
Property changes on: trunk/pywikipedia/maintenance/preferences.py ___________________________________________________________________ Name: svn:eol-style + native
Modified: trunk/pywikipedia/maintenance/setmail.py =================================================================== --- trunk/pywikipedia/maintenance/setmail.py 2007-11-21 09:45:28 UTC (rev 4578) +++ trunk/pywikipedia/maintenance/setmail.py 2007-11-21 09:48:11 UTC (rev 4579) @@ -1,63 +1,63 @@ -""" This tool sets an email address on all bot accounts and email confirms them.""" - -import sys, os, getpass -sys.path.append('..') - -import poplib -import wikipedia, config -import preferences -import re -import urllib2 - -def confirm(link): - req = urllib2.Request(link, headers = {'User-Agent': wikipedia.useragent}) - u = urllib2.urlopen(req) - u.close() - -if __name__ == '__main__': - r_mail = re.compile(ur'(http://\S*Confirmemail\S*)') - - email = wikipedia.input('Email?') - host = wikipedia.input('Host?') - port = wikipedia.input('Port (default: 110; ssl: 995)?') - try: - port = int(port) - except ValueError: - port = 0 - if not port: - port = 110 - ssl = wikipedia.inputChoice('SSL? ', ['no', 'yes'], - ['n', 'y'], (port == 995) and 'y' or 'n') == 'y' - username = wikipedia.input('User?') - password = wikipedia.input('Password?', True) - do_delete = wikipedia.inputChoice('Delete confirmed mails?', ['yes', 'no'], ['y', 'n'], 'y') == 'y' - - if email: - preferences.set_all(['wpUserEmail', 'wpEmailFlag', 'wpOpenotifusertalkpages'], - [email, True, False], verbose = True) - - if ssl: - pop = poplib.POP3_SSL(host, port) - else: - pop = poplib.POP3(host, port) - - pop.user(username) - pop.pass_(password) - wikipedia.output(unicode(pop.getwelcome())) - messages = [i.split(' ', 1)[0] for i in pop.list()[1]] - for i in messages: - msg = pop.retr(i) - confirmed = False - for line in msg[1]: - if r_mail.search(line): - confirmed = True - link = r_mail.search(line).group(1) - wikipedia.output(u'Confirming %s.' % link) - confirm(link) - - if not confirmed: - wikipedia.output(u'Unconfirmed mail!') - elif do_delete: - pop.dele(i) - pop.quit() - +""" This tool sets an email address on all bot accounts and email confirms them.""" + +import sys, os, getpass +sys.path.append('..') + +import poplib +import wikipedia, config +import preferences +import re +import urllib2 + +def confirm(link): + req = urllib2.Request(link, headers = {'User-Agent': wikipedia.useragent}) + u = urllib2.urlopen(req) + u.close() + +if __name__ == '__main__': + r_mail = re.compile(ur'(http://\S*Confirmemail\S*)') + + email = wikipedia.input('Email?') + host = wikipedia.input('Host?') + port = wikipedia.input('Port (default: 110; ssl: 995)?') + try: + port = int(port) + except ValueError: + port = 0 + if not port: + port = 110 + ssl = wikipedia.inputChoice('SSL? ', ['no', 'yes'], + ['n', 'y'], (port == 995) and 'y' or 'n') == 'y' + username = wikipedia.input('User?') + password = wikipedia.input('Password?', True) + do_delete = wikipedia.inputChoice('Delete confirmed mails?', ['yes', 'no'], ['y', 'n'], 'y') == 'y' + + if email: + preferences.set_all(['wpUserEmail', 'wpEmailFlag', 'wpOpenotifusertalkpages'], + [email, True, False], verbose = True) + + if ssl: + pop = poplib.POP3_SSL(host, port) + else: + pop = poplib.POP3(host, port) + + pop.user(username) + pop.pass_(password) + wikipedia.output(unicode(pop.getwelcome())) + messages = [i.split(' ', 1)[0] for i in pop.list()[1]] + for i in messages: + msg = pop.retr(i) + confirmed = False + for line in msg[1]: + if r_mail.search(line): + confirmed = True + link = r_mail.search(line).group(1) + wikipedia.output(u'Confirming %s.' % link) + confirm(link) + + if not confirmed: + wikipedia.output(u'Unconfirmed mail!') + elif do_delete: + pop.dele(i) + pop.quit() +
Property changes on: trunk/pywikipedia/maintenance/setmail.py ___________________________________________________________________ Name: svn:eol-style + native
Modified: trunk/pywikipedia/maintenance/update_namespaces.py =================================================================== --- trunk/pywikipedia/maintenance/update_namespaces.py 2007-11-21 09:45:28 UTC (rev 4578) +++ trunk/pywikipedia/maintenance/update_namespaces.py 2007-11-21 09:48:11 UTC (rev 4579) @@ -1,74 +1,74 @@ -import sys -sys.path.append('..') - -import wikipedia -from wikipedia import output - -import family_check -import re - -r_namespace_section = r'(?s)self.namespaces[%s]\s*=\s*{(.*?)}' - -r_string = '[u]?[r]?['"].*?['"]' -r_list = '\[.*?\]' -r_namespace_def = re.compile(r'['"]([a-z_-]*)['"]\s*:\s*((?:%s)|(?:%s))\s*,' % (r_string, r_list)) -def update_family(family, changes): - global namespace_section_text, namespace_defs, new_defs - - output(u'Updating family %s' % family) - family_file = open('../families/%s_family.py' % family.name, 'r') - old_family_text = family_text = family_file.read() - family_file.close() - - for lang, namespaces in changes.iteritems(): - for namespace_id, namespace_name, predefined_namespace in namespaces: - output(u'Setting namespace[%s] for %s to %s' % (namespace_id, lang, namespace_name)) - - namespace_section = re.search(r_namespace_section % namespace_id, family_text) - if not namespace_section: - continue - namespace_section_text = namespace_section.group(1) - namespace_defs = dict([(match.group(1), match.group(2)) - for match in r_namespace_def.finditer(namespace_section_text)]) - - if not namespace_defs.get(lang, '').startswith('['): - output(u'Updating namespace[%s] to %s' % (namespace_id, namespace_name)) - - namespace_defs[lang] = escape_string(namespace_name.encode('utf-8')) - else: - output(u'Namespace[%s] definition is a list; not updating.' % namespace_id) - - new_defs = namespace_defs.items() - new_defs.sort(key = lambda x: x[0]) - new_text = '\n' + ''.join([12 * ' ' + "'%s': %s,\n" % i for i in new_defs]) + ' ' * 8 - family_text = family_text.replace(namespace_section.group(1), new_text) - - if test_data(family_text): - output(u'Saving to family file') - family_file = open('../families/%s_family.py' % family.name, 'w') - family_file.write(family_text) - family_file.close() - else: - output(u'Warning! Syntax error!') - output(family_text.decode('utf-8')) - -def escape_string(string): - return "u'%s'" % string.replace('\', '\\').replace("'", "\'") - -def test_data(_test_data): - try: - exec _test_data - except SyntaxError: - return False - except: - return True - return True - -if __name__ == '__main__': - try: - wikipedia.handleArgs() - family = wikipedia.Family(wikipedia.default_family) - result = family_check.check_family(family) - update_family(family, result) - finally: +import sys +sys.path.append('..') + +import wikipedia +from wikipedia import output + +import family_check +import re + +r_namespace_section = r'(?s)self.namespaces[%s]\s*=\s*{(.*?)}' + +r_string = '[u]?[r]?['"].*?['"]' +r_list = '\[.*?\]' +r_namespace_def = re.compile(r'['"]([a-z_-]*)['"]\s*:\s*((?:%s)|(?:%s))\s*,' % (r_string, r_list)) +def update_family(family, changes): + global namespace_section_text, namespace_defs, new_defs + + output(u'Updating family %s' % family) + family_file = open('../families/%s_family.py' % family.name, 'r') + old_family_text = family_text = family_file.read() + family_file.close() + + for lang, namespaces in changes.iteritems(): + for namespace_id, namespace_name, predefined_namespace in namespaces: + output(u'Setting namespace[%s] for %s to %s' % (namespace_id, lang, namespace_name)) + + namespace_section = re.search(r_namespace_section % namespace_id, family_text) + if not namespace_section: + continue + namespace_section_text = namespace_section.group(1) + namespace_defs = dict([(match.group(1), match.group(2)) + for match in r_namespace_def.finditer(namespace_section_text)]) + + if not namespace_defs.get(lang, '').startswith('['): + output(u'Updating namespace[%s] to %s' % (namespace_id, namespace_name)) + + namespace_defs[lang] = escape_string(namespace_name.encode('utf-8')) + else: + output(u'Namespace[%s] definition is a list; not updating.' % namespace_id) + + new_defs = namespace_defs.items() + new_defs.sort(key = lambda x: x[0]) + new_text = '\n' + ''.join([12 * ' ' + "'%s': %s,\n" % i for i in new_defs]) + ' ' * 8 + family_text = family_text.replace(namespace_section.group(1), new_text) + + if test_data(family_text): + output(u'Saving to family file') + family_file = open('../families/%s_family.py' % family.name, 'w') + family_file.write(family_text) + family_file.close() + else: + output(u'Warning! Syntax error!') + output(family_text.decode('utf-8')) + +def escape_string(string): + return "u'%s'" % string.replace('\', '\\').replace("'", "\'") + +def test_data(_test_data): + try: + exec _test_data + except SyntaxError: + return False + except: + return True + return True + +if __name__ == '__main__': + try: + wikipedia.handleArgs() + family = wikipedia.Family(wikipedia.default_family) + result = family_check.check_family(family) + update_family(family, result) + finally: wikipedia.stopme() \ No newline at end of file
Property changes on: trunk/pywikipedia/maintenance/update_namespaces.py ___________________________________________________________________ Name: svn:eol-style + native