Make text wrapping off by default in tty, add a kwarg for it.

This commit is contained in:
Todd Gamblin 2016-01-14 10:26:31 -08:00
parent b02faf5641
commit 05b30bf83e
3 changed files with 60 additions and 21 deletions

View File

@ -63,35 +63,46 @@ def msg(message, *args):
def info(message, *args, **kwargs):
format = kwargs.get('format', '*b')
stream = kwargs.get('stream', sys.stdout)
wrap = kwargs.get('wrap', False)
cprint("@%s{==>} %s" % (format, cescape(str(message))), stream=stream)
for arg in args:
lines = textwrap.wrap(
str(arg), initial_indent=indent, subsequent_indent=indent)
for line in lines:
stream.write(line + '\n')
if wrap:
lines = textwrap.wrap(
str(arg), initial_indent=indent, subsequent_indent=indent)
for line in lines:
stream.write(line + '\n')
else:
stream.write(indent + str(arg) + '\n')
def verbose(message, *args):
def verbose(message, *args, **kwargs):
if _verbose:
info(message, *args, format='c')
kwargs.setdefault('format', 'c')
info(message, *args, **kwargs)
def debug(message, *args):
def debug(message, *args, **kwargs):
if _debug:
info(message, *args, format='g', stream=sys.stderr)
kwargs.setdefault('format', 'g')
kwargs.setdefault('stream', sys.stderr)
info(message, *args, **kwargs)
def error(message, *args):
info("Error: " + str(message), *args, format='*r', stream=sys.stderr)
def error(message, *args, **kwargs):
kwargs.setdefault('format', '*r')
kwargs.setdefault('stream', sys.stderr)
info("Error: " + str(message), *args, **kwargs)
def warn(message, *args):
info("Warning: " + str(message), *args, format='*Y', stream=sys.stderr)
def warn(message, *args, **kwargs):
kwargs.setdefault('format', '*Y')
kwargs.setdefault('stream', sys.stderr)
info("Warning: " + str(message), *args, **kwargs)
def die(message, *args):
error(message, *args)
def die(message, *args, **kwargs):
error(message, *args, **kwargs)
sys.exit(1)

View File

@ -135,8 +135,34 @@
import spack.util.spack_yaml as syaml
"""Dict from section names -> function to check section YAML format."""
valid_sections = ['compilers', 'mirrors', 'repos']
"""Dict from section names -> schema for that section."""
section_schemas = {
'compilers' : {
'$schema': 'http://json-schema.org/schema#',
'title' : 'Spack compiler configuration file schema',
'type' : 'object',
'properties' : {
'compilers' : {
'type' : 'map',
},
},
},
'mirrors' : {
'$schema': 'http://json-schema.org/schema#',
'title' : 'Spack mirror configuration file schema',
'type' : 'map',
'properties' : {
'mirrors' : {
}
},
},
'repos' : {
'$schema': 'http://json-schema.org/schema#',
'title' : 'Spack repository configuration file schema',
}}
"""OrderedDict of config scopes keyed by name.
Later scopes will override earlier scopes.
@ -146,9 +172,9 @@
def validate_section(section):
"""Raise a ValueError if the section is not a valid section."""
if section not in valid_sections:
if section not in section_schemas:
raise ValueError("Invalid config section: '%s'. Options are %s."
% (section, valid_sections))
% (section, section_schemas))
class ConfigScope(object):
@ -369,10 +395,12 @@ def update_config(section, update_data, scope=None):
scope.write_section(section)
"""Print a configuration to stdout"""
def print_section(section):
"""Print a configuration to stdout."""
try:
yaml.dump(get_config(section), stream=sys.stdout, default_flow_style=False)
data = syaml.syaml_dict()
data[section] = get_config(section)
syaml.dump(data, stream=sys.stdout, default_flow_style=False)
except (yaml.YAMLError, IOError) as e:
raise ConfigError("Error reading configuration: %s" % section)

View File

@ -858,7 +858,7 @@ def cleanup():
tty.warn("Keeping install prefix in place despite error.",
"Spack will think this package is installed." +
"Manually remove this directory to fix:",
self.prefix)
self.prefix, wrap=True)
def real_work():