diff options
| author | Joseph Hunkeler <jhunkeler@gmail.com> | 2015-06-20 17:24:18 -0400 | 
|---|---|---|
| committer | Joseph Hunkeler <jhunkeler@gmail.com> | 2015-06-20 17:24:18 -0400 | 
| commit | cf88b55c7d978943af005c327dd3ee8cd6d79a95 (patch) | |
| tree | 6ed5c52cb4e27b0a27e97087a4feb38b971e1492 | |
| download | cbc-cf88b55c7d978943af005c327dd3ee8cd6d79a95.tar.gz | |
Initial commit
| -rw-r--r-- | .gitignore | 2 | ||||
| -rw-r--r-- | cbc/__init__.py | 0 | ||||
| -rw-r--r-- | cbc/parser.py | 48 | 
3 files changed, 50 insertions, 0 deletions
| diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7849784 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.pyc +*.DS_Store diff --git a/cbc/__init__.py b/cbc/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/cbc/__init__.py diff --git a/cbc/parser.py b/cbc/parser.py new file mode 100644 index 0000000..f38532f --- /dev/null +++ b/cbc/parser.py @@ -0,0 +1,48 @@ +'''I refuse to write the same thing over and over again in meta.yaml. +And yeah, conda supports Jinja2, but ugh... No. +''' + +import os +import conda_build +import conda_build.metadata + +import configparser +from configparser import ConfigParser, ExtendedInterpolation +from pprint import pprint +import yaml + +def convert_conda_fields(fields): +    temp = {} +    for fkey, fval in fields.items(): +        temp[fkey] = { x: '' for x in fval} +            #fields[field] = dict(value) +    return temp + + +class Specfile(object): +    def __init__(self, filename): +        if not os.path.exists(filename): +            print('"{0}" does not exist.'.format(filename)); +            return +             +        self.filename = filename +        fields = convert_conda_fields(conda_build.metadata.FIELDS) +         +        config = ConfigParser(interpolation=ExtendedInterpolation(), allow_no_value=True) +        config.read_dict(fields) +        config.read(self.filename) +         +        with open('../../test.ini.out', 'w+') as testfile: +            config.write(testfile) +         +        y = yaml.load(fields) +        md = conda_build.metadata.MetaData() +         +        #for section in config.sections(): +        #    for sub in config[section]: +        #        print('{0}:{1}:{2}'.format(section, sub, config[section][sub])) + +if __name__ == '__main__': +    spec = Specfile('../../test.spec') +    #pprint() +    
\ No newline at end of file | 
