1
0
mirror of https://github.com/openSUSE/osc.git synced 2024-12-24 17:16:12 +01:00

Add revision control options to meta project commands

This commit is contained in:
Karsten Keil 2016-06-01 14:00:37 +02:00
parent 2364a08236
commit fca93a8b60
2 changed files with 48 additions and 12 deletions

View File

@ -740,6 +740,10 @@ class Osc(cmdln.Cmdln):
@cmdln.option('-F', '--file', metavar='FILE',
help='read metadata from FILE, instead of opening an editor. '
'\'-\' denotes standard input. ')
@cmdln.option('-r', '--revision', metavar='REV',
help='checkout given revision instead of head revision. For prj and prjconf meta only')
@cmdln.option('-m', '--message', metavar='TEXT',
help='specify log message TEXT. For prj and prjconf meta only')
@cmdln.option('-e', '--edit', action='store_true',
help='edit metadata')
@cmdln.option('-c', '--create', action='store_true',
@ -774,6 +778,8 @@ class Osc(cmdln.Cmdln):
the --file switch. If the argument is '-', input is taken from stdin:
osc meta prjconf home:user | sed ... | osc meta prjconf home:user -F -
For meta prj and prjconf updates optional commit messages can be applied with --message.
When trying to edit a non-existing resource, it is created implicitly.
@ -783,9 +789,10 @@ class Osc(cmdln.Cmdln):
osc meta pkg PRJ PKG -e
Usage:
osc meta <prj|prjconf> [-r|--revision REV] ARGS...
osc meta <prj|pkg|prjconf|user|pattern> ARGS...
osc meta <prj|pkg|prjconf|user|pattern> -e|--edit ARGS...
osc meta <prj|pkg|prjconf|user|pattern> -F|--file ARGS...
osc meta <prj|pkg|prjconf|user|pattern> [-m|--message TEXT] -e|--edit ARGS...
osc meta <prj|pkg|prjconf|user|pattern> [-m|--message TEXT] -F|--file ARGS...
osc meta pattern --delete PRJ PATTERN
osc meta attribute PRJ [PKG [SUBPACKAGE]] [--attribute ATTRIBUTE] [--create|--delete|--set [value_list]]
${cmd_option_list}
@ -873,17 +880,20 @@ class Osc(cmdln.Cmdln):
if opts.edit or opts.file:
raise oscerr.WrongArgs('A pattern file argument is required.')
if cmd not in ['prj', 'prjconf'] and (opts.message or opts.revision):
raise oscerr.WrongOptions('options --revision and --message are only supported for the prj or prjconf subcommand')
# show
if not opts.edit and not opts.file and not opts.delete and not opts.create and not opts.set:
if cmd == 'prj':
sys.stdout.write(''.join(show_project_meta(apiurl, project)))
sys.stdout.write(''.join(show_project_meta(apiurl, project, opts.revision)))
elif cmd == 'pkg':
sys.stdout.write(''.join(show_package_meta(apiurl, project, package)))
elif cmd == 'attribute':
sys.stdout.write(''.join(show_attribute_meta(apiurl, project, package, subpackage,
opts.attribute, opts.attribute_defaults, opts.attribute_project)))
elif cmd == 'prjconf':
sys.stdout.write(''.join(show_project_conf(apiurl, project)))
sys.stdout.write(''.join(show_project_conf(apiurl, project, opts.revision)))
elif cmd == 'user':
r = get_user_meta(apiurl, user)
if r:
@ -907,6 +917,7 @@ class Osc(cmdln.Cmdln):
remove_linking_repositories=opts.remove_linking_repositories,
path_args=quote_plus(project),
apiurl=apiurl,
msg = opts.message,
template_args=({
'name': project,
'user': conf.get_apiurl_usr(apiurl)}))
@ -923,6 +934,7 @@ class Osc(cmdln.Cmdln):
edit=True,
path_args=quote_plus(project),
apiurl=apiurl,
msg = opts.message,
template_args=None)
elif cmd == 'user':
edit_meta(metatype='user',
@ -972,6 +984,7 @@ class Osc(cmdln.Cmdln):
force=opts.force,
remove_linking_repositories=opts.remove_linking_repositories,
apiurl=apiurl,
msg = opts.message,
path_args=quote_plus(project))
elif cmd == 'pkg':
edit_meta(metatype='pkg',
@ -984,6 +997,7 @@ class Osc(cmdln.Cmdln):
data=f,
edit=opts.edit,
apiurl=apiurl,
msg = opts.message,
path_args=quote_plus(project))
elif cmd == 'user':
edit_meta(metatype='user',

View File

@ -3334,14 +3334,33 @@ def meta_get_project_list(apiurl, deleted=None):
return sorted([ node.get('name') for node in root if node.get('name')])
def show_project_meta(apiurl, prj):
def show_project_meta(apiurl, prj, rev=None):
if rev:
query = {}
query['rev'] = rev
url = makeurl(apiurl, ['source', prj, '_project', '_meta'], query)
try:
f = http_GET(url)
except HTTPError as e:
error_help = "%d" % e.code
os_err = e.hdrs.get('X-Opensuse-Errorcode')
if os_err:
error_help = "%s (%d) project: %s" % (os_err, e.code, prj)
if e.code == 404 and os_err == 'unknown_package':
error_help = 'option -r|--revision is not supported by this OBS version'
e.osc_msg = 'BuildService API error: %s' % error_help
raise
else:
url = makeurl(apiurl, ['source', prj, '_meta'])
f = http_GET(url)
return f.readlines()
def show_project_conf(apiurl, prj, rev=None):
query = {}
if rev:
query['rev'] = rev
def show_project_conf(apiurl, prj):
url = makeurl(apiurl, ['source', prj, '_config'])
url = makeurl(apiurl, ['source', prj, '_config'], query)
f = http_GET(url)
return f.readlines()
@ -3575,7 +3594,7 @@ def meta_exists(metatype,
return data
def make_meta_url(metatype, path_args=None, apiurl=None, force=False, remove_linking_repositories=False):
def make_meta_url(metatype, path_args=None, apiurl=None, force=False, remove_linking_repositories=False, msg=None):
global metatypes
if not apiurl:
@ -3592,6 +3611,8 @@ def make_meta_url(metatype, path_args=None, apiurl=None, force=False, remove_lin
query = { 'force': '1' }
if remove_linking_repositories:
query['remove_linking_repositories'] = '1'
if msg:
query['comment'] = msg
return makeurl(apiurl, [path], query)
@ -3604,7 +3625,8 @@ def edit_meta(metatype,
force=False,
remove_linking_repositories=False,
change_is_required=False,
apiurl=None):
apiurl=None,
msg=None):
global metatypes
@ -3631,7 +3653,7 @@ def edit_meta(metatype,
print(' osc meta pkg %s %s -e' % (unquote(project), package))
return
url = make_meta_url(metatype, path_args, apiurl, force, remove_linking_repositories)
url = make_meta_url(metatype, path_args, apiurl, force, remove_linking_repositories, msg)
f = metafile(url, data, change_is_required, metatypes[metatype]['file_ext'])
if edit: