Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2148)

Unified Diff: appengine/chrome_infra_packages/cipd/impl.py

Issue 1194803002: Add a package listing API to cipd. (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: appengine/chrome_infra_packages/cipd/impl.py
diff --git a/appengine/chrome_infra_packages/cipd/impl.py b/appengine/chrome_infra_packages/cipd/impl.py
index 451a0377cef1445f1698575efb196aa621fb0940..bbd6458fd504b054bfcf1b887501b53a7b83fa4b 100644
--- a/appengine/chrome_infra_packages/cipd/impl.py
+++ b/appengine/chrome_infra_packages/cipd/impl.py
@@ -165,6 +165,31 @@ class RepoService(object):
"""
return package_key(package_name).get()
+ def list_packages(self, prefix):
+ """Returns list of Packages with the given prefix.
+
+ Args:
+ prefix: string prefix of the packages to list.
+
+ Returns:
+ [Package, ...].
+ """
+ query = Package.query().order(Package.key)
+
+ # Only apply the filtering if a prefix was given. The empty string isn't a
+ # valid key and will result in an exception.
+ if prefix:
+ query = query.filter(
+ # Prefix match using the operators available to us. Packages can only
+ # contain lowercase ascii, numbers, and '/' so '\uffff' will always
+ # be larger.
+ ndb.AND(Package.key >= ndb.Key(Package, prefix),
Vadim Sh. 2015/06/19 21:12:03 this thing may require additional composite index
estaab 2015/06/20 02:25:25 Sounds good.
+ Package.key <= ndb.Key(Package, prefix + u'\uffff')))
+ pkgs = []
+ for pkg in query:
Vadim Sh. 2015/06/19 21:12:03 use keys_only=True query and extract package_name
estaab 2015/06/20 02:25:25 Done.
+ pkgs.append(pkg.package_name)
+ return pkgs
Vadim Sh. 2015/06/19 21:12:03 return sorted(pkgs)
estaab 2015/06/20 02:25:25 Done
+
def get_processing_result(self, package_name, instance_id, processor_name):
"""Returns results of some asynchronous processor or None if not ready.

Powered by Google App Engine
This is Rietveld 408576698