Merge lp:~rachidbm/ubuntu-l10n-tools/search into lp:ubuntu-l10n-tools
- search
- Merge into trunk
Status: | Superseded |
---|---|
Proposed branch: | lp:~rachidbm/ubuntu-l10n-tools/search |
Merge into: | lp:ubuntu-l10n-tools |
Diff against target: |
466 lines (+133/-72) 11 files modified
README (+1/-1) bin/ul10n-lp-set-pot-priority (+3/-2) setup.py (+1/-1) ul10n_tools/lp_get_imports_info/__init__.py (+3/-4) ul10n_tools/lp_get_queue/__init__.py (+3/-4) ul10n_tools/lp_get_team_info/__init__.py (+1/-1) ul10n_tools/lp_get_templates/__init__.py (+8/-3) ul10n_tools/lp_l10n_upload/__init__.py (+4/-4) ul10n_tools/lp_set_pot_priority/__init__.py (+48/-8) ul10n_tools/search/TranslationsSearch.py (+24/-31) ul10n_tools/search/__init__.py (+37/-13) |
To merge this branch: | bzr merge lp:~rachidbm/ubuntu-l10n-tools/search |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
David Planella | Needs Fixing | ||
Review via email: mp+62857@code.launchpad.net |
This proposal has been superseded by a proposal from 2011-05-31.
Commit message
Description of the change
- Search tool: Added some error checking in (removed TODO's)
- Search tool: Implemented search on 'both' mode (translation and original)
- In general: Fixed launchpadmanager and added some DEBUG messages
David Planella (dpm) wrote : | # |
A couple of other things I've noticed (I'm still reviewing the 'search both' implementation):
* On ul10n_tools/
* On ul10n_tools/
What do you think?
Rachid (rachidbm) wrote : | # |
Hi David,
On Mon, May 30, 2011 at 6:08 PM, David Planella
<email address hidden>wrote:
> Review: Needs Fixing
> Hi Rachid,
>
> Thanks a lot for the branch!
>
> A couple of things I've noticed while reviewing it:
>
> * On setup.py you add "print >> sys.stderr, 'To build ul10n-tools you need
> https:/
> python-
> the best way to check it here, as the exception only checks for
> python-
> which is not a build dependency, but a runtime dependency. I think having
> the check on the file that imports polib should be enough
>
OK, so I should only remove python-polib? Or the whole apt-get line? (I
doubt because apt-get is Ubuntu/Debian specific)
>
> * In ul10n_tools/
> ('hardy', 'intrepid', 'jaunty', 'karmic', 'lucid', 'maverick', 'natty')",
> which is correct, but we should probably be more dynamic and use
> launchpadlib to get the releases. Nothing to change here, just a mental note
> to myself that we should check out the capabilites of the Launchpad API
> concerning templates nowadays, to see if we can get rid of the
> screen-scraping :)
>
I was thinking about handling the DISTRO_CODENAMES in a central place
anyway. Didn't thought about the Launchpad API, but I shall investigate that
later.
>
> * This is optional but you are using correct constructs such as "Source
> package: %s" % (options.
> package: {0}".format(
> http://
> of string formatting is the new standard in Python 3.0, and should be
> preferred to the % formatting [...]")
>
I'm not a seasoned Python programmer, thanks for this tip ;)
>
> * In the future, if you submit a branch for each feature (i.e. each change
> you make for a tool), it will make it much easier to review (no need to do
> it for this now, I'll just review the current branch).
>
OK
>
> * On ul10n_tools/
> ul10n_tools/
> commented out. If it's not used, could you please remove it?
>
Which lines exactly? Do you mean the "Currently dead code" remark?
>
> Do you think you could have a look at these points and re-submit the merge
> proposal before merging?
>
> Thanks!
> --
> https:/
> You are the owner of lp:~rachidbm/ubuntu-l10n-tools/search.
>
Rachid (rachidbm) wrote : | # |
On Mon, May 30, 2011 at 6:35 PM, David Planella
<email address hidden>wrote:
> A couple of other things I've noticed (I'm still reviewing the 'search
> both' implementation):
>
> * On ul10n_tools/
> don't reformat the code. In general, when submitting merge proposals the
> changes should concentrate on the feature, so that the diff contains as
> little noise as possible.
>
I understand that this is not desirable for the reviewer (and now bazaar
thinks I changed that code). I'll try to check the diff before committing.
Tips on this procedure are welcome.
> * On ul10n_tools/
> really like is that you've managed to unify the code to have the same search
> loop for plural and singular entries (the "for entry_to_search in
> entries_to_search:" part. I think it might be interesting to explore
> optimizing this further and rewrite the for loop in a generic way that would
> work for both plural and singular, and have it called just once after the if
> clause in which we detect if the entry is plural or singular.
>
Thanks and good point. I think it can be done relatively easy by changing
the __add_match()
Just give it the entire entry object to add_match and do the check for
plural there (if that's still needed though).
By looking to the code I think that just giving the entry to __add_match is
enough. But I'll find that out.
>
> What do you think?
> --
> https:/
> You are the owner of lp:~rachidbm/ubuntu-l10n-tools/search.
>
David Planella (dpm) wrote : | # |
El dl 30 de 05 de 2011 a les 20:19 +0000, en/na Rachid va escriure:
> Hi David,
>
> On Mon, May 30, 2011 at 6:08 PM, David Planella
> <email address hidden>wrote:
>
> > Review: Needs Fixing
> > Hi Rachid,
> >
> > Thanks a lot for the branch!
> >
> > A couple of things I've noticed while reviewing it:
> >
> > * On setup.py you add "print >> sys.stderr, 'To build ul10n-tools you need
> > https:/
> > python-
> > the best way to check it here, as the exception only checks for
> > python-
> > which is not a build dependency, but a runtime dependency. I think having
> > the check on the file that imports polib should be enough
> >
> OK, so I should only remove python-polib? Or the whole apt-get line? (I
> doubt because apt-get is Ubuntu/Debian specific)
>
I'd suggest removing the python-polib reference for now. I personally
wouldn't have put the apt-line there, since this makes the tool even
more Ubuntu-specific, but as we're just targetting Ubuntu for now, it
can stay if you want.
>
> >
> > * In ul10n_tools/
> > ('hardy', 'intrepid', 'jaunty', 'karmic', 'lucid', 'maverick', 'natty')",
> > which is correct, but we should probably be more dynamic and use
> > launchpadlib to get the releases. Nothing to change here, just a mental note
> > to myself that we should check out the capabilites of the Launchpad API
> > concerning templates nowadays, to see if we can get rid of the
> > screen-scraping :)
> >
> I was thinking about handling the DISTRO_CODENAMES in a central place
> anyway. Didn't thought about the Launchpad API, but I shall investigate that
> later.
>
Yeah, good idea, perhaps just as a get_ubuntu_
launchpadmanager.py that returns a list of active distro releases. IIRC
there is already some code in one of the tools that returns releases
from Launchpad (or at least the current release). Anyway, this was only
an idea, not directly related with this merge proposal.
>
> >
> > * This is optional but you are using correct constructs such as "Source
> > package: %s" % (options.
> > package: {0}".format(
> > http://
> > of string formatting is the new standard in Python 3.0, and should be
> > preferred to the % formatting [...]")
> >
> I'm not a seasoned Python programmer, thanks for this tip ;)
>
> >
> > * In the future, if you submit a branch for each feature (i.e. each change
> > you make for a tool), it will make it much easier to review (no need to do
> > it for this now, I'll just review the current branch).
> >
> OK
>
> >
> > * On ul10n_tools/
> > ul10n_tools/
> > commented out. If it's not used, could you please remove it?
> >
> Which lines exactly? Do you mean the "Currently dead code" remark?
>...
- 7. By David Planella
-
Modified lp_get_queue tool to return all queue entries now, in CSV format
- 8. By David Planella
-
Merged in changes from Rachid BM. Thanks!
- Search tool: Added some error checking in (removed TODO's)
- Search tool: Implemented search on 'both' mode (translation and original)
- Search tool: Generalized for loop such that it's the same for plural and singular
- In general: Fixed launchpadmanager and added some DEBUG messages - 9. By David Planella
-
Added some todos and minor cleanups for the priority setter tool
- 10. By David Planella
-
Merged rachidbm's changes for the search tool
- Added support for case-insensitive search
- Added comment in HELP text that regex can be used - 11. By David Planella
-
Merged in rachidbm's changes:
- get-team-info: minor refactoring
- 12. By David Planella
-
Minor fixes and comments in the priority setter tool
- 13. By David Planella
-
Priority setter: used the csv module to read the csv file
- 14. By David Planella
-
Merged changes from Rachid BM:
ul10n-lp-
set-priority tool
* Retrieve active series from Launchpad
* Added class to handle the stuff regarding POT and Launchpad
* Prioritise just one template or give an CSV file
* Edit 1 pot over several distro codenames
* Removed unnecessary has_header check in CSV reader
* Removed obsolete imports - 15. By Rachid
-
Added parameter (-p) to print only package names
Preview Diff
1 | === modified file 'README' |
2 | --- README 2011-05-26 11:08:04 +0000 |
3 | +++ README 2011-05-31 08:16:39 +0000 |
4 | @@ -14,7 +14,7 @@ |
5 | ul10n-lp-get-imports-info |
6 | ------------------------- |
7 | |
8 | -Returns internal Launchpad URLs for translation tarball imports. Useful when we need to check a translations import when there are problems. This way we ban just download it from the URL without the need of locally building a package. |
9 | +Returns internal Launchpad URLs for translation tarball imports. Useful when we need to check a translations import when there are problems. This way we can just download it from the URL without the need of locally building a package. |
10 | |
11 | * Status: not tested since it was moved to ul10n_tools, might need some tweaking. |
12 | |
13 | |
14 | === modified file 'bin/ul10n-lp-set-pot-priority' |
15 | --- bin/ul10n-lp-set-pot-priority 2011-05-30 08:41:38 +0000 |
16 | +++ bin/ul10n-lp-set-pot-priority 2011-05-31 08:16:39 +0000 |
17 | @@ -15,7 +15,8 @@ |
18 | and PROJECT_ROOT_DIRECTORY not in sys.path): |
19 | sys.path.insert(0, PROJECT_ROOT_DIRECTORY) |
20 | os.putenv('PYTHONPATH', PROJECT_ROOT_DIRECTORY) # for subprocesses |
21 | - |
22 | + |
23 | import ul10n_tools.lp_set_pot_priority as lp_set_pot_priority |
24 | |
25 | -lp_set_pot_priority.main() |
26 | +lp_set_pot_priority.main() |
27 | + |
28 | |
29 | === modified file 'setup.py' |
30 | --- setup.py 2011-04-09 08:51:51 +0000 |
31 | +++ setup.py 2011-05-31 08:16:39 +0000 |
32 | @@ -12,7 +12,7 @@ |
33 | try: |
34 | import DistUtilsExtra.auto |
35 | except ImportError: |
36 | - print >> sys.stderr, 'To build ul10n-tools you need https://launchpad.net/python-distutils-extra' |
37 | + print >> sys.stderr, 'To build ul10n-tools you need https://launchpad.net/python-distutils-extra : \nsudo apt-get install python-distutils-extra' |
38 | sys.exit(1) |
39 | assert DistUtilsExtra.auto.__version__ >= '2.18', 'needs DistUtilsExtra.auto >= 2.18' |
40 | |
41 | |
42 | === modified file 'ul10n_tools/__init__.py' (properties changed: -x to +x) |
43 | === modified file 'ul10n_tools/lp_get_imports_info/__init__.py' |
44 | --- ul10n_tools/lp_get_imports_info/__init__.py 2011-05-30 08:41:38 +0000 |
45 | +++ ul10n_tools/lp_get_imports_info/__init__.py 2011-05-31 08:16:39 +0000 |
46 | @@ -21,6 +21,7 @@ |
47 | import logging |
48 | import optparse |
49 | from ul10n_tools import ul10n_toolsconfig |
50 | +from ul10n_tools.utils.launchpadmanager import get_launchpad |
51 | |
52 | LEVELS = ( logging.ERROR, |
53 | logging.WARNING, |
54 | @@ -28,8 +29,6 @@ |
55 | logging.DEBUG, |
56 | ) |
57 | |
58 | -from ul10n_tools.utils.launchpadmanager import get_launchpad |
59 | - |
60 | DISTRO_CODENAMES = ('hardy', 'intrepid', 'jaunty', 'karmic', 'lucid', 'maverick') |
61 | |
62 | |
63 | @@ -61,9 +60,9 @@ |
64 | parser.print_help() |
65 | print "\nYou must specify a distro and a date." |
66 | else: |
67 | - lp = get_launchpad() |
68 | + launchpad = get_launchpad() |
69 | |
70 | - distrorelease = lp.distributions['ubuntu'].getSeries(name_or_version = distro_codename) |
71 | + distrorelease = launchpad.distributions['ubuntu'].getSeries(name_or_version = distro_codename) |
72 | |
73 | for p in distrorelease.getPackageUploads(created_since_date = upload_date, |
74 | custom_type = tarball_type): |
75 | |
76 | === modified file 'ul10n_tools/lp_get_queue/__init__.py' |
77 | --- ul10n_tools/lp_get_queue/__init__.py 2011-05-30 08:41:38 +0000 |
78 | +++ ul10n_tools/lp_get_queue/__init__.py 2011-05-31 08:16:39 +0000 |
79 | @@ -21,6 +21,7 @@ |
80 | import logging |
81 | import optparse |
82 | from ul10n_tools import ul10n_toolsconfig |
83 | +from ul10n_tools.utils.launchpadmanager import get_launchpad |
84 | |
85 | LEVELS = ( logging.ERROR, |
86 | logging.WARNING, |
87 | @@ -28,8 +29,6 @@ |
88 | logging.DEBUG, |
89 | ) |
90 | |
91 | -from ul10n_tools.utils.launchpadmanager import get_launchpad |
92 | - |
93 | DISTRO_CODENAMES = ('hardy', 'intrepid', 'jaunty', 'karmic', 'lucid', 'maverick') |
94 | |
95 | |
96 | @@ -49,13 +48,13 @@ |
97 | |
98 | distro_codename = options.distro_codename |
99 | |
100 | - lp = get_launchpad() |
101 | + launchpad = get_launchpad() |
102 | |
103 | if distro_codename is None: |
104 | ubuntu = launchpad.distributions["ubuntu"] |
105 | distrorelease = ubuntu.current_series |
106 | else: |
107 | - distrorelease = lp.distributions['ubuntu'].getSeries(name_or_version = distro_codename) |
108 | + distrorelease = launchpad.distributions['ubuntu'].getSeries(name_or_version = distro_codename) |
109 | |
110 | entries = distrorelease.getTranslationImportQueueEntries(file_extension = '.pot', |
111 | import_status='Needs Review')[1:10] |
112 | |
113 | === modified file 'ul10n_tools/lp_get_team_info/__init__.py' |
114 | --- ul10n_tools/lp_get_team_info/__init__.py 2011-05-20 11:55:08 +0000 |
115 | +++ ul10n_tools/lp_get_team_info/__init__.py 2011-05-31 08:16:39 +0000 |
116 | @@ -26,7 +26,7 @@ |
117 | import tempfile |
118 | import atexit |
119 | import shutil |
120 | -from ul10n_tools.launchpadmanager import get_launchpad |
121 | +from ul10n_tools.utils.launchpadmanager import get_launchpad |
122 | import csv |
123 | import urllib2 |
124 | import re |
125 | |
126 | === modified file 'ul10n_tools/lp_get_templates/__init__.py' |
127 | --- ul10n_tools/lp_get_templates/__init__.py 2011-05-20 11:55:08 +0000 |
128 | +++ ul10n_tools/lp_get_templates/__init__.py 2011-05-31 08:16:39 +0000 |
129 | @@ -35,7 +35,7 @@ |
130 | LP_TRANSLATIONS_PAGE = "https://translations.launchpad.net/%s/%s/+source/%s" |
131 | RE_TEMPLATE = '.*<a href="/%s/%s/\+source/%s/\+pots/[a-zA-Z0-9\-\.]*"' |
132 | DISTRO_ID = 'ubuntu' |
133 | -DISTRO_CODENAMES = ('hardy', 'intrepid', 'jaunty', 'karmic', 'lucid') |
134 | +DISTRO_CODENAMES = ('hardy', 'intrepid', 'jaunty', 'karmic', 'lucid', 'maverick', 'natty') |
135 | |
136 | class Ignore404ErrorHandler(urllib2.HTTPDefaultErrorHandler): |
137 | """ Error handler which does not raise a HTTPError if a page is not |
138 | @@ -59,7 +59,10 @@ |
139 | templates = list() |
140 | |
141 | opener = urllib2.build_opener(Ignore404ErrorHandler) |
142 | - page = opener.open(LP_TRANSLATIONS_PAGE % (distro_id, distro_codename, source_package)) |
143 | + URL_TEMPLATE = LP_TRANSLATIONS_PAGE % (distro_id, distro_codename, source_package) |
144 | + logging.debug("Open URL: {0}".format(URL_TEMPLATE)) |
145 | + |
146 | + page = opener.open(URL_TEMPLATE) |
147 | data = page.read() |
148 | |
149 | #templates = RE_TEMPLATE.findall(data) |
150 | @@ -76,7 +79,7 @@ |
151 | translation templates available in Launchpad""" |
152 | parser = optparse.OptionParser(usage = USAGE) |
153 | parser.add_option('-d', '--debug', dest='debug_mode', action='store_true', |
154 | - help='Print the maximum debugging info (implies -vv)') |
155 | + help='Print the maximum debugging info (implies -vvv)') |
156 | parser.add_option('-v', '--verbose', dest='logging_level', action='count', |
157 | help='Set error_level output to warning, info, and then debug') |
158 | parser.add_option("-c", "--distro-codename", dest="distro_codename", |
159 | @@ -92,9 +95,11 @@ |
160 | options.logging_level = 3 |
161 | logging.basicConfig(level=LEVELS[options.logging_level], format='%(asctime)s %(levelname)s %(message)s') |
162 | |
163 | + # TODO: change to args[0] instead of -s |
164 | if not options.source_package: |
165 | print "Must specify a source package" |
166 | else: |
167 | + logging.debug("Source package: {0}".format(options.source_package)) |
168 | templates = templates_get(DISTRO_ID, options.distro_codename, options.source_package) |
169 | if templates: |
170 | for template in templates: |
171 | |
172 | === modified file 'ul10n_tools/lp_l10n_upload/__init__.py' |
173 | --- ul10n_tools/lp_l10n_upload/__init__.py 2011-05-30 08:41:38 +0000 |
174 | +++ ul10n_tools/lp_l10n_upload/__init__.py 2011-05-31 08:16:39 +0000 |
175 | @@ -20,8 +20,8 @@ |
176 | import tempfile, atexit, shutil, os.path |
177 | import logging |
178 | import optparse |
179 | -from ul10n_tools import ul10n_toolsconfig |
180 | from ul10n_tools.utils import MultipartPostHandler |
181 | +from ul10n_tools.utils.launchpadmanager import get_launchpad |
182 | import urllib2 |
183 | import cookielib |
184 | import os |
185 | @@ -36,7 +36,7 @@ |
186 | logging.DEBUG, |
187 | ) |
188 | |
189 | -from ul10n_tools.launchpadmanager import get_launchpad |
190 | + |
191 | |
192 | |
193 | def opener_with_cookie(cookie_file): |
194 | @@ -131,7 +131,7 @@ |
195 | format='%(asctime)s %(levelname)s %(message)s') |
196 | |
197 | if not options.distro_codename: |
198 | - launchpad = getLaunchpad() |
199 | + launchpad = get_launchpad() |
200 | ubuntu = launchpad.distributions["ubuntu"] |
201 | options.distro_codename = ubuntu.current_series.name |
202 | logging.info("Ubuntu current series: {0}".format(options.distro_codename)) |
203 | @@ -182,7 +182,7 @@ |
204 | html_page = response.read() |
205 | |
206 | with open('lp-response.html', 'w') as html_file: |
207 | - html_file.write(html_page) |
208 | + html_file.write(html_page) |
209 | except IOError, e: |
210 | print 'The "%s" page could not be opened.' % form_url |
211 | if hasattr(e, 'code'): |
212 | |
213 | === modified file 'ul10n_tools/lp_set_pot_priority/__init__.py' (properties changed: -x to +x) |
214 | --- ul10n_tools/lp_set_pot_priority/__init__.py 2011-05-26 13:48:10 +0000 |
215 | +++ ul10n_tools/lp_set_pot_priority/__init__.py 2011-05-31 08:16:39 +0000 |
216 | @@ -15,16 +15,55 @@ |
217 | # the templates from within already exposed objects, instead of using |
218 | # "launchpad.load()" directly |
219 | |
220 | -# TODO: import the launchpadmanager module from ul10n_tools and use that |
221 | -from launchpadlib.launchpad import Launchpad |
222 | +import sys |
223 | +import logging |
224 | +import optparse |
225 | +from ul10n_tools.utils.launchpadmanager import get_launchpad |
226 | |
227 | +LEVELS = ( logging.ERROR, |
228 | + logging.WARNING, |
229 | + logging.INFO, |
230 | + logging.DEBUG, |
231 | + ) |
232 | + |
233 | def main(): |
234 | - # TODO: make the Launchpad server ('production', 'staging') a command line option, |
235 | - # (e.g. --use-production) making the default 'staging' |
236 | - launchpad = Launchpad.login_with('Template priority setter', 'staging') |
237 | - |
238 | - # TODO: make the file name the argument to the program invokation |
239 | - template_list = open('natty-templates.csv').readlines() |
240 | + # Support for command line options. |
241 | + USAGE = """%prog [OPTIONS] pattern |
242 | + |
243 | + Sets the priorities of translatable templates in Launchpad according to the |
244 | + given CSV file""" |
245 | + parser = optparse.OptionParser(usage = USAGE) |
246 | + parser.add_option('-d', '--debug', dest='debug_mode', action='store_true', |
247 | + help = 'Print the maximum debugging info (implies -vvv)') |
248 | + parser.add_option('-v', '--verbose', dest='logging_level', action='count', |
249 | + help = 'Set error_level output to warning, info, and then debug') |
250 | + parser.add_option('-p', '--use-production', dest='use_staging', action='store_false', |
251 | + help = 'Use the launchpad "production" server. Default is "staging"') |
252 | + |
253 | + parser.set_defaults(logging_level = 0, use_staging = True) |
254 | + (options, args) = parser.parse_args() |
255 | + |
256 | + # Set the verbosity |
257 | + if options.debug_mode: |
258 | + options.logging_level = 3 |
259 | + logging.basicConfig(level = LEVELS[options.logging_level], |
260 | + format = '%(asctime)s %(levelname)s %(message)s') |
261 | + |
262 | + # Error checking (the pattern must be specified) |
263 | + if len(args) < 1: |
264 | + print >> sys.stderr, 'ERROR: Not enough arguments, CSV file must be specified' |
265 | + sys.exit(1) |
266 | + else: |
267 | + logging.debug("Using CSV file: %s" % (args[0])) |
268 | + |
269 | + logging.debug("Use staging: %s" % (options.use_staging)) |
270 | + |
271 | + launchpad = get_launchpad(options.use_staging) |
272 | + |
273 | + #launchpad = Launchpad.login_with('Template priority setter', launchpad_server) |
274 | + launchpad = get_launchpad(options.use_staging) |
275 | + |
276 | + template_list = open(args[0]).readlines() |
277 | |
278 | for line in template_list[1:]: |
279 | # TODO: use the csv module for reading the file |
280 | @@ -36,3 +75,4 @@ |
281 | sp + '/+pots/' + template) |
282 | pot.priority = int(priority) |
283 | pot.lp_save() |
284 | + |
285 | |
286 | === modified file 'ul10n_tools/search/TranslationsSearch.py' |
287 | --- ul10n_tools/search/TranslationsSearch.py 2011-05-23 14:48:55 +0000 |
288 | +++ ul10n_tools/search/TranslationsSearch.py 2011-05-31 08:16:39 +0000 |
289 | @@ -22,7 +22,13 @@ |
290 | import os |
291 | import sys |
292 | import logging |
293 | -import polib |
294 | + |
295 | +try: |
296 | + import polib |
297 | +except ImportError: |
298 | + print >> sys.stderr, 'You need python-polib: \nsudo apt-get install python-polib' |
299 | + sys.exit(1) |
300 | + |
301 | |
302 | def build_localedir(langcode, get_localedir_ubuntu = True): |
303 | LOCALEDIR_ROOT = os.path.join(sys.prefix, 'share', 'locale') |
304 | @@ -61,48 +67,35 @@ |
305 | for entry in mo.translated_entries(): |
306 | if entry.msgid_plural: |
307 | if self.mode == 'translations': |
308 | - entry_to_search = entry.msgstr_plural |
309 | - indexes = entry.msgstr_plural.keys() |
310 | + entries_to_search = entry.msgstr_plural.values() |
311 | elif self.mode == 'original': |
312 | - entry_to_search = entry.msgid_plural |
313 | - indexes = (entry.msgid, entry.msgid_plural) |
314 | + entries_to_search = [entry.msgid, entry.msgid_plural] |
315 | + elif self.mode == 'both': |
316 | + entries_to_search = [entry.msgid, entry.msgid_plural] |
317 | + entries_to_search.extend(entry.msgstr_plural.values()) |
318 | else: |
319 | - # TODO: implement the 'both' mode |
320 | - print "Invalid mode specified:", options.mode |
321 | + print >> sys.stderr, "Invalid mode specified:", options.mode |
322 | sys.exit(1) |
323 | - |
324 | - for index in indexes: |
325 | - try: |
326 | - entry_to_search = entry_to_search[index] |
327 | - except TypeError: |
328 | - entry_to_search = index |
329 | - if self.pattern.search(entry_to_search): |
330 | - self.__add_match(mofile, |
331 | - msgid = entry.msgid, |
332 | - msgid_plural = entry.msgid_plural, |
333 | - msgstr_plural = entry.msgstr_plural, |
334 | - ) |
335 | - break |
336 | + |
337 | else: |
338 | if self.mode == 'translations': |
339 | - entry_to_search = entry.msgstr |
340 | + entries_to_search = [entry.msgstr] |
341 | elif self.mode == 'original': |
342 | - entry_to_search = entry.msgid |
343 | + entries_to_search = [entry.msgid] |
344 | + elif self.mode == 'both': |
345 | + entries_to_search = [entry.msgstr, entry.msgid] |
346 | else: |
347 | - # TODO: implement the 'both' mode |
348 | - print "Invalid mode specified:", options.mode |
349 | + print >> sys.stderr, "Invalid mode specified:", self.mode |
350 | sys.exit(1) |
351 | - |
352 | + |
353 | + for entry_to_search in entries_to_search: |
354 | if self.pattern.search(entry_to_search): |
355 | - self.__add_match(mofile, |
356 | - msgid = entry.msgid, |
357 | - msgstr = entry.msgstr) |
358 | + self.__add_match(mofile, entry) |
359 | + break |
360 | |
361 | - def __add_match(self, mofile, **kwargs): |
362 | + def __add_match(self, mofile, entry): |
363 | template_name = os.path.splitext(os.path.basename(mofile))[0] |
364 | |
365 | - entry = polib.POEntry(**kwargs) |
366 | - |
367 | if template_name in self.matches: |
368 | self.matches[template_name].append(entry) |
369 | else: |
370 | |
371 | === modified file 'ul10n_tools/search/__init__.py' |
372 | --- ul10n_tools/search/__init__.py 2011-05-23 14:48:55 +0000 |
373 | +++ ul10n_tools/search/__init__.py 2011-05-31 08:16:39 +0000 |
374 | @@ -22,6 +22,7 @@ |
375 | # You should have received a copy of the GNU General Public License along |
376 | # with this program. If not, see <http://www.gnu.org/licenses/>. |
377 | |
378 | +import sys |
379 | import logging |
380 | import optparse |
381 | import re |
382 | @@ -40,6 +41,8 @@ |
383 | logging.DEBUG, |
384 | ) |
385 | |
386 | +SEARCH_MODES = ('translations', 'original', 'both') |
387 | + |
388 | def main(): |
389 | # Support for command line options. |
390 | USAGE = """%prog [OPTIONS] pattern |
391 | @@ -48,7 +51,7 @@ |
392 | and returns any matches""" |
393 | parser = optparse.OptionParser(usage = USAGE) |
394 | parser.add_option('-d', '--debug', dest='debug_mode', action='store_true', |
395 | - help = 'Print the maximum debugging info (implies -vv)') |
396 | + help = 'Print the maximum debugging info (implies -vvv)') |
397 | parser.add_option('-v', '--verbose', dest='logging_level', action='count', |
398 | help = 'Set error_level output to warning, info, and then debug') |
399 | parser.add_option("-l", "--language", dest="language", |
400 | @@ -58,33 +61,54 @@ |
401 | help = ("Specify the mode: 'translations' looks for the pattern " + |
402 | "in the translations; 'original' looks for the pattern " + |
403 | "in the original English messages; 'both' looks in both. " + |
404 | - "('both' is not yet supported). " + |
405 | - "The default is 'translations'.")) |
406 | + "The default is 'both'.")) |
407 | + """ |
408 | + # TODO Not implemented (yet) |
409 | parser.add_option("-E", "--extended-regexp", dest="extended_regexp", |
410 | action='store_true', |
411 | help = "Specify that pattern is an extended regular expression") |
412 | - |
413 | + """ |
414 | setlocale(LC_ALL, '') |
415 | |
416 | parser.set_defaults(logging_level = 0, |
417 | - mode = 'translations', |
418 | + mode = 'both', |
419 | language = getlocale()[0]) |
420 | - (options, args) = parser.parse_args() |
421 | - |
422 | + (options, args) = parser.parse_args() |
423 | + |
424 | # Set the verbosity |
425 | if options.debug_mode: |
426 | options.logging_level = 3 |
427 | logging.basicConfig(level = LEVELS[options.logging_level], |
428 | format = '%(asctime)s %(levelname)s %(message)s') |
429 | |
430 | - # TODO error checking (the pattern must be specified) |
431 | + logging.debug("Search mode: {0}".format(options.mode)) |
432 | + logging.debug("Language: {0}".format(options.language)) |
433 | + |
434 | + # Error checking (the pattern must be specified) |
435 | + if len(args) < 1: |
436 | + print >> sys.stderr, 'ERROR: Not enough arguments, the search pattern must be specified' |
437 | + sys.exit(1) |
438 | + else: |
439 | + logging.debug("Search string: {0}".format(args[0])) |
440 | + |
441 | pattern = re.compile(args[0]) |
442 | - |
443 | - # TODO error checking (check the localedir exists) |
444 | + |
445 | localedir = build_localedir(options.language) |
446 | - |
447 | - # TODO error checking (check the mode has been specified) |
448 | - |
449 | + logging.debug("Using localedir: {0}".format(localedir)) |
450 | + |
451 | + # Error checking (check the localedir exists) |
452 | + if localedir == None: |
453 | + print >> sys.stderr, 'ERROR: Could not locate directory for specified locale:', options.language |
454 | + sys.exit(1) |
455 | + |
456 | + # Error checking (check the mode that has been specified) |
457 | + if not options.mode in SEARCH_MODES: |
458 | + print >> sys.stderr, 'ERROR: Invalid mode specified:', options.mode |
459 | + print >> sys.stderr, "Valid modes are:",', '.join(SEARCH_MODES) |
460 | + sys.exit(1) |
461 | + |
462 | translations_search = TranslationsSearch(pattern, localedir, options.mode) |
463 | translations_search.search() |
464 | translations_search.print_matches() |
465 | + |
466 | + print "{0} match(es) found.".format(len(translations_search.matches.items())) |
Hi Rachid,
Thanks a lot for the branch!
A couple of things I've noticed while reviewing it:
* On setup.py you add "print >> sys.stderr, 'To build ul10n-tools you need https:/ /launchpad. net/python- distutils- extra : \nsudo apt-get install python- distutils- extra python-polib'". While it is true, I don't think it's the best way to check it here, as the exception only checks for python- distutils- extra and shouldn't have anything to do with python-polib, which is not a build dependency, but a runtime dependency. I think having the check on the file that imports polib should be enough
* In ul10n_tools/ lp_get_ templates/ __init_ _.py you add "DISTRO_CODENAMES = ('hardy', 'intrepid', 'jaunty', 'karmic', 'lucid', 'maverick', 'natty')", which is correct, but we should probably be more dynamic and use launchpadlib to get the releases. Nothing to change here, just a mental note to myself that we should check out the capabilites of the Launchpad API concerning templates nowadays, to see if we can get rid of the screen-scraping :)
* This is optional but you are using correct constructs such as "Source package: %s" % (options. source_ package) , but I'd recommend using "Source package: {0}".format( options. source_ package) (See the str.format method on http:// docs.python. org/library/ stdtypes. html#string- methods: "This method of string formatting is the new standard in Python 3.0, and should be preferred to the % formatting [...]")
* In the future, if you submit a branch for each feature (i.e. each change you make for a tool), it will make it much easier to review (no need to do it for this now, I'll just review the current branch).
* On ul10n_tools/ lp_set_ pot_priority/ __init_ _.py and ul10n_tools/ search/ TranslationsSea rch.py you are adding some code that is commented out. If it's not used, could you please remove it?
Do you think you could have a look at these points and re-submit the merge proposal before merging?
Thanks!