7
7
>>> from zope.security.proxy import removeSecurityProxy
8
8
>>> from canonical.launchpad.interfaces.lpstorm import IStore
9
>>> from lp.registry.interfaces.distroseries import IDistroSeries
10
>>> from lp.translations.interfaces.translationimportqueue import (
11
... ITranslationImportQueue)
9
12
>>> from lp.translations.model.translationimportqueue import (
10
13
... TranslationImportQueueEntry)
15
>>> translationimportqueue = getUtility(ITranslationImportQueue)
12
17
>>> def clear_queue(queue):
13
18
... """Remove all entries off the import queue."""
14
19
... store = IStore(TranslationImportQueueEntry)
15
20
... store.find(TranslationImportQueueEntry).remove()
22
>>> def get_target_names(status=None):
23
... """Call getRequestTargets, return list of names/titles."""
25
... queue = translationimportqueue.getRequestTargets(status)
26
... for object in queue:
27
... if IDistroSeries.providedBy(object):
28
... name = "%s/%s" % (object.distribution.name, object.name)
30
... name = object.name
31
... result.append("%s %s" % (name, object.displayname))
34
>>> def print_list(strings):
35
... """Print list of strings as list of lines."""
36
... for string in strings:
29
51
>>> from canonical.database.sqlbase import flush_database_updates
30
52
>>> from lp.app.interfaces.launchpad import ILaunchpadCelebrities
31
53
>>> from lp.registry.interfaces.distribution import IDistributionSet
32
>>> from lp.registry.interfaces.distroseries import IDistroSeries
33
54
>>> from lp.registry.interfaces.product import IProductSet
34
55
>>> from lp.registry.interfaces.sourcepackagename import (
35
56
... ISourcePackageNameSet)
36
57
>>> from lp.translations.enums import RosettaImportStatus
37
>>> from lp.translations.interfaces.translationimportqueue import (
38
... ITranslationImportQueue)
39
58
>>> from lp.registry.model.distroseries import DistroSeries
40
59
>>> from lp.registry.model.productseries import ProductSeries
41
60
>>> from lp.registry.model.sourcepackagename import SourcePackageName
42
61
>>> from canonical.launchpad.ftests import login
44
>>> translationimportqueue = getUtility(ITranslationImportQueue)
45
63
>>> rosetta_experts = getUtility(ILaunchpadCelebrities).rosetta_experts
47
65
>>> distroset = getUtility(IDistributionSet)
937
>>> # Helper functions
938
>>> def get_target_names(status=None):
939
... """Call getRequestTargets, return list of names/titles.
942
... queue = translationimportqueue.getRequestTargets(status)
943
... for object in queue:
944
... if IDistroSeries.providedBy(object):
945
... name = "%s/%s" % (object.distribution.name, object.name)
947
... name = object.name
948
... result.append("%s %s" % (name, object.displayname))
951
>>> def print_list(strings):
952
... """Print list of strings as list of lines."""
953
... for string in strings:
956
getRequestTargets() returns all objects that have entries in the
957
translation import queue waiting to be imported. Object can be a
958
Product or a DistroSeries.
960
The user uploads two translations into Hoary and Warty respectively, as
961
well as one for the Firefox trunk series.
963
>>> from lp.registry.interfaces.distribution import (
964
... IDistributionSet)
965
>>> ubuntu = getUtility(IDistributionSet).getByName('ubuntu')
966
>>> hoary_distroseries = ubuntu.getSeries('hoary')
967
>>> evolution_sourcepackagename = (
968
... SourcePackageName.selectOne("name='evolution'"))
969
>>> entry1 = translationimportqueue.addOrUpdateEntry(
970
... u'po/sr.po', 'foo', True, rosetta_experts,
971
... distroseries=hoary_distroseries,
972
... sourcepackagename=evolution_sourcepackagename)
974
>>> warty_distroseries = ubuntu.getSeries('warty')
975
>>> entry3 = translationimportqueue.addOrUpdateEntry(
976
... u'po/sr.po', 'foo', True, rosetta_experts,
977
... distroseries=warty_distroseries,
978
... sourcepackagename=evolution_sourcepackagename)
979
>>> print entry3.status.name
982
>>> firefox = productset['firefox']
983
>>> productseries = firefox.getSeries('trunk')
984
>>> entry2 = translationimportqueue.addOrUpdateEntry(
985
... 'foo/bar.pot', 'foo content', True,
986
... rosetta_experts, productseries=productseries)
987
>>> flush_database_updates()
989
The list of objects with approved entries is still empty, since we haven't
992
>>> print_list(sorted(get_target_names(RosettaImportStatus.APPROVED)))
994
>>> print entry3.status.name
997
Now we approve these entries (we need to be Rosetta administrator to do this).
998
We also need to set an import target.
1000
>>> login('carlos@canonical.com')
1001
>>> entry1.potemplate = factory.makePOTemplate(
1002
... name=u"evolution",
1003
... distroseries=hoary_distroseries,
1004
... sourcepackagename=evolution_sourcepackagename)
1005
>>> entry1.pofile = factory.makePOFile('sr', potemplate=entry1.potemplate)
1006
>>> entry1.setStatus(RosettaImportStatus.APPROVED, rosetta_experts)
1007
>>> entry2.potemplate = factory.makePOTemplate(
1008
... name=u"firefox",
1009
... productseries=productseries)
1010
>>> entry2.setStatus(RosettaImportStatus.APPROVED, rosetta_experts)
1012
>>> flush_database_updates()
1013
>>> translationimportqueue = getUtility(ITranslationImportQueue)
1015
If we re-get the list of objects which have approved entries, we'll
1016
get these recently approved ones.
1018
>>> print_list(sorted(get_target_names(RosettaImportStatus.APPROVED)))
1019
firefox Mozilla Firefox
1022
Lets check that the returned entries are actually the same ones we submitted.
1023
Each of the objects returned provides a getFirstEntryToImport method
1024
which returns the TranslationImportQueueEntry which is next up for import.
1026
>>> importqueues = translationimportqueue.getRequestTargets(
1027
... RosettaImportStatus.APPROVED)
1028
>>> sortedqueues = sorted(importqueues,
1029
... cmp=lambda x,y: cmp(y.title, x.title))
1030
>>> queue1 = sortedqueues[0]
1032
u'The Hoary Hedgehog Release'
1033
>>> entry = queue1.getFirstEntryToImport()
1037
>>> queue2 = sortedqueues[1]
1040
>>> entry = queue2.getFirstEntryToImport()
1044
Note that our third entry never received approval, so it is still awaiting
1047
>>> print entry3.status.name
1050
>>> print_list(sorted(get_target_names()))
1052
firefox Mozilla Firefox
1056
Administrators temporarily block translation imports to Warty.
1058
>>> warty_distroseries.defer_translation_imports = True
1060
While imports are blocked, Warty does not show up as having pending
1063
>>> print_list(sorted(get_target_names()))
1065
firefox Mozilla Firefox
1068
An administrator deactivates Firefox, thinking that the project is being
1069
run in violation of Launchpad policies.
1071
# Unlink the source packages so the project can be deactivated.
1072
>>> from lp.testing import unlink_source_packages
1073
>>> unlink_source_packages(firefox)
1074
>>> firefox.active = False
1076
Now that Firefox is inactive, it no longer shows up as having pending
1079
>>> print_list(sorted(get_target_names()))
1083
The administrator realizes that there has been a mistake, and makes
1084
Firefox active again.
1086
>>> firefox.active = True
1088
The import request for Firefox was not removed, so Firefox is listed as
1089
having pending imports again.
1091
>>> print_list(sorted(get_target_names()))
1093
firefox Mozilla Firefox
1096
952
addOrUpdateEntry()
1097
953
------------------
1436
1289
>>> clear_queue(translationimportqueue)
1439
getRequestTargets output ordering
1440
---------------------------------
1442
The queue is populated with a wild mix of requests: for packages in
1443
different release series of Ubuntu, for packages in different distros,
1444
for product series, with different statuses; some were imported from
1445
upstream, some were produced right here in Launchpad.
1447
>>> def create_distro_request(distro_name, series_name):
1448
... """Enqueue an import request for given distro package."""
1449
... distro = distroset[distro_name]
1450
... series = distro.getSeries(series_name)
1451
... package = packageset['pmount']
1452
... template = factory.makePOTemplate(distroseries=series,
1453
... sourcepackagename=package)
1454
... # In a completely arbitrary move, we make all import requests for
1455
... # distro series imported.
1456
... return translationimportqueue.addOrUpdateEntry('messages.pot',
1457
... 'dummy file', True, rosetta_experts, distroseries=series,
1458
... sourcepackagename=package, potemplate=template)
1460
>>> def create_product_request(product_name, template_name):
1461
... """Enqueue an import request for given product and template."""
1462
... product = productset[product_name]
1463
... series = product.primary_translatable
1464
... assert series is not None, (
1465
... "Product %s has no translatable series." % product_name)
1466
... template = series.getPOTemplate(template_name)
1467
... # In another completely arbitrary move, we make all import
1468
... # requests for products non-imported.
1469
... return translationimportqueue.addOrUpdateEntry('messages.pot',
1470
... 'dummy file', False, rosetta_experts, productseries=series,
1471
... potemplate=template)
1473
>>> # Populate import queue with wild mix of requests.
1474
>>> entry = create_product_request('evolution', 'evolution-2.2')
1475
>>> entry.setStatus(RosettaImportStatus.APPROVED, rosetta_experts)
1476
>>> entry = create_distro_request('debian', 'sarge')
1477
>>> entry.setStatus(RosettaImportStatus.NEEDS_REVIEW, rosetta_experts)
1478
>>> entry = create_product_request('alsa-utils', 'alsa-utils')
1479
>>> entry.setStatus(RosettaImportStatus.FAILED, rosetta_experts)
1480
>>> entry = create_distro_request('ubuntu', 'grumpy')
1481
>>> entry.setStatus(RosettaImportStatus.BLOCKED, rosetta_experts)
1482
>>> entry = create_distro_request('kubuntu', 'krunch')
1483
>>> entry.setStatus(RosettaImportStatus.APPROVED, rosetta_experts)
1484
>>> entry = create_product_request('evolution', 'evolution-2.2-test')
1485
>>> entry.setStatus(RosettaImportStatus.IMPORTED, rosetta_experts)
1486
>>> entry = create_distro_request('debian', 'woody')
1487
>>> entry.setStatus(RosettaImportStatus.NEEDS_REVIEW, rosetta_experts)
1488
>>> flush_database_updates()
1490
TranslationImportQueue.getRequestTargets first lists distro series
1491
(ordered by distro name and series name), followed by products (ordered
1494
>>> print_list(get_target_names())
1497
kubuntu/krunch Krunch
1498
ubuntu/grumpy Grumpy
1499
alsa-utils alsa-utils
1502
>>> for status in RosettaImportStatus.items:
1503
... print "%s:" % status.name
1504
... print_list(get_target_names(status))
1506
kubuntu/krunch Krunch
1512
alsa-utils alsa-utils
1517
ubuntu/grumpy Grumpy
1520
You can also select by status.
1522
>>> print_list(get_target_names(RosettaImportStatus.APPROVED))
1523
kubuntu/krunch Krunch
1581
1346
>>> from lp.app.enums import ServiceUsage
1348
>>> def create_product_request(product_name, template_name):
1349
... """Enqueue an import request for given product and template."""
1350
... product = productset[product_name]
1351
... series = product.primary_translatable
1352
... assert series is not None, (
1353
... "Product %s has no translatable series." % product_name)
1354
... template = series.getPOTemplate(template_name)
1355
... # In another completely arbitrary move, we make all import
1356
... # requests for products non-imported.
1357
... return translationimportqueue.addOrUpdateEntry('messages.pot',
1358
... 'dummy file', False, rosetta_experts, productseries=series,
1359
... potemplate=template)
1583
1361
>>> jokosher = productset['jokosher']
1584
1362
>>> jokosher_trunk = jokosher.getSeries('trunk')
1585
1363
>>> jokosher.translations_usage = ServiceUsage.LAUNCHPAD