From 05b30bf83e0bc8723472b6d609c692c3b83b486c Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Thu, 14 Jan 2016 10:26:31 -0800 Subject: Make text wrapping off by default in tty, add a kwarg for it. --- lib/spack/llnl/util/tty/__init__.py | 39 +++++++++++++++++++++++------------- lib/spack/spack/config.py | 40 +++++++++++++++++++++++++++++++------ lib/spack/spack/package.py | 2 +- 3 files changed, 60 insertions(+), 21 deletions(-) (limited to 'lib') diff --git a/lib/spack/llnl/util/tty/__init__.py b/lib/spack/llnl/util/tty/__init__.py index 203f429a48..3ecd3a4ac2 100644 --- a/lib/spack/llnl/util/tty/__init__.py +++ b/lib/spack/llnl/util/tty/__init__.py @@ -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) diff --git a/lib/spack/spack/config.py b/lib/spack/spack/config.py index c53dcbc405..3ff83ae529 100644 --- a/lib/spack/spack/config.py +++ b/lib/spack/spack/config.py @@ -135,8 +135,34 @@ from spack.error import SpackError 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 @@ config_scopes = OrderedDict() 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) diff --git a/lib/spack/spack/package.py b/lib/spack/spack/package.py index 5db83064b5..f926a14206 100644 --- a/lib/spack/spack/package.py +++ b/lib/spack/spack/package.py @@ -858,7 +858,7 @@ class Package(object): 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(): -- cgit v1.2.3-60-g2f50