Commit 5a5fc9a7 authored by Lorenz Huedepohl's avatar Lorenz Huedepohl
Browse files

New command 'mpcdf_copy_attributes'

parent 4a6a1ab3
Pipeline #71924 passed with stage
in 15 seconds
#!/usr/bin/python2
from __future__ import print_function
import mpcdf_common
import osc
import osc.conf
import osc.core
import osc.cmdln
@osc.cmdln.option('-t', '--to-apiurl', metavar='URL',
help='URL of destination api server. Default is the source api server.')
@osc.cmdln.alias("mpcdf_copy_attrs")
def do_mpcdf_copy_attributes(self, subcmd, opts, *args):
"""${cmd_name}: Copy attributes from one package to another
Usage:
osc mpcdf_copy_attributes SOURCE_PROJECT SOURCE_PACKAGE DEST_PROJECT DEST_PACKAGE
${cmd_option_list}
"""
if len(args) != 4:
raise osc.oscerr.WrongArgs('Wrong number of arguments')
else:
src_project, src_package, dst_project, dst_package = args
src_api = self.get_api_url()
if opts.to_apiurl:
dst_api = osc.conf.config['apiurl_aliases'].get(opts.to_apiurl, opts.to_apiurl)
else:
dst_api = src_api
for attribute in mpcdf_common.package_attributes + mpcdf_common.config_attributes:
try:
attr = mpcdf_common.get_attribute(src_api, src_project, src_package, attribute)
except mpcdf_common.UnsetAttributeException:
if mpcdf_common.has_attribute(dst_api, dst_project, dst_package, attribute):
mpcdf_common.remove_attribute(dst_api, dst_project, dst_package, attribute)
continue
mpcdf_common.set_attribute(dst_api, dst_project, dst_package, attr)
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