diff options
| author | Joseph Hunkeler <jhunkeler@gmail.com> | 2015-06-22 17:49:19 -0400 | 
|---|---|---|
| committer | Joseph Hunkeler <jhunkeler@gmail.com> | 2015-06-22 17:49:19 -0400 | 
| commit | f089b80df814e94a43db60d77d9f1a2e79428238 (patch) | |
| tree | f19f8cca8c753de7bd0ea1ea15a6d952ed2e4663 /cbc | |
| parent | 3bdc5103ae2b845e9c83a789b5781ee4ee979d7c (diff) | |
| download | cbc-f089b80df814e94a43db60d77d9f1a2e79428238.tar.gz | |
Minor cleanups and error handling
Diffstat (limited to 'cbc')
| -rw-r--r-- | cbc/meta.py | 38 | 
1 files changed, 25 insertions, 13 deletions
diff --git a/cbc/meta.py b/cbc/meta.py index fb36c57..da6ce3b 100644 --- a/cbc/meta.py +++ b/cbc/meta.py @@ -7,34 +7,46 @@ import conda_build.metadata  import yaml  from configparser import SafeConfigParser, ExtendedInterpolation  from collections import OrderedDict +from .environment import Environment +class SpecError(Exception): +    pass  class Spec(object):      def __init__(self, filename, env): +                  if not os.path.exists(filename): -            print('"{0}" does not exist.'.format(filename)); -            return +            raise OSError('"{0}" does not exist.'.format(filename)); -        self.keywords = ['build_ext', 'cgi']          self.filename = filename -        self.fields = self.convert_conda_fields(conda_build.metadata.FIELDS) -        config = SafeConfigParser(interpolation=ExtendedInterpolation(), allow_no_value=True) +        if not isinstance(env, Environment): +            raise SpecError('Expecting instance of cbc.environment.Environment, got: "{0}"'.format(type(env))) +         +        self.env = env +        self.keywords = ['build_ext', 'cgi'] +         +        self.fields = self.convert_conda_fields(conda_build.metadata.FIELDS) +        self.config = SafeConfigParser(interpolation=ExtendedInterpolation(), allow_no_value=True)          # Include built-in Conda metadata fields -        config.read_dict(self.fields) - +        self.config.read_dict(self.fields)          # Include user-defined build fields -        config.read(self.filename) - +        self.config.read(self.filename)          # Convert ConfigParser -> dict -        spec = self.as_dict(config) +        self.spec = self.as_dict(self.config) +         +        self.spec_metadata = {} +        for keyword in self.keywords: +            if self.spec[keyword]: +                self.spec_metadata[keyword] = self.spec[keyword]            # Convert dict to YAML-compatible dict -        metadata = self.scrub(spec, self.keywords) +        self.conda_metadata = self.scrub(self.spec, self.keywords) -        with open(os.path.join(env.config['meta']), 'w+') as metafile: -            yaml.safe_dump(metadata, metafile, default_flow_style=False, line_break=True, indent=4) +    def conda_write_meta(self): +        with open(os.path.join(self.env.config['meta']), 'w+') as metafile: +            yaml.safe_dump(self.conda_metadata, metafile, default_flow_style=False, line_break=True, indent=4)      def convert_conda_fields(self, fields):          temp = OrderedDict()  | 
