1
0
mirror of https://github.com/openSUSE/osc.git synced 2024-11-09 22:36:14 +01:00

- add "osc api --edit" option

This commit is contained in:
Adrian Schröter 2014-10-31 09:22:25 +01:00
parent 3e57d58729
commit bb75ce34fd
3 changed files with 21 additions and 6 deletions

2
NEWS
View File

@ -1,5 +1,5 @@
0.150
-
- add "osc api --edit" option to be able to edit some meta files directly
0.149
- removed "--diff" option from the "createrequest" command

View File

@ -6985,6 +6985,8 @@ Please submit there instead, or use --nodevelproject to force direct submission.
@cmdln.option('-X', '-m', '--method', default='GET', metavar='HTTP_METHOD',
help='specify HTTP method to use (GET|PUT|DELETE|POST)')
@cmdln.option('-e', '--edit', default=None, action='store_true',
help='GET, edit and PUT the location')
@cmdln.option('-d', '--data', default=None, metavar='STRING',
help='specify string data for e.g. POST')
@cmdln.option('-T', '-f', '--file', default=None, metavar='FILE',
@ -7005,6 +7007,7 @@ Please submit there instead, or use --nodevelproject to force direct submission.
Examples:
osc api /source/home:user
osc api -X PUT -T /etc/fstab source/home:user/test5/myfstab
osc api -e /build/_dispatchprios
${cmd_usage}
${cmd_option_list}
@ -7032,10 +7035,17 @@ Please submit there instead, or use --nodevelproject to force direct submission.
data=opts.data,
file=opts.file,
headers=opts.headers)
out = r.read()
sys.stdout.write(out)
if opts.edit:
text = edit_text(out)
r = http_request("PUT",
url,
data=text,
headers=opts.headers)
out = r.read()
sys.stdout.write(out)
@cmdln.option('-b', '--bugowner-only', action='store_true',

View File

@ -3829,7 +3829,6 @@ def _edit_message_open_editor(filename, data, orig_mtime):
return os.stat(filename).st_mtime != orig_mtime
def edit_message(footer='', template='', templatelen=30):
import tempfile
delim = '--This line, and those below, will be ignored--\n'
data = ''
if template != '':
@ -3839,13 +3838,19 @@ def edit_message(footer='', template='', templatelen=30):
if lines[templatelen:]:
footer = '%s\n\n%s' % ('\n'.join(lines[templatelen:]), footer)
data += '\n' + delim + '\n' + footer
edit_text(data, delim)
def edit_text(data='', delim=None):
import tempfile
try:
(fd, filename) = tempfile.mkstemp(prefix='osc-commitmsg', suffix='.diff')
(fd, filename) = tempfile.mkstemp(prefix='osc-editor', suffix='.txt')
os.close(fd)
mtime = os.stat(filename).st_mtime
while True:
file_changed = _edit_message_open_editor(filename, data, mtime)
msg = open(filename).read().split(delim)[0].rstrip()
msg = open(filename).read()
if delim:
msg = msg.split(delim)[0].rstrip()
if msg and file_changed:
break
else: