Commit 6046be38 authored by Lorenz Huedepohl's avatar Lorenz Huedepohl
Browse files

Push just one package

parent c3a4d47d
Pipeline #67075 failed with stage
in 11 seconds
......@@ -5,6 +5,7 @@ __all__ = ["valid_mpi", "valid_cuda", "project_meta", "get_attribute", "get_attr
import osc
import osc.conf
import osc.core
import osc.oscerr
from functools import partial
from xml.etree import ElementTree
......@@ -43,7 +44,7 @@ def project_meta(api_url, project):
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:
raise oscerr.APIError("Cannot fetch value for attribute '{0}' from {1}".format(attribute, (project, package)))
raise osc.oscerr.APIError("Cannot fetch value for attribute '{0}' from {1}".format(attribute, (project, package)))
root = ElementTree.fromstringlist(attribute_meta)
attribute = root.find("./attribute")
......@@ -52,6 +53,7 @@ def get_attribute(api_url, project, package, attribute, with_project=False):
else:
raise Exception("Attribute not set")
def get_attribute_values(api_url, project, package, attribute, with_project=False):
root = get_attribute(api_url, project, package, attribute, with_project)
attribute = root.find("./attribute")
......@@ -59,12 +61,12 @@ def get_attribute_values(api_url, project, package, attribute, with_project=Fals
def set_attribute(api_url, path, attribute):
attr_meta = ET.tostring(attribute, encoding=osc.core.ET_ENCODING)
attr_meta = ElementTree.tostring(attribute, encoding=osc.core.ET_ENCODING)
url = osc.core.makeurl(api_url, ["source"] + list(path) + ["_attribute"])
resp = ElementTree.fromstringlist(osc.core.streamfile(url, http_POST, data=attr_meta))
resp = ElementTree.fromstringlist(osc.core.streamfile(url, osc.core.http_POST, data=attr_meta))
if resp.find("./summary").text != "Ok":
raise osc.core.oscerr.APIError("Could not store attribute")
raise osc.oscerr.APIError("Could not store attribute")
def mpcdf_enable_repositories(api_url, project, package, verbose=False):
......@@ -91,7 +93,7 @@ def mpcdf_enable_repositories(api_url, project, package, verbose=False):
try:
enable_repos = get_attribute_values(api_url, project, package, "MPCDF:enable_repositories")
except:
except Exception:
if verbose:
print("Warning: Could not get attribute MPCDF:enable_repositories for package {0}".format(package))
return False
......@@ -109,7 +111,7 @@ def mpcdf_enable_repositories(api_url, project, package, verbose=False):
for compiler in compilers:
for mpi in mpis:
if valid_mpi(compiler, mpi):
enable(mpi + "_" + compiler)
enable(mpi + "_" + compiler)
if flag == "cuda":
for cuda in cudas:
......@@ -128,13 +130,22 @@ def mpcdf_enable_repositories(api_url, project, package, verbose=False):
if len(build.getchildren()) > 0:
build.getchildren()[-1].tail = "\n "
pkg_meta = ET.tostring(root, encoding=osc.core.ET_ENCODING)
pkg_meta = ElementTree.tostring(root, encoding=osc.core.ET_ENCODING)
osc.core.edit_meta("pkg", (project, package), data=pkg_meta)
return True
def mpcdf_setup_repos(api_url, project, distribution, parent=None, dry_run=False):
def mpcdf_setup_repos(api_url, project, distribution, parent=None, packages=None, dry_run=False):
if parent:
for attribute in ["MPCDF:compiler_modules", "MPCDF:mpi_modules", "MPCDF:cuda_modules"]:
try:
get_attribute_values(api_url, project, None, attribute)
except Exception:
print("Copying attribute '{0}' from parent project".format(attribute))
set_attribute(api_url, (project,), get_attribute(api_url, parent, None, attribute))
compilers = list(get_attribute_values(api_url, project, None, "MPCDF:compiler_modules"))
mpis = list(get_attribute_values(api_url, project, None, "MPCDF:mpi_modules"))
cudas = list(get_attribute_values(api_url, project, None, "MPCDF:cuda_modules"))
......@@ -142,7 +153,7 @@ def mpcdf_setup_repos(api_url, project, distribution, parent=None, dry_run=False
distributions = project_meta(api_url, "distributions")
dist_repo = distributions.find('./repository[@name="{0}"]'.format(distribution))
if dist_repo is None:
raise oscerr.WrongArgs("No repository '{0}' is defined in project 'distributions' on the server".format(distribution))
raise osc.oscerr.WrongArgs("No repository '{0}' is defined in project 'distributions' on the server".format(distribution))
architectures = list(arch.text for arch in dist_repo.findall("./arch"))
root = project_meta(api_url, project)
......@@ -159,7 +170,7 @@ def mpcdf_setup_repos(api_url, project, distribution, parent=None, dry_run=False
end = len(prjconf)
prjconf_head = "".join(prjconf[:start])
prjconf_tail = "".join(prjconf[end+1:])
prjconf_tail = "".join(prjconf[end + 1:])
prjconf = [start_marker]
# Remove existing repositories
......@@ -173,12 +184,13 @@ def mpcdf_setup_repos(api_url, project, distribution, parent=None, dry_run=False
raise Exception("Invalid argument")
r = ElementTree.SubElement(root, "repository")
r.set("name", name)
r.text="\n "
r.text = "\n "
def path(project, repo):
p = ElementTree.SubElement(r, "path")
p.set("project", project)
p.set("repository", repo)
p.tail="\n "
p.tail = "\n "
if parent:
path(parent, name)
......@@ -200,8 +212,10 @@ def mpcdf_setup_repos(api_url, project, distribution, parent=None, dry_run=False
prjconf.append("%endif")
prjconf.append("")
repo("System", ("distributions", distribution))
if parent:
repo("System")
else:
repo("System", ("distributions", distribution))
for compiler in compilers:
repo(compiler, (project, "System"))
......@@ -218,7 +232,6 @@ def mpcdf_setup_repos(api_url, project, distribution, parent=None, dry_run=False
(project, mpi + "_" + compiler),
mpi=True, cuda=True)
# Remove build configuration
build = root.find("./build")
if build is None:
......@@ -230,7 +243,7 @@ def mpcdf_setup_repos(api_url, project, distribution, parent=None, dry_run=False
root.insert(list(root).index(root.find("./repository")), build)
root.getchildren()[-1].tail = "\n"
prj = ET.tostring(root, encoding=osc.core.ET_ENCODING)
prj = ElementTree.tostring(root, encoding=osc.core.ET_ENCODING)
prjconf.append(end_marker)
prjconf = prjconf_head + "\n".join(prjconf) + prjconf_tail
......@@ -241,7 +254,9 @@ def mpcdf_setup_repos(api_url, project, distribution, parent=None, dry_run=False
else:
# First set-up the <enable/> flags, that way no
# spurious builds are launched
for package in osc.core.meta_get_packagelist(api_url, project):
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):
print("ATTENTION: Not changing unmanaged package {0}".format(package))
......@@ -251,4 +266,3 @@ def mpcdf_setup_repos(api_url, project, distribution, parent=None, dry_run=False
osc.core.edit_meta("prj", project, data=prj)
print("Updating prjconf meta")
osc.core.edit_meta("prjconf", project, data=prjconf)
#!/usr/bin/python2
from __future__ import print_function
import sys
import argparse
from functools import partial
from xml.etree import ElementTree
from mpcdf_common import *
from mpcdf_setup_repos import do_mpcdf_setup_repos
from mpcdf_common import get_attribute, set_attribute, project_meta, mpcdf_setup_repos
import osc
import osc.conf
import osc.core
import osc.cmdln
def do_mpcdf_push(self, subcmd, opts, from_project, to_project):
"""${cmd_name}: Branch all packages from one project to another"
def do_mpcdf_push(self, subcmd, opts, *args):
"""${cmd_name}: Branch all packages from one project to another
All packages from FROM_PROJECT (that do not yet exist in the target
project) are branched into TO_PROJECT.
......@@ -22,13 +17,28 @@ def do_mpcdf_push(self, subcmd, opts, from_project, to_project):
Packages that already exist are not branched/modified but the repository
configuration is updated to match the attribute settings from FROM_PROJECT.
${cmd_usage}
Usage:
osc mpcdf_push FROM_PROJECT TO_PROJECT
osc mpcdf_push FROM_PROJECT PACKAGE TO_PROJECT
${cmd_option_list}
"""
if len(args) < 2:
raise osc.oscerr.WrongArgs("Not enough arguments")
elif len(args) == 2:
from_project, to_project = args
package = None
elif len(args) == 3:
from_project, package, to_project = args
else:
raise osc.oscerr.WrongArgs("Too many arguments")
api_url = self.get_api_url()
from_packages = osc.core.meta_get_packagelist(api_url, from_project)
if package is None:
from_packages = osc.core.meta_get_packagelist(api_url, from_project)
else:
from_packages = [package]
to_packages = osc.core.meta_get_packagelist(api_url, to_project)
project_attributes = ["MPCDF:compiler_modules", "MPCDF:cuda_modules", "MPCDF:mpi_modules"]
......@@ -37,27 +47,27 @@ def do_mpcdf_push(self, subcmd, opts, from_project, to_project):
for attribute in project_attributes:
try:
get_attribute(api_url, to_project, None, attribute)
except:
except Exception:
attr = get_attribute(api_url, from_project, None, attribute)
print("Setting attribute", attribute)
set_attribute(api_url, (to_project,), attr)
for package in from_packages:
if not package in to_packages:
l = osc.core.meta_get_filelist(api_url, from_project, package)
if "_link" in l:
print("Skipping package {0}, is a link".format(package))
if package not in to_packages:
filelist = osc.core.meta_get_filelist(api_url, from_project, package)
if "_link" in filelist:
print("Not branching package {0}, is a link".format(package))
else:
print("Branching package {0}".format(package))
exists, targetprj, targetpkg, srcprj, srcpkg = \
branch_pkg(api_url, from_project, package, target_project=to_project)
osc.core.branch_pkg(api_url, from_project, package, target_project=to_project)
else:
print("Skipping package {0}, already present in target".format(package))
print("Not branching package {0}, already present in target".format(package))
for attribute in package_attributes:
try:
attr = get_attribute(api_url, from_project, package, attribute)
except:
except Exception as e:
continue
set_attribute(api_url, (to_project, package), attr)
......@@ -70,4 +80,4 @@ def do_mpcdf_push(self, subcmd, opts, from_project, to_project):
distribution = sys_repo.find('./path[@project="distributions"]').get("repository")
print("Creating repository configuration")
mpcdf_setup_repos(api_url, to_project, distribution)
mpcdf_setup_repos(api_url, to_project, distribution, packages=[package] if package else None)
Supports Markdown
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