1
0
mirror of https://github.com/openSUSE/osc.git synced 2025-08-22 06:28:53 +02:00

smarter ls -b

- list all repos/archs if not specified
- use project or package of the current dir if none specified
This commit is contained in:
Ludwig Nussel
2009-11-17 13:39:46 +00:00
parent 11c22ac9c1
commit 4139db3e3d
2 changed files with 60 additions and 20 deletions

View File

@@ -200,8 +200,9 @@ class Osc(cmdln.Cmdln):
"""${cmd_name}: List existing content on the server """${cmd_name}: List existing content on the server
This command is used to list sources, or binaries (when used with the This command is used to list sources, or binaries (when used with the
--binaries option). To use the --binary option, --repo and --arch are --binaries option). When using the --binary option, --repo
also required. and --arch can be used to limit output to specific repos
and/or architectures.
Examples: Examples:
ls # list all projects ls # list all projects
@@ -224,6 +225,7 @@ class Osc(cmdln.Cmdln):
${cmd_option_list} ${cmd_option_list}
""" """
apiurl = conf.config['apiurl']
args = slash_split(args) args = slash_split(args)
if subcmd == 'll': if subcmd == 'll':
opts.verbose = True opts.verbose = True
@@ -231,8 +233,11 @@ class Osc(cmdln.Cmdln):
opts.verbose = True opts.verbose = True
opts.expand = True opts.expand = True
project = None
package = None
if len(args) == 1: if len(args) == 1:
project = args[0] project = args[0]
package = None
elif len(args) == 2 or len(args) == 3: elif len(args) == 2 or len(args) == 3:
project = args[0] project = args[0]
package = args[1] package = args[1]
@@ -242,32 +247,59 @@ class Osc(cmdln.Cmdln):
elif len(args) > 3: elif len(args) > 3:
raise oscerr.WrongArgs('Too many arguments') raise oscerr.WrongArgs('Too many arguments')
if opts.binaries and (not opts.repo or not opts.arch):
raise oscerr.WrongOptions('Sorry, -r <repo> -a <arch> missing\n'
'You can list repositories with: \'osc repositories <project>\'')
if opts.binaries and opts.expand: if opts.binaries and opts.expand:
raise oscerr.WrongOptions('Sorry, --binaries and --expand are mutual exclusive.') raise oscerr.WrongOptions('Sorry, --binaries and --expand are mutual exclusive.')
# list binaries # list binaries
if opts.binaries: if opts.binaries:
if not args: # ls -b toplevel doesn't make sense, so use info from
# current dir if available
if len(args) == 0:
dir = os.getcwd()
if is_project_dir(dir):
project = store_read_project(dir)
apiurl = store_read_apiurl(dir)
elif is_package_dir(dir):
project = store_read_project(dir)
package = store_read_package(dir)
apiurl = store_read_apiurl(dir)
if not project:
raise oscerr.WrongArgs('There are no binaries to list above project level.') raise oscerr.WrongArgs('There are no binaries to list above project level.')
if opts.revision: if opts.revision:
raise oscerr.WrongOptions('Sorry, the --revision option is not supported for binaries.') raise oscerr.WrongOptions('Sorry, the --revision option is not supported for binaries.')
r = None repos = []
if len(args) == 1: if opts.repo and opts.arch:
r = get_binarylist(conf.config['apiurl'], project, opts.repo, opts.arch, verbose=opts.verbose) repos.append(Repo(opts.repo, opts.arch))
elif opts.repo and not opts.arch:
elif len(args) == 2: for repo in get_repos_of_project(apiurl, project):
r = get_binarylist(conf.config['apiurl'], project, opts.repo, opts.arch, package=package, verbose=opts.verbose) if repo.name == opts.repo:
repos.append(repo)
if opts.verbose: elif opts.arch and not opts.repo:
for f in r: for repo in get_repos_of_project(apiurl, project):
print "%9d %s %-40s" % (f.size, shorttime(f.mtime), f.name) if repo.arch == opts.arch:
repos.append(repo)
else: else:
print '\n'.join(r) repos = get_repos_of_project(apiurl, project)
results = []
for repo in repos:
results.append((repo, get_binarylist(apiurl, project, repo.name, repo.arch, package=package, verbose=opts.verbose)))
for result in results:
indent = ''
if len(results) > 1:
print '%s/%s' % (result[0].name, result[0].arch)
indent = ' '
if opts.verbose:
for f in result[1]:
print "%9d %s %-40s" % (f.size, shorttime(f.mtime), f.name)
else:
for f in result[1]:
print indent+f
# list sources # list sources
elif not opts.binaries: elif not opts.binaries:

View File

@@ -3234,15 +3234,23 @@ def get_repositories_of_project(apiurl, prj):
return r return r
class Repo:
repo_line_templ = '%-15s %-10s'
def __init__(self, name, arch):
self.name = name
self.arch = arch
def __str__(self):
return self.repo_line_templ % (self.name, self.arch)
def get_repos_of_project(apiurl, prj): def get_repos_of_project(apiurl, prj):
f = show_project_meta(apiurl, prj) f = show_project_meta(apiurl, prj)
tree = ET.parse(StringIO(''.join(f))) tree = ET.parse(StringIO(''.join(f)))
repo_line_templ = '%-15s %-10s'
for node in tree.findall('repository'): for node in tree.findall('repository'):
for node2 in node.findall('arch'): for node2 in node.findall('arch'):
yield repo_line_templ % (node.get('name'), node2.text) yield Repo(node.get('name'), node2.text)
def get_binarylist(apiurl, prj, repo, arch, package=None, verbose=False): def get_binarylist(apiurl, prj, repo, arch, package=None, verbose=False):
what = package or '_repository' what = package or '_repository'