Commit 3a47690c authored by Lorenz Huedepohl's avatar Lorenz Huedepohl
Browse files

New command 'mpcdf_set_as_branch'

This turns a package into a branch of another package, after the fact.
parent b5359a9e
......@@ -330,3 +330,43 @@ def mpcdf_setup_repositories(api_url, project, distribution=None, parent=None, p
osc.core.edit_meta("prj", project, data=prj)
print("Updating prjconf meta")
osc.core.edit_meta("prjconf", project, data=prjconf)
def set_as_branch(api_url, my_project, my_package, main_project, main_package):
import os
def dirmeta(project, package):
url = osc.core.makeurl(api_url, ["source", project, package])
return ElementTree.fromstringlist(osc.core.streamfile(url, osc.core.http_GET))
srcmeta = dirmeta(my_project, my_package)
dstmeta = dirmeta(main_project, main_package)
linkinfo = srcmeta.find('./linkinfo')
if linkinfo is not None:
print("ERROR: package {0} is already linked to package {1} in project {2}".format(
my_package, linkinfo.get("package"), linkinfo.get("project")))
return False
linkfile = ElementTree.Element("link")
linkfile.set("project", main_project)
linkfile.set("package", main_package)
linkfile.set("baserev", dstmeta.get("srcmd5"))
patches = ElementTree.SubElement(linkfile, "patches")
ElementTree.SubElement(patches, "branch")
url = osc.core.makeurl(api_url, ["source", my_project, my_package, "_link"])
resp = ElementTree.fromstringlist(osc.core.streamfile(url, osc.core.http_PUT, data=ElementTree.tostring(linkfile)))
rev = resp.get("rev")
if rev is None:
print("ERROR: Could not commit _link file")
return False
print("Commited as revision", rev)
this_package = osc.core.store_read_package(os.curdir)
this_project = osc.core.store_read_project(os.curdir)
if this_package == my_package and this_project == my_project:
pac = osc.core.filedir_to_pac(os.curdir)
rev = pac.latest_rev(expand=True)
return True
from __future__ import print_function
import mpcdf_common
import os
import osc
import osc.conf
import osc.core
import osc.cmdln
def do_mpcdf_set_as_branch(self, subcmd, opts, *args):
"""${cmd_name}: Convert a package to be a branch of another
The package MY_PACKAGE is set-up to be a branch of the package
The currently checked out package is used as MY_PACKAGE, if that
argument is omitted, and MAIN_PACKAGE is assumed to have the same name as
MY_PACKAGE, of omitted.
osc mpcdf_set_as_branch MAIN_PROJECT [MAIN_PACKAGE]
if len(args) < 1:
raise osc.oscerr.WrongArgs("Not enough arguments")
if len(args) == 1:
main_project, = args
main_package = None
if len(args) == 2:
main_project, main_package = args
if len(args) in [1, 2]:
if osc.core.is_package_dir(os.curdir):
my_package = osc.core.store_read_package(os.curdir)
my_project = osc.core.store_read_project(os.curdir)
raise osc.oscerr.WrongArgs('Specify MY_PROJECT and MY_PACKAGE or run command in an osc package checkout directory')
if main_package is None:
main_package = my_package
if len(args) == 3:
my_project, my_package, main_project = args
main_package = my_package
if len(args) == 4:
my_project, my_package, main_project, main_package = args
elif len(args) > 4:
raise osc.oscerr.WrongArgs("Too many arguments")
if not mpcdf_common.set_as_branch(self.get_api_url(), my_project, my_package, main_project, main_package):
raise SystemExit(1)
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