r81092 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r81091‎ | r81092 | r81093 >
Date:16:07, 27 January 2011
Author:diederik
Status:deferred
Tags:
Comment:
Minor bug fixes.
Modified paths:
  • /trunk/tools/editor_trends/classes/languages.py (modified) (history)
  • /trunk/tools/editor_trends/classes/runtime_settings.py (modified) (history)

Diff [purge]

Index: trunk/tools/editor_trends/classes/runtime_settings.py
@@ -52,12 +52,14 @@
5353 if args:
5454 self.args = args
5555 self.hash = self.secs_since_epoch()
56 - self.base_location = self.get_value('location') \
57 - if self.get_value('location') != None else settings.input_location
 56+ print self.settings.input_location
 57+ print self.settings.working_directory
 58+ self.base_location = self.settings.input_location if \
 59+ self.settings.input_location != None else self.get_value('location')
5860 self.update_project_settings()
5961 self.update_language_settings()
6062
61 - self.targets = self.get_value('charts')
 63+ self.targets = self.split_keywords(self.get_value('charts'))
6264 self.keywords = self.split_keywords(self.get_value('keywords'))
6365 self.function = self.get_value('func')
6466 self.collection = self.get_value('collection')
@@ -65,6 +67,8 @@
6668 self.clean = self.get_value('new')
6769 self.force = self.get_value('force')
6870 self.location = self.get_project_location()
 71+ print self.location
 72+ print self.settings.working_directory
6973 self.filename = self.generate_wikidump_filename()
7074 self.namespaces = self.get_namespaces()
7175
@@ -82,7 +86,6 @@
8387 self.dataset,
8488 self.charts]
8589 self.path = '/%s/latest/' % self.project
86 - self.targets = self.targets.split(', ')
8790 settings.verify_environment(self.directories)
8891
8992 def __str__(self):
@@ -102,11 +105,19 @@
103106 return props
104107
105108 def split_keywords(self, keywords):
106 - keywords = keywords.split(',')
107109 d = {}
108 - for kw in keywords:
109 - key, value = kw.split('=')
110 - d[key] = value
 110+ if keywords != None:
 111+ keywords = keywords.split(',')
 112+ if [True for kw in keywords if kw.find('=') > -1] != []:
 113+ for kw in keywords:
 114+ key, value = kw.split('=')
 115+ try:
 116+ value = int(value)
 117+ except ValueError:
 118+ pass
 119+ d[key] = value
 120+ else:
 121+ return keywords
111122 return d
112123
113124 def get_project_location(self):
@@ -149,7 +160,7 @@
150161 '''
151162 lang = self.get_value('language')
152163 lnc = languages.LanguageContainer()
153 - default = lnc.determine_default_language()
 164+ default = lnc.languages[lnc.default]
154165 if lang != default.name:
155166 lang = lnc.get_language(lang)
156167 return lang
Index: trunk/tools/editor_trends/classes/languages.py
@@ -1,6 +1,16 @@
22 #!/usr/bin/python
33 # coding=utf-8
4 -
 4+'''
 5+Copyright (C) 2010 by Diederik van Liere (dvanliere@gmail.com)
 6+This program is free software; you can redistribute it and/or
 7+modify it under the terms of the GNU General Public License version 2
 8+as published by the Free Software Foundation.
 9+This program is distributed in the hope that it will be useful,
 10+but WITHOUT ANY WARRANTY; without even the implied warranty of
 11+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 12+See the GNU General Public License for more details, at
 13+http://www.fsf.org/licenses/gpl.html
 14+'''
515 __author__ = '''\n'''.join(['Diederik van Liere (dvanliere@gmail.com)', ])
616 __author__email = 'dvanliere at gmail dot com'
717 __date__ = '2011-01-26'
@@ -12,14 +22,28 @@
1323 from utils import ordered_dict as odict
1424
1525 class Language:
16 - def __init__(self, name, code, locale=None):
 26+ def __init__(self, name, code, default, locale=None):
1727 self.name = name
1828 self.locale = locale
1929 self.code = code
 30+ self.default = default
2031
2132 def __repr__(self):
2233 return '%s - %s' % (self.code, self.name)
2334
 35+ def show_languages(self, settings, project, startswith=None):
 36+ if startswith != None:
 37+ startswith = startswith.title()
 38+ project.valid_languages.sort()
 39+ for language in project.valid_languages:
 40+ try:
 41+ if startswith != None and language.startswith(first):
 42+ print '%s' % language.decode(settings.encoding)
 43+ elif startswith == None:
 44+ print '%s' % language.decode(settings.encoding)
 45+ except UnicodeEncodeError:
 46+ print '%s' % language
 47+
2448 class LanguageContainer:
2549 def __init__(self):
2650 self.init_languages = odict.OrderedDict([
@@ -605,18 +629,21 @@
606630 ])
607631
608632 self.languages = {}
 633+ self.default = self.determine_default_language()
609634 for language, code in self.init_languages.iteritems():
610 - ln = self.languages.get(code, Language(language, code))
 635+ ln = self.languages.get(code, Language(language, code, self.default))
611636 if language != ln.name:
612637 ln.locale = language
 638+ elif language == 'English':
 639+ ln.locale = 'English'
613640 self.languages[code] = ln
614 - self.default = self.determine_default_language()
615641
 642+
616643 def __repr__(self):
617644 return 'contains %s languages' % (len(self.languages))
618645
619646 def get_language(self, code):
620 - return self.languages.get(code, None)
 647+ return '%s' % self.languages.get(code, None)
621648
622649 def determine_default_language(self):
623650 '''
@@ -624,27 +651,8 @@
625652 Wikipedia project is most likely of interest
626653 '''
627654 code = locale.getdefaultlocale()[0]
628 - code = code.split('_')[0]
629 - return self.languages[code]
 655+ return code.split('_')[0]
630656
631 - def show_languages(settings, project, startswith=None):
632 - if startswith != None:
633 - startswith = startswith.title()
634 - choices = project.supported_languages()
635 - lang = []
636 - for choice in choices:
637 - lang.append(choice)
638 - lang.sort()
639 - for language in lang:
640 - try:
641 - if startswith != None and language.startswith(first):
642 - print '%s' % language.decode(settings.encoding)
643 - elif startswith == None:
644 - print '%s' % language.decode(settings.encoding)
645 - except UnicodeEncodeError:
646 - print '%s' % language
647 -
648 -
649657 def extract_language_code_from_wikiprojects(self):
650658 '''
651659 Copy and paste a string of all supported projects from
@@ -663,7 +671,7 @@
664672
665673 def init():
666674 lnc = LanguageContainer()
667 - return lnc.determine_default_language()
 675+ return lnc.languages[lnc.default]
668676
669677 if __name__ == '__main__':
670678 init()

Status & tagging log