Skip to content

Commit

Permalink
sage --package properties: Add option --format, change default to 'pl…
Browse files Browse the repository at this point in the history
…ain'
  • Loading branch information
mkoeppe committed Jan 14, 2024
1 parent eadb3d5 commit 3e5c66b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
10 changes: 8 additions & 2 deletions build/sage_bootstrap/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ def list_cls(self, *package_classes, **filters):
for pkg_name in pc.names:
print(pkg_name)

def properties(self, *package_classes, props=['path', 'version_with_patchlevel', 'type', 'source', 'trees']):
def properties(self, *package_classes, props=['path', 'version_with_patchlevel', 'type', 'source', 'trees'],
format='plain'):
"""
Show the properties of given packages
Expand All @@ -92,14 +93,19 @@ def properties(self, *package_classes, props=['path', 'version_with_patchlevel',
pc = PackageClass(*package_classes)
for package_name in pc.names:
package = Package(package_name)
if format == 'plain':
print("{0}:".format(package_name))
for p in props:
value = getattr(package, p)
if value is None:
if p.startswith('version'):
value = 'none'
else:
value = ''
print("{0}_{1}='{2}'".format(p, package_name, value))
if format == 'plain':
print(" {0:28} {1}".format(p + ":", value))
else:
print("{0}_{1}='{2}'".format(p, package_name, value))

def name(self, tarball_filename):
"""
Expand Down
5 changes: 4 additions & 1 deletion build/sage_bootstrap/cmdline.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,9 @@ def make_parser():
type=str, nargs='+',
help=('package name or designator for all packages of a given type '
'(one of :all:, :standard:, :optional:, and :experimental:)'))
parser_properties.add_argument(
'--format', type=str, default='plain',
help='output format (one of plain and shell; default: plain)')

parser_name = subparsers.add_parser(
'name', epilog=epilog_name,
Expand Down Expand Up @@ -427,7 +430,7 @@ def run():
include_dependencies=args.include_dependencies,
exclude_dependencies=args.exclude_dependencies)
elif args.subcommand == 'properties':
app.properties(*args.package_class)
app.properties(*args.package_class, format=args.format)
elif args.subcommand == 'name':
app.name(args.tarball_filename)
elif args.subcommand == 'tarball':
Expand Down

0 comments on commit 3e5c66b

Please sign in to comment.