From fca93a8b60a5e378d3a62bdd98f81c55affda92b Mon Sep 17 00:00:00 2001 From: Karsten Keil Date: Wed, 1 Jun 2016 14:00:37 +0200 Subject: [PATCH] Add revision control options to meta project commands --- osc/commandline.py | 22 ++++++++++++++++++---- osc/core.py | 38 ++++++++++++++++++++++++++++++-------- 2 files changed, 48 insertions(+), 12 deletions(-) diff --git a/osc/commandline.py b/osc/commandline.py index 646cccb0..21432533 100644 --- a/osc/commandline.py +++ b/osc/commandline.py @@ -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 [-r|--revision REV] ARGS... osc meta ARGS... - osc meta -e|--edit ARGS... - osc meta -F|--file ARGS... + osc meta [-m|--message TEXT] -e|--edit ARGS... + osc meta [-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', diff --git a/osc/core.py b/osc/core.py index 5aa8f4f5..d3951b56 100644 --- a/osc/core.py +++ b/osc/core.py @@ -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): - url = makeurl(apiurl, ['source', prj, '_meta']) - f = http_GET(url) +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: