File 0001-SCRD-2694-Synchronize-the-index-with-current-venvs.patch of Package python-ardana-packager
From 250c910a8660b247ac33ea1ffdab0d3f181e52de Mon Sep 17 00:00:00 2001
From: Alberto Planas <aplanas@gmail.com>
Date: Mon, 19 Feb 2018 16:42:17 +0100
Subject: [PATCH] SCRD-2694 Synchronize the index with current venvs
With the SUSEification effort we deploy the venvs inside an RPM
package, so when a new version of the venv is installed the old
one get removed from the `ardana_packager` directory.
As of today there is not co-installation for multiple versions
of the same venv service.
This patch makes sure that when an old venv tarball is removed,
it is also removed from the venv index.
Change-Id: I4e5cd757657124b2ffb8a809d299183442ddc5ab
---
.../packager/ardana_packager/indexer.py | 23 ++++++++++++++++++----
1 file changed, 19 insertions(+), 4 deletions(-)
diff --git a/ansible/library_python/packager/ardana_packager/indexer.py b/ansible/library_python/packager/ardana_packager/indexer.py
index 81b91e5..a08271e 100644
--- a/ansible/library_python/packager/ardana_packager/indexer.py
+++ b/ansible/library_python/packager/ardana_packager/indexer.py
@@ -1,6 +1,6 @@
#
# (c) Copyright 2015-2016 Hewlett Packard Enterprise Development LP
-# (c) Copyright 2017 SUSE LLC
+# (c) Copyright 2017-2018 SUSE LLC
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
@@ -60,7 +60,7 @@ def create_index(dir):
Write it out, but also return it, in case it's useful.
"""
- packages = collections.defaultdict(dict)
+ packages = {}
existing_index_files = []
try:
@@ -74,8 +74,23 @@ def create_index(dir):
for package_version in package.itervalues():
existing_index_files.append(package_version["file"])
- files = [os.path.join(dir, file) for file in os.listdir(dir)
- if file not in existing_index_files]
+ files = os.listdir(dir)
+ # Remove from `packages` the venvs for each service that is not
+ # there anymore
+ files_to_remove = set(existing_index_files) - set(files)
+ _packages = collections.defaultdict(dict)
+ _packages.update({
+ k: { _k: _v for _k, _v in v.iteritems()
+ if _v['file'] not in files_to_remove }
+ for k, v in packages.iteritems()
+ })
+ packages = _packages
+
+ # New files that potentially can be new venvs that we need to add
+ # to the index file
+ files_to_add = set(files) - set(existing_index_files)
+ files = [os.path.join(dir, file) for file in files_to_add]
+
pool = multiprocessing.Pool(multiprocessing.cpu_count() * 4)
file_to_version = pool.map(get_version, files)
--
2.16.2