mirror of
https://github.com/openSUSE/osc.git
synced 2024-12-24 17:16:12 +01:00
- refactored getStatus into the Project/Package class
- removed getStatus - added the following new methods to the Project class: * get_status: get the status of all packages in the project * status: get the status of a single package * get_pacobj: return a new Package object - added the following new method to the Package class: * get_status: get the status of all files in the package - do_commit: fixed getStatus() call - do_status: rewrite (uses new methods)
This commit is contained in:
parent
f8eae74898
commit
c330700f36
@ -2878,41 +2878,42 @@ Please submit there instead, or use --nodevelproject to force direct submission.
|
|||||||
${cmd_option_list}
|
${cmd_option_list}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
args = parseargs(args)
|
if opts.quiet and opts.verbose:
|
||||||
|
raise oscerr.WrongOptions('\'--quiet\' and \'--verbose\' are mutually exclusive')
|
||||||
|
|
||||||
# storage for single Package() objects
|
args = parseargs(args)
|
||||||
pacpaths = []
|
lines = []
|
||||||
# storage for a project dir ( { prj_instance : [ package objects ] } )
|
excl_states = (' ',)
|
||||||
prjpacs = {}
|
if opts.quiet:
|
||||||
|
excl_states += ('?',)
|
||||||
|
elif opts.verbose:
|
||||||
|
excl_states = ()
|
||||||
for arg in args:
|
for arg in args:
|
||||||
# when 'status' is run inside a project dir, it should
|
|
||||||
# stat all packages existing in the wc
|
|
||||||
if is_project_dir(arg):
|
if is_project_dir(arg):
|
||||||
prj = Project(arg, False)
|
prj = Project(arg, False)
|
||||||
|
# don't exclude packages with state ' ' because the packages
|
||||||
if conf.config['do_package_tracking']:
|
# might have modified etc. files
|
||||||
prjpacs[prj] = []
|
prj_excl = [st for st in excl_states if st != ' ']
|
||||||
for pac in prj.pacs_have:
|
for st, pac in sorted(prj.get_status(*prj_excl), lambda x, y: cmp(x[1], y[1])):
|
||||||
# we cannot create package objects if the dir does not exist
|
p = prj.get_pacobj(pac)
|
||||||
if not pac in prj.pacs_broken:
|
if p is None:
|
||||||
prjpacs[prj].append(os.path.join(arg, pac))
|
# state is != ' '
|
||||||
else:
|
lines.append(statfrmt(st, os.path.normpath(os.path.join(prj.dir, pac))))
|
||||||
pacpaths += [arg + '/' + n for n in prj.pacs_have]
|
continue
|
||||||
elif is_package_dir(arg):
|
if st == ' ' and opts.verbose or st != ' ':
|
||||||
pacpaths.append(arg)
|
lines.append(statfrmt(st, os.path.normpath(os.path.join(prj.dir, pac))))
|
||||||
elif os.path.isfile(arg) or is_package_dir(os.path.dirname(arg)):
|
states = p.get_status(opts.show_excluded, *excl_states)
|
||||||
pacpaths.append(arg)
|
for st, filename in sorted(states, lambda x, y: cmp(x[1], y[1])):
|
||||||
|
lines.append(statfrmt(st, os.path.normpath(os.path.join(p.dir, filename))))
|
||||||
else:
|
else:
|
||||||
msg = '\'%s\' is neither a project or a package directory' % arg
|
p = findpacs([arg])[0]
|
||||||
raise oscerr.NoWorkingCopy, msg
|
for st, filename in sorted(p.get_status(opts.show_excluded, *excl_states), lambda x, y: cmp(x[1], y[1])):
|
||||||
lines = []
|
lines.append(statfrmt(st, os.path.normpath(os.path.join(p.dir, filename))))
|
||||||
# process single packages
|
# arrange the lines in order: unknown files first
|
||||||
lines = getStatus(findpacs(pacpaths), None, opts.verbose, opts.quiet, opts.show_excluded)
|
# filenames are already sorted
|
||||||
# process project dirs
|
lines = [l for l in lines if l[0] == '?'] + \
|
||||||
for prj, pacs in prjpacs.iteritems():
|
[l for l in lines if l[0] != '?']
|
||||||
lines += getStatus(findpacs(pacs), prj, opts.verbose, opts.quiet, opts.show_excluded)
|
print '\n'.join(lines)
|
||||||
if lines:
|
|
||||||
print '\n'.join(lines)
|
|
||||||
|
|
||||||
|
|
||||||
def do_add(self, subcmd, opts, *args):
|
def do_add(self, subcmd, opts, *args):
|
||||||
@ -3060,13 +3061,14 @@ Please submit there instead, or use --nodevelproject to force direct submission.
|
|||||||
# but first, produce status and diff to append to the template
|
# but first, produce status and diff to append to the template
|
||||||
footer = []
|
footer = []
|
||||||
lines = []
|
lines = []
|
||||||
for pac in pacs:
|
for p in pacs:
|
||||||
changed = getStatus([pac], quiet=True)
|
states = sorted(p.get_status(False, ' ', '?'), lambda x, y: cmp(x[1], y[1]))
|
||||||
|
changed = [statfrmt(st, os.path.normpath(os.path.join(p.dir, filename))) for st, filename in states]
|
||||||
if changed:
|
if changed:
|
||||||
footer += changed
|
footer += changed
|
||||||
footer.append('\nDiff for working copy: %s' % pac.dir)
|
footer.append('\nDiff for working copy: %s' % p.dir)
|
||||||
footer.extend([''.join(i) for i in pac.get_diff(ignoreUnversioned=True)])
|
footer.extend([''.join(i) for i in p.get_diff(ignoreUnversioned=True)])
|
||||||
lines.extend(get_commit_message_template(pac))
|
lines.extend(get_commit_message_template(p))
|
||||||
if template == None:
|
if template == None:
|
||||||
template='\n'.join(lines)
|
template='\n'.join(lines)
|
||||||
msg = ''
|
msg = ''
|
||||||
|
103
osc/core.py
103
osc/core.py
@ -494,6 +494,39 @@ class Project:
|
|||||||
pathname=getTransActPath(os.path.join(self.dir, pac)), \
|
pathname=getTransActPath(os.path.join(self.dir, pac)), \
|
||||||
prj_obj=self, prj_dir=self.dir, expand_link=expand_link, progress_obj=self.progress_obj)
|
prj_obj=self, prj_dir=self.dir, expand_link=expand_link, progress_obj=self.progress_obj)
|
||||||
|
|
||||||
|
def status(self, pac):
|
||||||
|
exists = os.path.exists(os.path.join(self.absdir, pac))
|
||||||
|
st = self.get_state(pac)
|
||||||
|
if st is None and exists:
|
||||||
|
return '?'
|
||||||
|
elif st is None:
|
||||||
|
raise oscerr.OscIOError(None, 'osc: \'%s\' is not under version control' % pac)
|
||||||
|
elif st in ('A', ' ') and not exists:
|
||||||
|
return '!'
|
||||||
|
elif st == 'D' and not exists:
|
||||||
|
return 'D'
|
||||||
|
else:
|
||||||
|
return st
|
||||||
|
|
||||||
|
def get_status(self, *exclude_states):
|
||||||
|
res = []
|
||||||
|
for pac in self.pacs_have:
|
||||||
|
st = self.status(pac)
|
||||||
|
if not st in exclude_states:
|
||||||
|
res.append((st, pac))
|
||||||
|
if not '?' in exclude_states:
|
||||||
|
res.extend([('?', pac) for pac in self.pacs_unvers])
|
||||||
|
return res
|
||||||
|
|
||||||
|
def get_pacobj(self, pac, *pac_args, **pac_kwargs):
|
||||||
|
try:
|
||||||
|
st = self.status(pac)
|
||||||
|
if st in ('?', '!') or st == 'D' and not os.path.exists(os.path.join(self.dir, pac)):
|
||||||
|
return None
|
||||||
|
return Package(os.path.join(self.dir, pac), *pac_args, **pac_kwargs)
|
||||||
|
except oscerr.OscIOError:
|
||||||
|
return None
|
||||||
|
|
||||||
def set_state(self, pac, state):
|
def set_state(self, pac, state):
|
||||||
node = self.get_package_node(pac)
|
node = self.get_package_node(pac)
|
||||||
if node == None:
|
if node == None:
|
||||||
@ -1475,6 +1508,22 @@ class Package:
|
|||||||
if i.name == n:
|
if i.name == n:
|
||||||
return i
|
return i
|
||||||
|
|
||||||
|
def get_status(self, excluded=False, *exclude_states):
|
||||||
|
global store
|
||||||
|
todo = self.todo
|
||||||
|
if not todo:
|
||||||
|
todo = self.filenamelist + self.to_be_added + \
|
||||||
|
[i for i in self.filenamelist_unvers if not os.path.isdir(os.path.join(self.absdir, i))]
|
||||||
|
if excluded:
|
||||||
|
todo.extend([i for i in self.excluded if i != store])
|
||||||
|
todo = set(todo)
|
||||||
|
res = []
|
||||||
|
for fname in sorted(todo):
|
||||||
|
st = self.status(fname)
|
||||||
|
if not st in exclude_states:
|
||||||
|
res.append((st, fname))
|
||||||
|
return res
|
||||||
|
|
||||||
def status(self, n):
|
def status(self, n):
|
||||||
"""
|
"""
|
||||||
status can be:
|
status can be:
|
||||||
@ -5447,60 +5496,6 @@ def getTransActPath(pac_dir):
|
|||||||
pathn = ''
|
pathn = ''
|
||||||
return pathn
|
return pathn
|
||||||
|
|
||||||
def getStatus(pacs, prj_obj=None, verbose=False, quiet=False, excluded=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
|
|
||||||
Package() objects in the pacs list have to belong to this project.
|
|
||||||
"""
|
|
||||||
global store
|
|
||||||
lines = []
|
|
||||||
if prj_obj:
|
|
||||||
if conf.config['do_package_tracking']:
|
|
||||||
for data in prj_obj.pacs_unvers:
|
|
||||||
lines.append(statfrmt('?', os.path.normpath(os.path.join(prj_obj.dir, data))))
|
|
||||||
for data in prj_obj.pacs_broken:
|
|
||||||
if prj_obj.get_state(data) == 'D':
|
|
||||||
lines.append(statfrmt('D', os.path.normpath(os.path.join(prj_obj.dir, data))))
|
|
||||||
else:
|
|
||||||
lines.append(statfrmt('!', os.path.normpath(os.path.join(prj_obj.dir, data))))
|
|
||||||
|
|
||||||
for p in pacs:
|
|
||||||
if not p.todo and excluded:
|
|
||||||
# all files + dirs in pwd (except .osc storedir)
|
|
||||||
p.todo = p.filenamelist + p.filenamelist_unvers + [i for i in p.excluded if i != store]
|
|
||||||
elif not p.todo:
|
|
||||||
# only files, no dirs and no excluded files
|
|
||||||
p.todo = p.filenamelist + [i for i in p.filenamelist_unvers if not os.path.isdir(i)]
|
|
||||||
p.todo.sort()
|
|
||||||
|
|
||||||
if prj_obj and conf.config['do_package_tracking']:
|
|
||||||
state = prj_obj.get_state(p.name)
|
|
||||||
if state != None and (state != ' ' or verbose):
|
|
||||||
lines.append(statfrmt(state, os.path.normpath(os.path.join(prj_obj.dir, p.name))))
|
|
||||||
|
|
||||||
for filename in p.todo:
|
|
||||||
# if filename.startswith('_service:'):
|
|
||||||
# continue
|
|
||||||
if filename in p.excluded and not excluded:
|
|
||||||
continue
|
|
||||||
# if filename in p.skipped:
|
|
||||||
# continue
|
|
||||||
s = p.status(filename)
|
|
||||||
if s == 'F':
|
|
||||||
lines.append(statfrmt('!', pathjoin(p.dir, filename)))
|
|
||||||
elif s != ' ' or (s == ' ' and verbose):
|
|
||||||
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
|
|
||||||
# filenames are already sorted
|
|
||||||
lines = [line for line in lines if line[0] == '?'] \
|
|
||||||
+ [line for line in lines if line[0] != '?']
|
|
||||||
return lines
|
|
||||||
|
|
||||||
def get_commit_message_template(pac):
|
def get_commit_message_template(pac):
|
||||||
"""
|
"""
|
||||||
Read the difference in .changes file(s) and put them as a template to commit message.
|
Read the difference in .changes file(s) and put them as a template to commit message.
|
||||||
|
Loading…
Reference in New Issue
Block a user