mirror of
https://github.com/openSUSE/osc.git
synced 2024-12-26 09:56:13 +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!'
|
||||
return 1
|
||||
|
||||
except oscerr.UserAbort:
|
||||
print >>sys.stderr, 'aborted.'
|
||||
return 1
|
||||
|
||||
except oscerr.UnreadableFile, e:
|
||||
print >>sys.stderr, e.msg
|
||||
return 1
|
||||
|
@ -663,14 +663,19 @@ class Osc(cmdln.Cmdln):
|
||||
print r
|
||||
|
||||
|
||||
def do_deletepac(self, subcmd, opts, project, package):
|
||||
"""${cmd_name}: Delete a package on the repository server
|
||||
def do_deletepac(self, subcmd, opts, project, *pkgs):
|
||||
"""${cmd_name}: Delete packages on the repository server
|
||||
|
||||
${cmd_usage}
|
||||
usage:
|
||||
osc deletepac PROJECT PACKAGE [PACKAGE ...]
|
||||
${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',
|
||||
@ -875,6 +880,8 @@ class Osc(cmdln.Cmdln):
|
||||
+ 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',
|
||||
help='print extra information')
|
||||
@cmdln.alias('st')
|
||||
@ -933,10 +940,10 @@ class Osc(cmdln.Cmdln):
|
||||
raise oscerr.NoWorkingCopy, msg
|
||||
lines = []
|
||||
# process single packages
|
||||
lines = getStatus(findpacs(pacpaths), None, opts.verbose)
|
||||
lines = getStatus(findpacs(pacpaths), None, opts.verbose, opts.quiet)
|
||||
# process project dirs
|
||||
for prj, pacs in prjpacs.iteritems():
|
||||
lines += getStatus(findpacs(pacs), prj, opts.verbose)
|
||||
lines += getStatus(findpacs(pacs), prj, opts.verbose, opts.quiet)
|
||||
if lines:
|
||||
print '\n'.join(lines)
|
||||
|
||||
@ -1029,6 +1036,9 @@ class Osc(cmdln.Cmdln):
|
||||
${cmd_usage}
|
||||
${cmd_option_list}
|
||||
"""
|
||||
|
||||
args = parseargs(args)
|
||||
|
||||
msg = ''
|
||||
if opts.message:
|
||||
msg = opts.message
|
||||
@ -1038,13 +1048,27 @@ class Osc(cmdln.Cmdln):
|
||||
except:
|
||||
sys.exit('could not open file \'%s\'.' % opts.file)
|
||||
|
||||
args = parseargs(args)
|
||||
for arg in args:
|
||||
if conf.config['do_package_tracking'] and is_project_dir(arg):
|
||||
Project(arg).commit(msg=msg)
|
||||
args.remove(arg)
|
||||
|
||||
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:
|
||||
prj_paths = {}
|
||||
single_paths = []
|
||||
|
51
osc/core.py
51
osc/core.py
@ -133,8 +133,11 @@ new_user_template = """\
|
||||
"""
|
||||
|
||||
info_templ = """\
|
||||
Project name: %s
|
||||
Package name: %s
|
||||
Path: %s
|
||||
API URL: %s
|
||||
Source URL: %s
|
||||
srcmd5: %s
|
||||
Revision: %s
|
||||
Link info: %s
|
||||
@ -589,7 +592,8 @@ class Package:
|
||||
self.todo_delete = []
|
||||
|
||||
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
|
||||
|
||||
def addfile(self, n):
|
||||
@ -1780,6 +1784,38 @@ def read_meta_from_spec(specfile, *args):
|
||||
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,
|
||||
src_project, src_package,
|
||||
dst_project, dst_package,
|
||||
@ -3257,7 +3293,7 @@ def getTransActPath(pac_dir):
|
||||
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()
|
||||
objects and prj_obj is a Project() object. If prj_obj is specified all
|
||||
@ -3294,8 +3330,11 @@ def getStatus(pacs, prj_obj=None, verbose=False):
|
||||
elif s != ' ' or (s == ' ' and verbose):
|
||||
lines.append(statfrmt(s, pathjoin(p.dir, filename)))
|
||||
|
||||
# arrange the lines in order: unknown files first
|
||||
# filenames are already sorted
|
||||
lines = [line for line in lines if line[0] == '?'] \
|
||||
+ [line for line in lines if line[0] != '?']
|
||||
if quiet:
|
||||
lines = [line for line in lines if line[0] != '?']
|
||||
else:
|
||||
# arrange the lines in order: unknown files first
|
||||
# filenames are already sorted
|
||||
lines = [line for line in lines if line[0] == '?'] \
|
||||
+ [line for line in lines if line[0] != '?']
|
||||
return lines
|
||||
|
@ -14,6 +14,9 @@ class OscBaseError(Exception):
|
||||
def __str__(self):
|
||||
return ''.join(self.args)
|
||||
|
||||
class UserAbort(OscBaseError):
|
||||
"""Exception raised when the user requested abortion"""
|
||||
|
||||
class ConfigError(OscBaseError):
|
||||
"""Exception raised when there is an error in the config file"""
|
||||
def __init__(self, msg):
|
||||
|
Loading…
Reference in New Issue
Block a user