Allow widths in spec format strings.
This commit is contained in:
parent
703e611043
commit
3607c26439
2 changed files with 30 additions and 9 deletions
|
@ -98,5 +98,9 @@ def hasher():
|
||||||
for spec in specs:
|
for spec in specs:
|
||||||
print spec.tree(indent=4, format='$_$@$+', color=True),
|
print spec.tree(indent=4, format='$_$@$+', color=True),
|
||||||
else:
|
else:
|
||||||
for abbrv in abbreviated:
|
max_len = max([len(s.name) for s in specs])
|
||||||
print " %s" % abbrv
|
max_len += 4
|
||||||
|
|
||||||
|
for spec in specs:
|
||||||
|
format = '$-' + str(max_len) + '_$@$+$#'
|
||||||
|
print " " + spec.format(format, color=True)
|
||||||
|
|
|
@ -1015,6 +1015,10 @@ def format(self, format_string='$_$@$%@$+$=', **kwargs):
|
||||||
$# Dependencies' 8-char sha1 prefix
|
$# Dependencies' 8-char sha1 prefix
|
||||||
$$ $
|
$$ $
|
||||||
|
|
||||||
|
Optionally you can provide a width, e.g. $20_ for a 20-wide name.
|
||||||
|
Like printf, you can provide '-' for left justification, e.g.
|
||||||
|
$-20_ for a left-justified name.
|
||||||
|
|
||||||
Anything else is copied verbatim into the output stream.
|
Anything else is copied verbatim into the output stream.
|
||||||
|
|
||||||
*Example:* ``$_$@$+`` translates to the name, version, and options
|
*Example:* ``$_$@$+`` translates to the name, version, and options
|
||||||
|
@ -1035,27 +1039,40 @@ def write(s, c):
|
||||||
else:
|
else:
|
||||||
out.write(s)
|
out.write(s)
|
||||||
|
|
||||||
for i, c in enumerate(format_string):
|
iterator = enumerate(format_string)
|
||||||
|
for i, c in iterator:
|
||||||
if escape:
|
if escape:
|
||||||
|
fmt = '%'
|
||||||
|
if c == '-':
|
||||||
|
fmt += c
|
||||||
|
i, c = next(iterator)
|
||||||
|
|
||||||
|
while c in '0123456789':
|
||||||
|
fmt += c
|
||||||
|
i, c = next(iterator)
|
||||||
|
fmt += 's'
|
||||||
|
|
||||||
if c == '_':
|
if c == '_':
|
||||||
out.write(self.name)
|
out.write(fmt % self.name)
|
||||||
elif c == '@':
|
elif c == '@':
|
||||||
if self.versions and self.versions != _any_version:
|
if self.versions and self.versions != _any_version:
|
||||||
write(c + str(self.versions), c)
|
write(fmt % (c + str(self.versions)), c)
|
||||||
elif c == '%':
|
elif c == '%':
|
||||||
if self.compiler:
|
if self.compiler:
|
||||||
write(c + str(self.compiler.name), c)
|
write(fmt % (c + str(self.compiler.name)), c)
|
||||||
compiler = True
|
compiler = True
|
||||||
elif c == '+':
|
elif c == '+':
|
||||||
if self.variants:
|
if self.variants:
|
||||||
write(str(self.variants), c)
|
write(fmt % str(self.variants), c)
|
||||||
elif c == '=':
|
elif c == '=':
|
||||||
if self.architecture:
|
if self.architecture:
|
||||||
write(c + str(self.architecture), c)
|
write(fmt % (c + str(self.architecture)), c)
|
||||||
elif c == '#':
|
elif c == '#':
|
||||||
if self.dependencies:
|
if self.dependencies:
|
||||||
out.write('-' + self.dep_hash(8))
|
out.write(fmt % ('-' + self.dep_hash(8)))
|
||||||
elif c == '$':
|
elif c == '$':
|
||||||
|
if fmt != '':
|
||||||
|
raise ValueError("Can't use format width with $$.")
|
||||||
out.write('$')
|
out.write('$')
|
||||||
escape = False
|
escape = False
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue