Commit bcf4e44f authored by Lorenz Huedepohl's avatar Lorenz Huedepohl
Browse files

Speed-up mpcdf_setup_repositories by making multiple connections to the server

parent 6b0433be
......@@ -111,6 +111,14 @@ class UnsetAttributeException(Exception):
pass
def chunked(l, chunksize):
n = len(l)
i = 0
while i * chunksize < n:
yield l[i * chunksize: (i + 1) * chunksize]
i += 1
def get_attribute(api_url, project, package, attribute, with_project=False):
attribute_meta = osc.core.show_attribute_meta(api_url, project, package, None, attribute, False, with_project)
if attribute_meta is None:
......@@ -325,6 +333,8 @@ def mpcdf_enable_repositories(api_url, project, package, verbose=False, filter_r
def mpcdf_setup_repositories(api_url, project, distribution=None, parent=None, packages=None, dry_run=False, filter_repos=None, only_project=False, remove_old=False):
import threading
if parent:
for attribute in config_attributes + default_attributes:
print("Copying attribute '{0}' from parent project".format(attribute))
......@@ -485,10 +495,26 @@ def mpcdf_setup_repositories(api_url, project, distribution=None, parent=None, p
# spurious builds are launched
if packages is None:
packages = osc.core.meta_get_packagelist(api_url, project)
for package in packages:
print("Updating repositories for", package)
if not mpcdf_enable_repositories(api_url, project, package, filter_repos=filter_repos):
print("ATTENTION: Not changing unmanaged package {0}".format(package))
if len(packages) > 40:
chunksize = len(packages) // 20
else:
chunksize = len(packages)
def work(packagelist):
for package in packagelist:
print("Updating repositories for", package)
if not mpcdf_enable_repositories(api_url, project, package, filter_repos=filter_repos):
print("ATTENTION: Not changing unmanaged package {0}".format(package))
threads = []
for packagelist in chunked(packages, chunksize):
t = threading.Thread(target=work, args=(packagelist,))
threads.append(t)
t.start()
for t in threads:
t.join()
# Update repositories
print("Updating prj meta")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment