diff options
author | Ed Bartosh <eduard.bartosh@intel.com> | 2015-02-15 00:59:41 +0200 |
---|---|---|
committer | Ed Bartosh <eduard.bartosh@intel.com> | 2015-02-19 15:07:49 +0200 |
commit | 779b04108ac6bf43b43c0a9f97b4927bbdd47c43 (patch) | |
tree | 1faff634bab70c150385bd3fb852958574bfa329 | |
parent | 096cc22035ecb46f538d0ed2b3dc062ddd5abf3b (diff) | |
download | repa-779b04108ac6bf43b43c0a9f97b4927bbdd47c43.tar.gz repa-779b04108ac6bf43b43c0a9f97b4927bbdd47c43.tar.bz2 repa-779b04108ac6bf43b43c0a9f97b4927bbdd47c43.zip |
Implement --edit command line option
-e or --edit option is used in accept, reject, rebuild, lock, unlock and
remove commands to edit a comment. Default comment is taken from
accept_comment, reject_comment, rebuild_comment, lock_comment,
unlock_comment or remove_comment configuration options.
Fixes: #2420
Change-Id: I5979ebd246541b5c4ba56629ba97fd268b178d8d
Signed-off-by: Ed Bartosh <eduard.bartosh@intel.com>
-rw-r--r-- | repa.1 | 67 | ||||
-rw-r--r-- | repa/accept.py | 13 | ||||
-rw-r--r-- | repa/common.py | 33 | ||||
-rw-r--r-- | repa/lock.py | 10 | ||||
-rw-r--r-- | repa/rebuild.py | 10 | ||||
-rw-r--r-- | repa/reject.py | 12 | ||||
-rw-r--r-- | repa/remove.py | 10 | ||||
-rw-r--r-- | repa/unlock.py | 10 |
8 files changed, 149 insertions, 16 deletions
@@ -255,6 +255,12 @@ Add acceptance comment for created SR. Trigger Jenkins job to accept submission. .RE +.PP +\-e \-\-edit +.RS 2 +Run editor to edit comment. Editor is taken from EDITOR environment variable. +.RE + .\" .\" The "reject" command description .\" @@ -287,6 +293,12 @@ Add rejection comment for created SR. Trigger Jenkins job to reject submission. .RE +.PP +\-e \-\-edit +.RS 2 +Run editor to edit comment. Editor is taken from EDITOR environment variable. +.RE + .\" .\" The "group" command description .\" @@ -422,6 +434,12 @@ Provide a comment with the explanation of a reason for rebuild. Mandatory option Rebuild only one package. .RE +.PP +\-e \-\-edit +.RS 2 +Run editor to edit comment. Editor is taken from EDITOR environment variable. +.RE + .\" .\" The "lock" command description .\" @@ -447,6 +465,12 @@ Print short help text about the "lock" command and exit. Provide a comment with the explanation of a reason for lock. Mandatory option. .RE +.PP +\-e \-\-edit +.RS 2 +Run editor to edit comment. Editor is taken from EDITOR environment variable. +.RE + .\" .\" The "unlock" command description .\" @@ -472,6 +496,11 @@ Print short help text about the "unlock" command and exit. Provide a comment with the explanation of a reason for unlock. .RE +.PP +\-e \-\-edit +.RS 2 +Run editor to edit comment. Editor is taken from EDITOR environment variable. +.RE .\" .\" The "remove" command description @@ -498,6 +527,12 @@ Print short help text about the "remove" command and exit. Provide a comment with the explanation of a reason for remove. This is mandatory option. .RE +.PP +\-e \-\-edit +.RS 2 +Run editor to edit comment. Editor is taken from EDITOR environment variable. +.RE + .SH CONFIGURATION FILE @@ -554,8 +589,36 @@ noaggregate = mic-bootstrap-x86-arm.rpm|mic-bootstrap.rpm|mic-bootstrap-debugsou .RS 2 showtime = off .RE - - +.RS 2 +accept_comment = default comment + for accept + command +.RE +.RS 2 +reject_comment = default comment + for reject + command +.RE +.RS 2 +rebuild_comment = default comment + for rebuild + command +.RE +.RS 2 +lock_comment = default comment + for lock + command +.RE +.RS 2 +unlock_comment = default comment + for unlock + command +.RE +.RS 2 +remove_comment = default comment + for remove + command +.RE .RS 2 Mandatory options: apiurl, apiuser, apipasswd, jenkins_url, jenkins_user, jenkins_passwd and project diff --git a/repa/accept.py b/repa/accept.py index 410952d..45be50a 100644 --- a/repa/accept.py +++ b/repa/accept.py @@ -34,7 +34,7 @@ from collections import namedtuple from repa.obs import OBS from repa.main import sub_main -from repa.common import accept_or_reject +from repa.common import accept_or_reject, edit class Accept(object): @@ -45,16 +45,23 @@ class Accept(object): help = description @staticmethod - def add_arguments(parser, _): + def add_arguments(parser, config): """Adds arguments to the parser. Called from [sub_]main.""" + parser.add_argument('submission', help='submission or group') - parser.add_argument('-c', '--comment', help='comment', default='') + parser.add_argument('-c', '--comment', help='comment', + default=config.get('accept_comment', '')) parser.add_argument('-j', '--jenkins', action='store_true', help='trigger Jenkins job') + parser.add_argument('-e', '--edit', action='store_true', + help='run editor to edit comment') @staticmethod def run(argv): """Command line entry point. Called from [sub_]main.""" + if argv.edit: + argv.comment = edit(argv.comment) + obs = OBS(argv.apiurl, argv.apiuser, argv.apipasswd) cred = None diff --git a/repa/common.py b/repa/common.py index 7829f52..e63f073 100644 --- a/repa/common.py +++ b/repa/common.py @@ -33,7 +33,10 @@ import sys import os import time import json +import tempfile +import subprocess from functools import wraps, partial +from distutils.spawn import find_executable from repa.jenkins import trigger_build @@ -219,3 +222,33 @@ def get_obs_url(meta, buildurl='https://build.tizen.org'): return os.path.join(buildurl, 'project/show?project=home:prerelease:%s:%s' % (meta['obs_target_prj'], name.replace('/', ':'))) + +def edit(content): + """ + Launch an editor to get input from user. + Returns: content of user input. + """ + editor = os.getenv('EDITOR') or 'vi' + + if not find_executable(editor): + raise RepaException("editor %s not found. Please set EDITOR " + "environment variable or install vi" % editor) + + fds, path = tempfile.mkstemp('.tmp', 'repa-', text=True) + try: + if content: + os.write(fds, content) + os.close(fds) + + try: + subprocess.call([editor, path]) + except OSError as error: + raise RepaException("Can't run %s %s: %s" % (editor, path, error)) + + with open(path) as fobj: + result = fobj.read() + finally: + os.unlink(path) + + return result + diff --git a/repa/lock.py b/repa/lock.py index 9edd966..a9d9c04 100644 --- a/repa/lock.py +++ b/repa/lock.py @@ -35,6 +35,7 @@ from collections import namedtuple from repa.main import sub_main from repa.jenkins import trigger_build +from repa.common import edit class Lock(object): """Subcommand: lock submissions.""" @@ -44,14 +45,19 @@ class Lock(object): help = description @staticmethod - def add_arguments(parser, _): + def add_arguments(parser, config): """Adds arguments to the parser. Called from [sub_]main.""" parser.add_argument('submission', help='submission') - parser.add_argument('-c', '--comment', help='comment', required=True) + parser.add_argument('-c', '--comment', help='comment', + default=config.get('lock_comment', '')) + parser.add_argument('-e', '--edit', action='store_true', + help='run editor to edit comment') @staticmethod def run(argv): """Command line entry point. Called from [sub_]main.""" + if argv.edit: + argv.comment = edit(argv.comment) job = 're' cred = namedtuple('cred', ['url', 'username', 'password'])(\ argv.jenkins_url, argv.jenkins_user, argv.jenkins_passwd) diff --git a/repa/rebuild.py b/repa/rebuild.py index d79b823..898658f 100644 --- a/repa/rebuild.py +++ b/repa/rebuild.py @@ -35,6 +35,7 @@ from collections import namedtuple from repa.main import sub_main from repa.jenkins import trigger_build +from repa.common import edit class Rebuild(object): """Subcommand: rebuild submissions.""" @@ -44,15 +45,20 @@ class Rebuild(object): help = description @staticmethod - def add_arguments(parser, _): + def add_arguments(parser, config): """Adds arguments to the parser. Called from [sub_]main.""" parser.add_argument('submission', help='submission') parser.add_argument('-p', '--package', help='package') - parser.add_argument('-c', '--comment', help='comment', required=True) + parser.add_argument('-c', '--comment', help='comment', + default=config.get('rebuild_comment', '')) + parser.add_argument('-e', '--edit', action='store_true', + help='run editor to edit comment') @staticmethod def run(argv): """Command line entry point. Called from [sub_]main.""" + if argv.edit: + argv.comment = edit(argv.comment) job = 're' cred = namedtuple('cred', ['url', 'username', 'password'])(\ argv.jenkins_url, argv.jenkins_user, argv.jenkins_passwd) diff --git a/repa/reject.py b/repa/reject.py index 4f8290a..8866e3f 100644 --- a/repa/reject.py +++ b/repa/reject.py @@ -34,7 +34,7 @@ from collections import namedtuple from repa.obs import OBS from repa.main import sub_main -from repa.common import accept_or_reject +from repa.common import accept_or_reject, edit class Reject(object): @@ -45,16 +45,22 @@ class Reject(object): help = description @staticmethod - def add_arguments(parser, _): + def add_arguments(parser, config): """Adds arguments to the parser. Called from [sub_]main.""" parser.add_argument('submission', help='submission or group') - parser.add_argument('-c', '--comment', help='comment', default='') + parser.add_argument('-c', '--comment', help='comment', + default=config.get('reject_comment', '')) parser.add_argument('-j', '--jenkins', action='store_true', help='trigger Jenkins job') + parser.add_argument('-e', '--edit', action='store_true', + help='run editor to edit comment') @staticmethod def run(argv): """Command line entry point. Called from [sub_]main.""" + if argv.edit: + argv.comment = edit(argv.comment) + obs = OBS(argv.apiurl, argv.apiuser, argv.apipasswd) cred = None diff --git a/repa/remove.py b/repa/remove.py index f06cbbf..5bfe05b 100644 --- a/repa/remove.py +++ b/repa/remove.py @@ -35,6 +35,7 @@ from collections import namedtuple from repa.main import sub_main from repa.jenkins import trigger_build +from repa.common import edit class Remove(object): """Subcommand: remove submissions.""" @@ -44,14 +45,19 @@ class Remove(object): help = description @staticmethod - def add_arguments(parser, _): + def add_arguments(parser, config): """Adds arguments to the parser. Called from [sub_]main.""" parser.add_argument('submission', help='submission') - parser.add_argument('-c', '--comment', help='comment', required=True) + parser.add_argument('-c', '--comment', help='comment', + default=config.get('remove_comment', '')) + parser.add_argument('-e', '--edit', action='store_true', + help='run editor to edit comment') @staticmethod def run(argv): """Command line entry point. Called from [sub_]main.""" + if argv.edit: + argv.comment = edit(argv.comment) job = 're' cred = namedtuple('cred', ['url', 'username', 'password'])(\ argv.jenkins_url, argv.jenkins_user, argv.jenkins_passwd) diff --git a/repa/unlock.py b/repa/unlock.py index 47e0fec..7e90330 100644 --- a/repa/unlock.py +++ b/repa/unlock.py @@ -35,6 +35,7 @@ from collections import namedtuple from repa.main import sub_main from repa.jenkins import trigger_build +from repa.common import edit class Unlock(object): """Subcommand: unlock submissions.""" @@ -44,14 +45,19 @@ class Unlock(object): help = description @staticmethod - def add_arguments(parser, _): + def add_arguments(parser, config): """Adds arguments to the parser. Called from [sub_]main.""" parser.add_argument('submission', help='submission') - parser.add_argument('-c', '--comment', help='comment') + parser.add_argument('-c', '--comment', help='comment', + default=config.get('unlock_comment', '')) + parser.add_argument('-e', '--edit', action='store_true', + help='run editor to edit comment') @staticmethod def run(argv): """Command line entry point. Called from [sub_]main.""" + if argv.edit: + argv.comment = edit(argv.comment) job = 're' cred = namedtuple('cred', ['url', 'username', 'password'])(\ argv.jenkins_url, argv.jenkins_user, argv.jenkins_passwd) |