Merge lp:~rachidbm/ubuntu-l10n-tools/search into lp:ubuntu-l10n-tools

Proposed by Rachid
Status: Merged
Merged at revision: 8
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
Reviewer Review Type Date Requested Status
David Planella Approve
Review via email: mp+62951@code.launchpad.net

This proposal supersedes a proposal from 2011-05-30.

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

Re-submit:
 - Fixes based on Davids feedback in the review
 - Removed unnecessary comments
 - Searchtool: Generalized for loop such that it's the same for plural and singular

To post a comment you must log in.
Revision history for this message
David Planella (dpm) wrote : Posted in a previous version of this proposal

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/TranslationsSearch.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!

review: Needs Fixing
Revision history for this message
David Planella (dpm) wrote : Posted in a previous version of this proposal

A couple of other things I've noticed (I'm still reviewing the 'search both' implementation):

* On ul10n_tools/search/TranslationsSearch.py, line 336 of the diff, please 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.

* On ul10n_tools/search/TranslationsSearch.py, line 333, one thing that I 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.

What do you think?

Revision history for this message
Rachid (rachidbm) wrote : Posted in a previous version of this proposal

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://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
>
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/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 :)
>
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.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 [...]")
>
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/lp_set_pot_priority/__init__.py and
> ul10n_tools/search/TranslationsSearch.py you are adding some code that is
> 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://code.launchpad.net/~rachidbm/ubuntu-l10n-tools/search/+merge/62857
> You are the owner of lp:~rachidbm/ubuntu-l10n-tools/search.
>

Revision history for this message
Rachid (rachidbm) wrote : Posted in a previous version of this proposal

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/search/TranslationsSearch.py, line 336 of the diff, please
> 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/search/TranslationsSearch.py, line 333, one thing that I
> 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://code.launchpad.net/~rachidbm/ubuntu-l10n-tools/search/+merge/62857
> You are the owner of lp:~rachidbm/ubuntu-l10n-tools/search.
>

Revision history for this message
David Planella (dpm) wrote : Posted in a previous version of this proposal
Download full text (4.4 KiB)

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://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
> >
> 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/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 :)
> >
> 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_releases() function in
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.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 [...]")
> >
> 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/lp_set_pot_priority/__init__.py and
> > ul10n_tools/search/TranslationsSearch.py you are adding some code that is
> > commented out. If it's not used, could you please remove it?
> >
> Which lines exactly? Do you mean the "Currently dead code" remark?
>...

Read more...

Revision history for this message
David Planella (dpm) wrote :

Excellent, looks good to me, thanks!

I'll merge your branch, then.

review: Approve
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

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'README'
--- README 2011-05-26 11:08:04 +0000
+++ README 2011-05-31 08:19:24 +0000
@@ -14,7 +14,7 @@
14ul10n-lp-get-imports-info14ul10n-lp-get-imports-info
15-------------------------15-------------------------
1616
17Returns 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.17Returns 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.
1818
19* Status: not tested since it was moved to ul10n_tools, might need some tweaking.19* Status: not tested since it was moved to ul10n_tools, might need some tweaking.
2020
2121
=== modified file 'bin/ul10n-lp-set-pot-priority'
--- bin/ul10n-lp-set-pot-priority 2011-05-30 08:41:38 +0000
+++ bin/ul10n-lp-set-pot-priority 2011-05-31 08:19:24 +0000
@@ -15,7 +15,8 @@
15 and PROJECT_ROOT_DIRECTORY not in sys.path):15 and PROJECT_ROOT_DIRECTORY not in sys.path):
16 sys.path.insert(0, PROJECT_ROOT_DIRECTORY)16 sys.path.insert(0, PROJECT_ROOT_DIRECTORY)
17 os.putenv('PYTHONPATH', PROJECT_ROOT_DIRECTORY) # for subprocesses17 os.putenv('PYTHONPATH', PROJECT_ROOT_DIRECTORY) # for subprocesses
1818
19import ul10n_tools.lp_set_pot_priority as lp_set_pot_priority19import ul10n_tools.lp_set_pot_priority as lp_set_pot_priority
2020
21lp_set_pot_priority.main()21lp_set_pot_priority.main()
22
2223
=== modified file 'setup.py'
--- setup.py 2011-04-09 08:51:51 +0000
+++ setup.py 2011-05-31 08:19:24 +0000
@@ -12,7 +12,7 @@
12try:12try:
13 import DistUtilsExtra.auto13 import DistUtilsExtra.auto
14except ImportError:14except ImportError:
15 print >> sys.stderr, 'To build ul10n-tools you need https://launchpad.net/python-distutils-extra'15 print >> sys.stderr, 'To build ul10n-tools you need https://launchpad.net/python-distutils-extra : \nsudo apt-get install python-distutils-extra'
16 sys.exit(1)16 sys.exit(1)
17assert DistUtilsExtra.auto.__version__ >= '2.18', 'needs DistUtilsExtra.auto >= 2.18'17assert DistUtilsExtra.auto.__version__ >= '2.18', 'needs DistUtilsExtra.auto >= 2.18'
1818
1919
=== modified file 'ul10n_tools/__init__.py' (properties changed: -x to +x)
=== modified file 'ul10n_tools/lp_get_imports_info/__init__.py'
--- ul10n_tools/lp_get_imports_info/__init__.py 2011-05-30 08:41:38 +0000
+++ ul10n_tools/lp_get_imports_info/__init__.py 2011-05-31 08:19:24 +0000
@@ -21,6 +21,7 @@
21import logging21import logging
22import optparse22import optparse
23from ul10n_tools import ul10n_toolsconfig23from ul10n_tools import ul10n_toolsconfig
24from ul10n_tools.utils.launchpadmanager import get_launchpad
2425
25LEVELS = ( logging.ERROR,26LEVELS = ( logging.ERROR,
26 logging.WARNING,27 logging.WARNING,
@@ -28,8 +29,6 @@
28 logging.DEBUG,29 logging.DEBUG,
29 )30 )
3031
31from ul10n_tools.utils.launchpadmanager import get_launchpad
32
33DISTRO_CODENAMES = ('hardy', 'intrepid', 'jaunty', 'karmic', 'lucid', 'maverick')32DISTRO_CODENAMES = ('hardy', 'intrepid', 'jaunty', 'karmic', 'lucid', 'maverick')
3433
3534
@@ -61,9 +60,9 @@
61 parser.print_help()60 parser.print_help()
62 print "\nYou must specify a distro and a date."61 print "\nYou must specify a distro and a date."
63 else:62 else:
64 lp = get_launchpad()63 launchpad = get_launchpad()
6564
66 distrorelease = lp.distributions['ubuntu'].getSeries(name_or_version = distro_codename)65 distrorelease = launchpad.distributions['ubuntu'].getSeries(name_or_version = distro_codename)
6766
68 for p in distrorelease.getPackageUploads(created_since_date = upload_date,67 for p in distrorelease.getPackageUploads(created_since_date = upload_date,
69 custom_type = tarball_type):68 custom_type = tarball_type):
7069
=== modified file 'ul10n_tools/lp_get_queue/__init__.py'
--- ul10n_tools/lp_get_queue/__init__.py 2011-05-30 08:41:38 +0000
+++ ul10n_tools/lp_get_queue/__init__.py 2011-05-31 08:19:24 +0000
@@ -21,6 +21,7 @@
21import logging21import logging
22import optparse22import optparse
23from ul10n_tools import ul10n_toolsconfig23from ul10n_tools import ul10n_toolsconfig
24from ul10n_tools.utils.launchpadmanager import get_launchpad
2425
25LEVELS = ( logging.ERROR,26LEVELS = ( logging.ERROR,
26 logging.WARNING,27 logging.WARNING,
@@ -28,8 +29,6 @@
28 logging.DEBUG,29 logging.DEBUG,
29 )30 )
3031
31from ul10n_tools.utils.launchpadmanager import get_launchpad
32
33DISTRO_CODENAMES = ('hardy', 'intrepid', 'jaunty', 'karmic', 'lucid', 'maverick')32DISTRO_CODENAMES = ('hardy', 'intrepid', 'jaunty', 'karmic', 'lucid', 'maverick')
3433
3534
@@ -49,13 +48,13 @@
4948
50 distro_codename = options.distro_codename49 distro_codename = options.distro_codename
5150
52 lp = get_launchpad()51 launchpad = get_launchpad()
5352
54 if distro_codename is None:53 if distro_codename is None:
55 ubuntu = launchpad.distributions["ubuntu"]54 ubuntu = launchpad.distributions["ubuntu"]
56 distrorelease = ubuntu.current_series55 distrorelease = ubuntu.current_series
57 else:56 else:
58 distrorelease = lp.distributions['ubuntu'].getSeries(name_or_version = distro_codename)57 distrorelease = launchpad.distributions['ubuntu'].getSeries(name_or_version = distro_codename)
5958
60 entries = distrorelease.getTranslationImportQueueEntries(file_extension = '.pot',59 entries = distrorelease.getTranslationImportQueueEntries(file_extension = '.pot',
61 import_status='Needs Review')[1:10]60 import_status='Needs Review')[1:10]
6261
=== modified file 'ul10n_tools/lp_get_team_info/__init__.py'
--- ul10n_tools/lp_get_team_info/__init__.py 2011-05-20 11:55:08 +0000
+++ ul10n_tools/lp_get_team_info/__init__.py 2011-05-31 08:19:24 +0000
@@ -26,7 +26,7 @@
26import tempfile26import tempfile
27import atexit27import atexit
28import shutil28import shutil
29from ul10n_tools.launchpadmanager import get_launchpad29from ul10n_tools.utils.launchpadmanager import get_launchpad
30import csv30import csv
31import urllib231import urllib2
32import re32import re
3333
=== modified file 'ul10n_tools/lp_get_templates/__init__.py'
--- ul10n_tools/lp_get_templates/__init__.py 2011-05-20 11:55:08 +0000
+++ ul10n_tools/lp_get_templates/__init__.py 2011-05-31 08:19:24 +0000
@@ -35,7 +35,7 @@
35LP_TRANSLATIONS_PAGE = "https://translations.launchpad.net/%s/%s/+source/%s"35LP_TRANSLATIONS_PAGE = "https://translations.launchpad.net/%s/%s/+source/%s"
36RE_TEMPLATE = '.*<a href="/%s/%s/\+source/%s/\+pots/[a-zA-Z0-9\-\.]*"'36RE_TEMPLATE = '.*<a href="/%s/%s/\+source/%s/\+pots/[a-zA-Z0-9\-\.]*"'
37DISTRO_ID = 'ubuntu'37DISTRO_ID = 'ubuntu'
38DISTRO_CODENAMES = ('hardy', 'intrepid', 'jaunty', 'karmic', 'lucid')38DISTRO_CODENAMES = ('hardy', 'intrepid', 'jaunty', 'karmic', 'lucid', 'maverick', 'natty')
3939
40class Ignore404ErrorHandler(urllib2.HTTPDefaultErrorHandler):40class Ignore404ErrorHandler(urllib2.HTTPDefaultErrorHandler):
41 """ Error handler which does not raise a HTTPError if a page is not41 """ Error handler which does not raise a HTTPError if a page is not
@@ -59,7 +59,10 @@
59 templates = list()59 templates = list()
6060
61 opener = urllib2.build_opener(Ignore404ErrorHandler)61 opener = urllib2.build_opener(Ignore404ErrorHandler)
62 page = opener.open(LP_TRANSLATIONS_PAGE % (distro_id, distro_codename, source_package))62 URL_TEMPLATE = LP_TRANSLATIONS_PAGE % (distro_id, distro_codename, source_package)
63 logging.debug("Open URL: {0}".format(URL_TEMPLATE))
64
65 page = opener.open(URL_TEMPLATE)
63 data = page.read()66 data = page.read()
6467
65 #templates = RE_TEMPLATE.findall(data)68 #templates = RE_TEMPLATE.findall(data)
@@ -76,7 +79,7 @@
76 translation templates available in Launchpad"""79 translation templates available in Launchpad"""
77 parser = optparse.OptionParser(usage = USAGE)80 parser = optparse.OptionParser(usage = USAGE)
78 parser.add_option('-d', '--debug', dest='debug_mode', action='store_true',81 parser.add_option('-d', '--debug', dest='debug_mode', action='store_true',
79 help='Print the maximum debugging info (implies -vv)')82 help='Print the maximum debugging info (implies -vvv)')
80 parser.add_option('-v', '--verbose', dest='logging_level', action='count',83 parser.add_option('-v', '--verbose', dest='logging_level', action='count',
81 help='Set error_level output to warning, info, and then debug')84 help='Set error_level output to warning, info, and then debug')
82 parser.add_option("-c", "--distro-codename", dest="distro_codename",85 parser.add_option("-c", "--distro-codename", dest="distro_codename",
@@ -92,9 +95,11 @@
92 options.logging_level = 395 options.logging_level = 3
93 logging.basicConfig(level=LEVELS[options.logging_level], format='%(asctime)s %(levelname)s %(message)s')96 logging.basicConfig(level=LEVELS[options.logging_level], format='%(asctime)s %(levelname)s %(message)s')
9497
98 # TODO: change to args[0] instead of -s
95 if not options.source_package:99 if not options.source_package:
96 print "Must specify a source package"100 print "Must specify a source package"
97 else:101 else:
102 logging.debug("Source package: {0}".format(options.source_package))
98 templates = templates_get(DISTRO_ID, options.distro_codename, options.source_package)103 templates = templates_get(DISTRO_ID, options.distro_codename, options.source_package)
99 if templates:104 if templates:
100 for template in templates:105 for template in templates:
101106
=== modified file 'ul10n_tools/lp_l10n_upload/__init__.py'
--- ul10n_tools/lp_l10n_upload/__init__.py 2011-05-30 08:41:38 +0000
+++ ul10n_tools/lp_l10n_upload/__init__.py 2011-05-31 08:19:24 +0000
@@ -20,8 +20,8 @@
20import tempfile, atexit, shutil, os.path20import tempfile, atexit, shutil, os.path
21import logging21import logging
22import optparse22import optparse
23from ul10n_tools import ul10n_toolsconfig
24from ul10n_tools.utils import MultipartPostHandler23from ul10n_tools.utils import MultipartPostHandler
24from ul10n_tools.utils.launchpadmanager import get_launchpad
25import urllib225import urllib2
26import cookielib26import cookielib
27import os27import os
@@ -36,7 +36,7 @@
36 logging.DEBUG,36 logging.DEBUG,
37 )37 )
3838
39from ul10n_tools.launchpadmanager import get_launchpad39
4040
4141
42def opener_with_cookie(cookie_file):42def opener_with_cookie(cookie_file):
@@ -131,7 +131,7 @@
131 format='%(asctime)s %(levelname)s %(message)s')131 format='%(asctime)s %(levelname)s %(message)s')
132132
133 if not options.distro_codename:133 if not options.distro_codename:
134 launchpad = getLaunchpad()134 launchpad = get_launchpad()
135 ubuntu = launchpad.distributions["ubuntu"]135 ubuntu = launchpad.distributions["ubuntu"]
136 options.distro_codename = ubuntu.current_series.name136 options.distro_codename = ubuntu.current_series.name
137 logging.info("Ubuntu current series: {0}".format(options.distro_codename))137 logging.info("Ubuntu current series: {0}".format(options.distro_codename))
@@ -182,7 +182,7 @@
182 html_page = response.read()182 html_page = response.read()
183183
184 with open('lp-response.html', 'w') as html_file:184 with open('lp-response.html', 'w') as html_file:
185 html_file.write(html_page)185 html_file.write(html_page)
186 except IOError, e:186 except IOError, e:
187 print 'The "%s" page could not be opened.' % form_url187 print 'The "%s" page could not be opened.' % form_url
188 if hasattr(e, 'code'):188 if hasattr(e, 'code'):
189189
=== modified file 'ul10n_tools/lp_set_pot_priority/__init__.py' (properties changed: -x to +x)
--- ul10n_tools/lp_set_pot_priority/__init__.py 2011-05-26 13:48:10 +0000
+++ ul10n_tools/lp_set_pot_priority/__init__.py 2011-05-31 08:19:24 +0000
@@ -15,16 +15,55 @@
15# the templates from within already exposed objects, instead of using 15# the templates from within already exposed objects, instead of using
16# "launchpad.load()" directly16# "launchpad.load()" directly
1717
18# TODO: import the launchpadmanager module from ul10n_tools and use that18import sys
19from launchpadlib.launchpad import Launchpad19import logging
20import optparse
21from ul10n_tools.utils.launchpadmanager import get_launchpad
2022
23LEVELS = ( logging.ERROR,
24 logging.WARNING,
25 logging.INFO,
26 logging.DEBUG,
27 )
28
21def main():29def main():
22 # TODO: make the Launchpad server ('production', 'staging') a command line option,30 # Support for command line options.
23 # (e.g. --use-production) making the default 'staging'31 USAGE = """%prog [OPTIONS] pattern
24 launchpad = Launchpad.login_with('Template priority setter', 'staging')32
2533 Sets the priorities of translatable templates in Launchpad according to the
26 # TODO: make the file name the argument to the program invokation34 given CSV file"""
27 template_list = open('natty-templates.csv').readlines()35 parser = optparse.OptionParser(usage = USAGE)
36 parser.add_option('-d', '--debug', dest='debug_mode', action='store_true',
37 help = 'Print the maximum debugging info (implies -vvv)')
38 parser.add_option('-v', '--verbose', dest='logging_level', action='count',
39 help = 'Set error_level output to warning, info, and then debug')
40 parser.add_option('-p', '--use-production', dest='use_staging', action='store_false',
41 help = 'Use the launchpad "production" server. Default is "staging"')
42
43 parser.set_defaults(logging_level = 0, use_staging = True)
44 (options, args) = parser.parse_args()
45
46 # Set the verbosity
47 if options.debug_mode:
48 options.logging_level = 3
49 logging.basicConfig(level = LEVELS[options.logging_level],
50 format = '%(asctime)s %(levelname)s %(message)s')
51
52 # Error checking (the pattern must be specified)
53 if len(args) < 1:
54 print >> sys.stderr, 'ERROR: Not enough arguments, CSV file must be specified'
55 sys.exit(1)
56 else:
57 logging.debug("Using CSV file: %s" % (args[0]))
58
59 logging.debug("Use staging: %s" % (options.use_staging))
60
61 launchpad = get_launchpad(options.use_staging)
62
63 #launchpad = Launchpad.login_with('Template priority setter', launchpad_server)
64 launchpad = get_launchpad(options.use_staging)
65
66 template_list = open(args[0]).readlines()
2867
29 for line in template_list[1:]:68 for line in template_list[1:]:
30 # TODO: use the csv module for reading the file69 # TODO: use the csv module for reading the file
@@ -36,3 +75,4 @@
36 sp + '/+pots/' + template)75 sp + '/+pots/' + template)
37 pot.priority = int(priority)76 pot.priority = int(priority)
38 pot.lp_save()77 pot.lp_save()
78
3979
=== modified file 'ul10n_tools/search/TranslationsSearch.py'
--- ul10n_tools/search/TranslationsSearch.py 2011-05-23 14:48:55 +0000
+++ ul10n_tools/search/TranslationsSearch.py 2011-05-31 08:19:24 +0000
@@ -22,7 +22,13 @@
22import os22import os
23import sys23import sys
24import logging24import logging
25import polib25
26try:
27 import polib
28except ImportError:
29 print >> sys.stderr, 'You need python-polib: \nsudo apt-get install python-polib'
30 sys.exit(1)
31
2632
27def build_localedir(langcode, get_localedir_ubuntu = True):33def build_localedir(langcode, get_localedir_ubuntu = True):
28 LOCALEDIR_ROOT = os.path.join(sys.prefix, 'share', 'locale')34 LOCALEDIR_ROOT = os.path.join(sys.prefix, 'share', 'locale')
@@ -61,48 +67,35 @@
61 for entry in mo.translated_entries():67 for entry in mo.translated_entries():
62 if entry.msgid_plural:68 if entry.msgid_plural:
63 if self.mode == 'translations':69 if self.mode == 'translations':
64 entry_to_search = entry.msgstr_plural70 entries_to_search = entry.msgstr_plural.values()
65 indexes = entry.msgstr_plural.keys()
66 elif self.mode == 'original':71 elif self.mode == 'original':
67 entry_to_search = entry.msgid_plural72 entries_to_search = [entry.msgid, entry.msgid_plural]
68 indexes = (entry.msgid, entry.msgid_plural)73 elif self.mode == 'both':
74 entries_to_search = [entry.msgid, entry.msgid_plural]
75 entries_to_search.extend(entry.msgstr_plural.values())
69 else:76 else:
70 # TODO: implement the 'both' mode77 print >> sys.stderr, "Invalid mode specified:", options.mode
71 print "Invalid mode specified:", options.mode
72 sys.exit(1)78 sys.exit(1)
7379
74 for index in indexes:
75 try:
76 entry_to_search = entry_to_search[index]
77 except TypeError:
78 entry_to_search = index
79 if self.pattern.search(entry_to_search):
80 self.__add_match(mofile,
81 msgid = entry.msgid,
82 msgid_plural = entry.msgid_plural,
83 msgstr_plural = entry.msgstr_plural,
84 )
85 break
86 else:80 else:
87 if self.mode == 'translations':81 if self.mode == 'translations':
88 entry_to_search = entry.msgstr82 entries_to_search = [entry.msgstr]
89 elif self.mode == 'original':83 elif self.mode == 'original':
90 entry_to_search = entry.msgid84 entries_to_search = [entry.msgid]
85 elif self.mode == 'both':
86 entries_to_search = [entry.msgstr, entry.msgid]
91 else:87 else:
92 # TODO: implement the 'both' mode88 print >> sys.stderr, "Invalid mode specified:", self.mode
93 print "Invalid mode specified:", options.mode
94 sys.exit(1)89 sys.exit(1)
9590
91 for entry_to_search in entries_to_search:
96 if self.pattern.search(entry_to_search):92 if self.pattern.search(entry_to_search):
97 self.__add_match(mofile,93 self.__add_match(mofile, entry)
98 msgid = entry.msgid,94 break
99 msgstr = entry.msgstr)
10095
101 def __add_match(self, mofile, **kwargs):96 def __add_match(self, mofile, entry):
102 template_name = os.path.splitext(os.path.basename(mofile))[0]97 template_name = os.path.splitext(os.path.basename(mofile))[0]
10398
104 entry = polib.POEntry(**kwargs)
105
106 if template_name in self.matches:99 if template_name in self.matches:
107 self.matches[template_name].append(entry)100 self.matches[template_name].append(entry)
108 else:101 else:
109102
=== modified file 'ul10n_tools/search/__init__.py'
--- ul10n_tools/search/__init__.py 2011-05-23 14:48:55 +0000
+++ ul10n_tools/search/__init__.py 2011-05-31 08:19:24 +0000
@@ -22,6 +22,7 @@
22# You should have received a copy of the GNU General Public License along22# You should have received a copy of the GNU General Public License along
23# with this program. If not, see <http://www.gnu.org/licenses/>.23# with this program. If not, see <http://www.gnu.org/licenses/>.
2424
25import sys
25import logging26import logging
26import optparse27import optparse
27import re28import re
@@ -40,6 +41,8 @@
40 logging.DEBUG,41 logging.DEBUG,
41 )42 )
4243
44SEARCH_MODES = ('translations', 'original', 'both')
45
43def main():46def main():
44 # Support for command line options.47 # Support for command line options.
45 USAGE = """%prog [OPTIONS] pattern48 USAGE = """%prog [OPTIONS] pattern
@@ -48,7 +51,7 @@
48 and returns any matches"""51 and returns any matches"""
49 parser = optparse.OptionParser(usage = USAGE)52 parser = optparse.OptionParser(usage = USAGE)
50 parser.add_option('-d', '--debug', dest='debug_mode', action='store_true',53 parser.add_option('-d', '--debug', dest='debug_mode', action='store_true',
51 help = 'Print the maximum debugging info (implies -vv)')54 help = 'Print the maximum debugging info (implies -vvv)')
52 parser.add_option('-v', '--verbose', dest='logging_level', action='count',55 parser.add_option('-v', '--verbose', dest='logging_level', action='count',
53 help = 'Set error_level output to warning, info, and then debug')56 help = 'Set error_level output to warning, info, and then debug')
54 parser.add_option("-l", "--language", dest="language",57 parser.add_option("-l", "--language", dest="language",
@@ -58,33 +61,54 @@
58 help = ("Specify the mode: 'translations' looks for the pattern " +61 help = ("Specify the mode: 'translations' looks for the pattern " +
59 "in the translations; 'original' looks for the pattern " +62 "in the translations; 'original' looks for the pattern " +
60 "in the original English messages; 'both' looks in both. " +63 "in the original English messages; 'both' looks in both. " +
61 "('both' is not yet supported). " +64 "The default is 'both'."))
62 "The default is 'translations'."))65 """
66 # TODO Not implemented (yet)
63 parser.add_option("-E", "--extended-regexp", dest="extended_regexp",67 parser.add_option("-E", "--extended-regexp", dest="extended_regexp",
64 action='store_true',68 action='store_true',
65 help = "Specify that pattern is an extended regular expression")69 help = "Specify that pattern is an extended regular expression")
6670 """
67 setlocale(LC_ALL, '')71 setlocale(LC_ALL, '')
6872
69 parser.set_defaults(logging_level = 0,73 parser.set_defaults(logging_level = 0,
70 mode = 'translations',74 mode = 'both',
71 language = getlocale()[0])75 language = getlocale()[0])
72 (options, args) = parser.parse_args()76 (options, args) = parser.parse_args()
7377
74 # Set the verbosity78 # Set the verbosity
75 if options.debug_mode:79 if options.debug_mode:
76 options.logging_level = 380 options.logging_level = 3
77 logging.basicConfig(level = LEVELS[options.logging_level],81 logging.basicConfig(level = LEVELS[options.logging_level],
78 format = '%(asctime)s %(levelname)s %(message)s')82 format = '%(asctime)s %(levelname)s %(message)s')
7983
80 # TODO error checking (the pattern must be specified)84 logging.debug("Search mode: {0}".format(options.mode))
85 logging.debug("Language: {0}".format(options.language))
86
87 # Error checking (the pattern must be specified)
88 if len(args) < 1:
89 print >> sys.stderr, 'ERROR: Not enough arguments, the search pattern must be specified'
90 sys.exit(1)
91 else:
92 logging.debug("Search string: {0}".format(args[0]))
93
81 pattern = re.compile(args[0])94 pattern = re.compile(args[0])
8295
83 # TODO error checking (check the localedir exists)
84 localedir = build_localedir(options.language)96 localedir = build_localedir(options.language)
8597 logging.debug("Using localedir: {0}".format(localedir))
86 # TODO error checking (check the mode has been specified)98
8799 # Error checking (check the localedir exists)
100 if localedir == None:
101 print >> sys.stderr, 'ERROR: Could not locate directory for specified locale:', options.language
102 sys.exit(1)
103
104 # Error checking (check the mode that has been specified)
105 if not options.mode in SEARCH_MODES:
106 print >> sys.stderr, 'ERROR: Invalid mode specified:', options.mode
107 print >> sys.stderr, "Valid modes are:",', '.join(SEARCH_MODES)
108 sys.exit(1)
109
88 translations_search = TranslationsSearch(pattern, localedir, options.mode)110 translations_search = TranslationsSearch(pattern, localedir, options.mode)
89 translations_search.search()111 translations_search.search()
90 translations_search.print_matches()112 translations_search.print_matches()
113
114 print "{0} match(es) found.".format(len(translations_search.matches.items()))

Subscribers

People subscribed via source and target branches