Index: trunk/tools/editor_trends/classes/runtime_settings.py |
— | — | @@ -52,12 +52,14 @@ |
53 | 53 | if args: |
54 | 54 | self.args = args |
55 | 55 | 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') |
58 | 60 | self.update_project_settings() |
59 | 61 | self.update_language_settings() |
60 | 62 | |
61 | | - self.targets = self.get_value('charts') |
| 63 | + self.targets = self.split_keywords(self.get_value('charts')) |
62 | 64 | self.keywords = self.split_keywords(self.get_value('keywords')) |
63 | 65 | self.function = self.get_value('func') |
64 | 66 | self.collection = self.get_value('collection') |
— | — | @@ -65,6 +67,8 @@ |
66 | 68 | self.clean = self.get_value('new') |
67 | 69 | self.force = self.get_value('force') |
68 | 70 | self.location = self.get_project_location() |
| 71 | + print self.location |
| 72 | + print self.settings.working_directory |
69 | 73 | self.filename = self.generate_wikidump_filename() |
70 | 74 | self.namespaces = self.get_namespaces() |
71 | 75 | |
— | — | @@ -82,7 +86,6 @@ |
83 | 87 | self.dataset, |
84 | 88 | self.charts] |
85 | 89 | self.path = '/%s/latest/' % self.project |
86 | | - self.targets = self.targets.split(', ') |
87 | 90 | settings.verify_environment(self.directories) |
88 | 91 | |
89 | 92 | def __str__(self): |
— | — | @@ -102,11 +105,19 @@ |
103 | 106 | return props |
104 | 107 | |
105 | 108 | def split_keywords(self, keywords): |
106 | | - keywords = keywords.split(',') |
107 | 109 | 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 |
111 | 122 | return d |
112 | 123 | |
113 | 124 | def get_project_location(self): |
— | — | @@ -149,7 +160,7 @@ |
150 | 161 | ''' |
151 | 162 | lang = self.get_value('language') |
152 | 163 | lnc = languages.LanguageContainer() |
153 | | - default = lnc.determine_default_language() |
| 164 | + default = lnc.languages[lnc.default] |
154 | 165 | if lang != default.name: |
155 | 166 | lang = lnc.get_language(lang) |
156 | 167 | return lang |
Index: trunk/tools/editor_trends/classes/languages.py |
— | — | @@ -1,6 +1,16 @@ |
2 | 2 | #!/usr/bin/python |
3 | 3 | # 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 | +''' |
5 | 15 | __author__ = '''\n'''.join(['Diederik van Liere (dvanliere@gmail.com)', ]) |
6 | 16 | __author__email = 'dvanliere at gmail dot com' |
7 | 17 | __date__ = '2011-01-26' |
— | — | @@ -12,14 +22,28 @@ |
13 | 23 | from utils import ordered_dict as odict |
14 | 24 | |
15 | 25 | class Language: |
16 | | - def __init__(self, name, code, locale=None): |
| 26 | + def __init__(self, name, code, default, locale=None): |
17 | 27 | self.name = name |
18 | 28 | self.locale = locale |
19 | 29 | self.code = code |
| 30 | + self.default = default |
20 | 31 | |
21 | 32 | def __repr__(self): |
22 | 33 | return '%s - %s' % (self.code, self.name) |
23 | 34 | |
| 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 | + |
24 | 48 | class LanguageContainer: |
25 | 49 | def __init__(self): |
26 | 50 | self.init_languages = odict.OrderedDict([ |
— | — | @@ -605,18 +629,21 @@ |
606 | 630 | ]) |
607 | 631 | |
608 | 632 | self.languages = {} |
| 633 | + self.default = self.determine_default_language() |
609 | 634 | 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)) |
611 | 636 | if language != ln.name: |
612 | 637 | ln.locale = language |
| 638 | + elif language == 'English': |
| 639 | + ln.locale = 'English' |
613 | 640 | self.languages[code] = ln |
614 | | - self.default = self.determine_default_language() |
615 | 641 | |
| 642 | + |
616 | 643 | def __repr__(self): |
617 | 644 | return 'contains %s languages' % (len(self.languages)) |
618 | 645 | |
619 | 646 | def get_language(self, code): |
620 | | - return self.languages.get(code, None) |
| 647 | + return '%s' % self.languages.get(code, None) |
621 | 648 | |
622 | 649 | def determine_default_language(self): |
623 | 650 | ''' |
— | — | @@ -624,27 +651,8 @@ |
625 | 652 | Wikipedia project is most likely of interest |
626 | 653 | ''' |
627 | 654 | code = locale.getdefaultlocale()[0] |
628 | | - code = code.split('_')[0] |
629 | | - return self.languages[code] |
| 655 | + return code.split('_')[0] |
630 | 656 | |
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 | | - |
649 | 657 | def extract_language_code_from_wikiprojects(self): |
650 | 658 | ''' |
651 | 659 | Copy and paste a string of all supported projects from |
— | — | @@ -663,7 +671,7 @@ |
664 | 672 | |
665 | 673 | def init(): |
666 | 674 | lnc = LanguageContainer() |
667 | | - return lnc.determine_default_language() |
| 675 | + return lnc.languages[lnc.default] |
668 | 676 | |
669 | 677 | if __name__ == '__main__': |
670 | 678 | init() |