summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan Maat <tm@tlater.net>2018-03-24 17:56:56 +0000
committerTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2018-06-07 16:35:51 -0400
commit60a29f687c520fd7b17f4b98ab0a033c41e31fc5 (patch)
tree4760db953ed2b175d8aa9f097115c44c10d2d811
parent4632cb039d543d78a9a8956c605fa3ed40f3f035 (diff)
downloadbuildstream-60a29f687c520fd7b17f4b98ab0a033c41e31fc5.tar.gz
_ostree.py: Introduce _list_all_refs() and list_artifacts()
The unused list_remote_refs() function has also been removed as part of this commit.
-rw-r--r--buildstream/_ostree.py44
1 files changed, 44 insertions, 0 deletions
diff --git a/buildstream/_ostree.py b/buildstream/_ostree.py
index 246b54f51..e40df5fb5 100644
--- a/buildstream/_ostree.py
+++ b/buildstream/_ostree.py
@@ -552,3 +552,47 @@ def configure_remote(repo, remote, url, key_url=None):
repo.remote_gpg_import(remote, stream, None, 0, None)
except GLib.GError as e:
raise OSTreeError("Failed to add gpg key from url '{}': {}".format(key_url, e.message)) from e
+
+
+# list_artifacts():
+#
+# List cached artifacts in Least Recently Modified (LRM) order.
+#
+# Returns:
+# (list) - A list of refs in LRM order
+#
+def list_artifacts(repo):
+ # string of: /path/to/repo/refs/heads
+ ref_heads = os.path.join(repo.get_path().get_path(), 'refs', 'heads')
+
+ # obtain list of <project>/<element>/<key>
+ refs = _list_all_refs(repo).keys()
+
+ mtimes = []
+ for ref in refs:
+ ref_path = os.path.join(ref_heads, ref)
+ if os.path.exists(ref_path):
+ # Obtain the mtime (the time a file was last modified)
+ mtimes.append(os.path.getmtime(ref_path))
+
+ # NOTE: Sorted will sort from earliest to latest, thus the
+ # first element of this list will be the file modified earliest.
+ return [ref for _, ref in sorted(zip(mtimes, refs))]
+
+
+# _list_all_refs():
+#
+# Create a list of all refs.
+#
+# Args:
+# repo (OSTree.Repo): The repo
+#
+# Returns:
+# (dict): A dict of refs to checksums.
+#
+def _list_all_refs(repo):
+ try:
+ _, refs = repo.list_refs(None)
+ return refs
+ except GLib.GError as e:
+ raise OSTreeError(message=e.message) from e