846
848
return elapsedtime_text
851
def list_product_request_targets(status_condition):
852
"""Return list of Products with import queue entries.
854
:param status_condition: Storm conditional restricting the
855
queue-entry status to look for.
856
:return: A list of `Product`, distinct and ordered by name.
858
# Avoid circular imports.
859
from lp.registry.model.product import Product
860
from lp.registry.model.productseries import ProductSeries
862
products = IStore(Product).find(
864
Product.id == ProductSeries.productID,
865
Product.active == True,
866
ProductSeries.id.is_in(Select(
867
TranslationImportQueueEntry.productseries_id,
869
TranslationImportQueueEntry.productseries_id != None,
873
# Products may occur multiple times due to the join with
875
products = products.config(distinct=True)
877
# Sort python-side; doing it in SQL conflicts with the
879
return sorted(products, key=attrgetter('name'))
882
def list_distroseries_request_targets(status_condition):
883
"""Return list of DistroSeries with import queue entries.
885
:param status_condition: Storm conditional restricting the
886
queue-entry status to look for.
887
:return: A list of `DistroSeries`, distinct and ordered by
888
(`Distribution.name`, `DistroSeries.name`).
890
# Avoid circular imports.
891
from lp.registry.model.distribution import Distribution
892
from lp.registry.model.distroseries import DistroSeries
894
# DistroSeries with queue entries.
895
distroseries = IStore(DistroSeries).find(
897
DistroSeries.defer_translation_imports == False,
898
Distribution.id == DistroSeries.distributionID,
899
DistroSeries.id.is_in(Select(
900
TranslationImportQueueEntry.distroseries_id,
902
TranslationImportQueueEntry.distroseries_id != None,
905
distroseries = distroseries.order_by(Distribution.name, DistroSeries.name)
906
return list(distroseries)
849
909
class TranslationImportQueue:
850
910
implements(ITranslationImportQueue)
1224
1284
def getRequestTargets(self, status=None):
1225
1285
"""See `ITranslationImportQueue`."""
1226
# XXX DaniloSegan 2007-05-22: When imported on the module level,
1227
# it errs out with: "ImportError: cannot import name Person"
1228
from lp.registry.model.distroseries import DistroSeries
1229
from lp.registry.model.product import Product
1231
1287
if status is None:
1232
status_clause = "TRUE"
1288
status_clause = True
1235
"TranslationImportQueueEntry.status = %s" % sqlvalues(status))
1237
def distroseries_sort_key(distroseries):
1238
return (distroseries.distribution.name, distroseries.name)
1241
'ProductSeries.product = Product.id',
1242
'TranslationImportQueueEntry.productseries = ProductSeries.id',
1243
'Product.active IS TRUE']
1244
if status is not None:
1245
query.append(status_clause)
1247
products = list(Product.select(
1248
' AND '.join(query),
1249
clauseTables=['ProductSeries', 'TranslationImportQueueEntry'],
1250
distinct=True, orderBy='Product.name'))
1252
distroseriess = shortlist(DistroSeries.select("""
1253
defer_translation_imports IS FALSE AND
1255
SELECT DISTINCT distroseries
1256
FROM TranslationImportQueueEntry
1259
""" % status_clause))
1260
distroseriess.sort(key=distroseries_sort_key)
1262
return distroseriess + products
1290
status_clause = (TranslationImportQueueEntry.status == status)
1292
distroseries = list_distroseries_request_targets(status_clause)
1293
products = list_product_request_targets(status_clause)
1295
return distroseries + products
1264
1297
def _attemptToSet(self, entry, potemplate=None, pofile=None):
1265
1298
"""Set potemplate or pofile on a `TranslationImportQueueEntry`.