mirror of
https://github.com/openSUSE/osc.git
synced 2024-12-27 18:26:15 +01:00
- osc commit: open $EDITOR for commit message
- osc status: implement -q/--quiet switch - osc deletepac: allow deletion of multiple packages at once - osc info: slightly more verbose - core.edit_message() added - core.getStatus() accepts new "quiet" argument - oscerr.UserAbort added
This commit is contained in:
parent
3c5a25f1a5
commit
7e524fd442
@ -58,6 +58,10 @@ def run(prg):
|
|||||||
print >>sys.stderr, 'interrupted!'
|
print >>sys.stderr, 'interrupted!'
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
|
except oscerr.UserAbort:
|
||||||
|
print >>sys.stderr, 'aborted.'
|
||||||
|
return 1
|
||||||
|
|
||||||
except oscerr.UnreadableFile, e:
|
except oscerr.UnreadableFile, e:
|
||||||
print >>sys.stderr, e.msg
|
print >>sys.stderr, e.msg
|
||||||
return 1
|
return 1
|
||||||
|
@ -663,14 +663,19 @@ class Osc(cmdln.Cmdln):
|
|||||||
print r
|
print r
|
||||||
|
|
||||||
|
|
||||||
def do_deletepac(self, subcmd, opts, project, package):
|
def do_deletepac(self, subcmd, opts, project, *pkgs):
|
||||||
"""${cmd_name}: Delete a package on the repository server
|
"""${cmd_name}: Delete packages on the repository server
|
||||||
|
|
||||||
${cmd_usage}
|
usage:
|
||||||
|
osc deletepac PROJECT PACKAGE [PACKAGE ...]
|
||||||
${cmd_option_list}
|
${cmd_option_list}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
delete_package(conf.config['apiurl'], project, package)
|
if not pkgs:
|
||||||
|
raise oscerr.WrongArgs('Missing argument.')
|
||||||
|
|
||||||
|
for pkg in pkgs:
|
||||||
|
delete_package(conf.config['apiurl'], project, pkg)
|
||||||
|
|
||||||
|
|
||||||
@cmdln.option('-f', '--force', action='store_true',
|
@cmdln.option('-f', '--force', action='store_true',
|
||||||
@ -875,6 +880,8 @@ class Osc(cmdln.Cmdln):
|
|||||||
+ self.get_cmd_help('checkout'))
|
+ self.get_cmd_help('checkout'))
|
||||||
|
|
||||||
|
|
||||||
|
@cmdln.option('-q', '--quiet', action='store_true',
|
||||||
|
help='print as little as possible')
|
||||||
@cmdln.option('-v', '--verbose', action='store_true',
|
@cmdln.option('-v', '--verbose', action='store_true',
|
||||||
help='print extra information')
|
help='print extra information')
|
||||||
@cmdln.alias('st')
|
@cmdln.alias('st')
|
||||||
@ -933,10 +940,10 @@ class Osc(cmdln.Cmdln):
|
|||||||
raise oscerr.NoWorkingCopy, msg
|
raise oscerr.NoWorkingCopy, msg
|
||||||
lines = []
|
lines = []
|
||||||
# process single packages
|
# process single packages
|
||||||
lines = getStatus(findpacs(pacpaths), None, opts.verbose)
|
lines = getStatus(findpacs(pacpaths), None, opts.verbose, opts.quiet)
|
||||||
# process project dirs
|
# process project dirs
|
||||||
for prj, pacs in prjpacs.iteritems():
|
for prj, pacs in prjpacs.iteritems():
|
||||||
lines += getStatus(findpacs(pacs), prj, opts.verbose)
|
lines += getStatus(findpacs(pacs), prj, opts.verbose, opts.quiet)
|
||||||
if lines:
|
if lines:
|
||||||
print '\n'.join(lines)
|
print '\n'.join(lines)
|
||||||
|
|
||||||
@ -1029,6 +1036,9 @@ class Osc(cmdln.Cmdln):
|
|||||||
${cmd_usage}
|
${cmd_usage}
|
||||||
${cmd_option_list}
|
${cmd_option_list}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
args = parseargs(args)
|
||||||
|
|
||||||
msg = ''
|
msg = ''
|
||||||
if opts.message:
|
if opts.message:
|
||||||
msg = opts.message
|
msg = opts.message
|
||||||
@ -1038,13 +1048,27 @@ class Osc(cmdln.Cmdln):
|
|||||||
except:
|
except:
|
||||||
sys.exit('could not open file \'%s\'.' % opts.file)
|
sys.exit('could not open file \'%s\'.' % opts.file)
|
||||||
|
|
||||||
args = parseargs(args)
|
|
||||||
for arg in args:
|
for arg in args:
|
||||||
if conf.config['do_package_tracking'] and is_project_dir(arg):
|
if conf.config['do_package_tracking'] and is_project_dir(arg):
|
||||||
Project(arg).commit(msg=msg)
|
Project(arg).commit(msg=msg)
|
||||||
args.remove(arg)
|
args.remove(arg)
|
||||||
|
|
||||||
pacs = findpacs(args)
|
pacs = findpacs(args)
|
||||||
|
|
||||||
|
if not msg:
|
||||||
|
# open editor for commit message
|
||||||
|
# but first, produce status and diff to append to the template
|
||||||
|
footer = diffs = []
|
||||||
|
for pac in pacs:
|
||||||
|
changed = getStatus([pac], quiet=True)
|
||||||
|
if changed:
|
||||||
|
footer += changed
|
||||||
|
diffs += ['\nDiff for working copy: %s' % pac.dir]
|
||||||
|
diffs += make_diff(pac, 0)
|
||||||
|
# if footer is empty, there is nothing to commit, and no edit needed.
|
||||||
|
if footer:
|
||||||
|
msg = edit_message(footer='\n'.join(footer))
|
||||||
|
|
||||||
if conf.config['do_package_tracking'] and len(pacs) > 0:
|
if conf.config['do_package_tracking'] and len(pacs) > 0:
|
||||||
prj_paths = {}
|
prj_paths = {}
|
||||||
single_paths = []
|
single_paths = []
|
||||||
|
43
osc/core.py
43
osc/core.py
@ -133,8 +133,11 @@ new_user_template = """\
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
info_templ = """\
|
info_templ = """\
|
||||||
|
Project name: %s
|
||||||
|
Package name: %s
|
||||||
Path: %s
|
Path: %s
|
||||||
API URL: %s
|
API URL: %s
|
||||||
|
Source URL: %s
|
||||||
srcmd5: %s
|
srcmd5: %s
|
||||||
Revision: %s
|
Revision: %s
|
||||||
Link info: %s
|
Link info: %s
|
||||||
@ -589,7 +592,8 @@ class Package:
|
|||||||
self.todo_delete = []
|
self.todo_delete = []
|
||||||
|
|
||||||
def info(self):
|
def info(self):
|
||||||
r = info_templ % (self.dir, self.apiurl, self.srcmd5, self.rev, self.linkinfo)
|
source_url = makeurl(self.apiurl, ['source', self.prjname, self.name])
|
||||||
|
r = info_templ % (self.prjname, self.name, self.absdir, self.apiurl, source_url, self.srcmd5, self.rev, self.linkinfo)
|
||||||
return r
|
return r
|
||||||
|
|
||||||
def addfile(self, n):
|
def addfile(self, n):
|
||||||
@ -1780,6 +1784,38 @@ def read_meta_from_spec(specfile, *args):
|
|||||||
return spec_data
|
return spec_data
|
||||||
|
|
||||||
|
|
||||||
|
def edit_message(footer=''):
|
||||||
|
delim = '--This line, and those below, will be ignored--\n\n' + footer
|
||||||
|
import tempfile
|
||||||
|
(fd, filename) = tempfile.mkstemp(prefix = 'osc-commitmsg', suffix = '.txt', dir = '/tmp')
|
||||||
|
f = os.fdopen(fd, 'w')
|
||||||
|
f.write('\n')
|
||||||
|
f.write(delim)
|
||||||
|
f.close()
|
||||||
|
hash_orig = dgst(filename)
|
||||||
|
|
||||||
|
editor = os.getenv('EDITOR', default='vim')
|
||||||
|
while 1:
|
||||||
|
os.system('%s %s' % (editor, filename))
|
||||||
|
hash = dgst(filename)
|
||||||
|
|
||||||
|
if hash != hash_orig:
|
||||||
|
msg = open(filename).read()
|
||||||
|
os.unlink(filename)
|
||||||
|
return msg.split(delim)[0].rstrip()
|
||||||
|
else:
|
||||||
|
input = raw_input('Log message unchanged or not specified\n'
|
||||||
|
'a)bort, c)ontinue, e)dit: ')
|
||||||
|
if input in 'aA':
|
||||||
|
os.unlink(filename)
|
||||||
|
raise oscerr.UserAbort
|
||||||
|
elif input in 'cC':
|
||||||
|
os.unlink(filename)
|
||||||
|
return ''
|
||||||
|
elif input in 'eE':
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
def create_submit_request(apiurl,
|
def create_submit_request(apiurl,
|
||||||
src_project, src_package,
|
src_project, src_package,
|
||||||
dst_project, dst_package,
|
dst_project, dst_package,
|
||||||
@ -3257,7 +3293,7 @@ def getTransActPath(pac_dir):
|
|||||||
pathn = ''
|
pathn = ''
|
||||||
return pathn
|
return pathn
|
||||||
|
|
||||||
def getStatus(pacs, prj_obj=None, verbose=False):
|
def getStatus(pacs, prj_obj=None, verbose=False, quiet=False):
|
||||||
"""
|
"""
|
||||||
calculates the status of certain packages. pacs is a list of Package()
|
calculates the status of certain packages. pacs is a list of Package()
|
||||||
objects and prj_obj is a Project() object. If prj_obj is specified all
|
objects and prj_obj is a Project() object. If prj_obj is specified all
|
||||||
@ -3294,6 +3330,9 @@ def getStatus(pacs, prj_obj=None, verbose=False):
|
|||||||
elif s != ' ' or (s == ' ' and verbose):
|
elif s != ' ' or (s == ' ' and verbose):
|
||||||
lines.append(statfrmt(s, pathjoin(p.dir, filename)))
|
lines.append(statfrmt(s, pathjoin(p.dir, filename)))
|
||||||
|
|
||||||
|
if quiet:
|
||||||
|
lines = [line for line in lines if line[0] != '?']
|
||||||
|
else:
|
||||||
# arrange the lines in order: unknown files first
|
# arrange the lines in order: unknown files first
|
||||||
# filenames are already sorted
|
# filenames are already sorted
|
||||||
lines = [line for line in lines if line[0] == '?'] \
|
lines = [line for line in lines if line[0] == '?'] \
|
||||||
|
@ -14,6 +14,9 @@ class OscBaseError(Exception):
|
|||||||
def __str__(self):
|
def __str__(self):
|
||||||
return ''.join(self.args)
|
return ''.join(self.args)
|
||||||
|
|
||||||
|
class UserAbort(OscBaseError):
|
||||||
|
"""Exception raised when the user requested abortion"""
|
||||||
|
|
||||||
class ConfigError(OscBaseError):
|
class ConfigError(OscBaseError):
|
||||||
"""Exception raised when there is an error in the config file"""
|
"""Exception raised when there is an error in the config file"""
|
||||||
def __init__(self, msg):
|
def __init__(self, msg):
|
||||||
|
Loading…
Reference in New Issue
Block a user