Esempio n. 1
0
def main(path):
    schema_decl = (
        # path, type, subschema
        ('changed', bool),
        ('code-remote', str),
        ('source', str),
        ('explorer', dict, (
            ('state', str),
        )),
        ('parameter', dict, (
            ('state', str),
        )),
        ('state', str),
        ('tags', dict, (
            ('exclude', list),
            ('include', list),
            ('only', list),
        )),
    )

    schema = cconfig.Schema(schema_decl)
    obj = cconfig.from_schema(schema)
    print(obj)
    obj['changed'] = True
    obj['tags'] = {'exclude': ['a', 'b'], 'include': set(('c', 'd')), 'only': ('x', 'y')}
    print('changed: ', obj['changed'])
    print('state: ', obj['state'])
    print('parameter[\'state\']: ', obj['parameter']['state'])
    print('explorer[\'state\']: ', obj['explorer']['state'])
    print(obj)
    import tempfile
    tmpdir = tempfile.mkdtemp()
    print('tmpdir: ', tmpdir)
    cconfig.to_dir(tmpdir, obj, schema=schema)
Esempio n. 2
0
def main():
    schema_decl = (
        # path, type, subschema
        ("changed", bool),
        ("code-remote", str),
        ("source", str),
        ("explorer", dict, (("state", str),)),
        ("parameter", dict, (("state", str),)),
        ("state", str),
    )

    schema = cconfig.Schema(schema_decl)
    d = cconfig.from_schema(schema)
    print(d)
    # set some properties
    d["changed"] = True
    d["code-remote"] = "whatever"
    d["source"] = "/path/to/source"
    d["explorer"] = {"state": "absent"}
    d["parameter"] = {"state": "present"}
    d["state"] = "done"

    import tempfile

    path = tempfile.mkdtemp()
    print("path: ", path)
    obj = cconfig.bind(d, path, schema=schema)
    print(obj)
    # implicit load/sync with context manager
    with obj as _o:
        print(_o)
        _o["state"] = "not-like-before"
        _o.save()
    print(obj)
Esempio n. 3
0
def main_(path):
    schema_decl = (
        # path, type, subschema
        ('changed', bool),
        ('code-remote', str),
        ('source', str),
        ('explorer', dict, (
            ('state', str),
        )),
        ('parameter', dict, (
            ('state', str),
        )),
        ('state', str),
    )

    schema = cconfig.Schema(schema_decl)
    obj = cconfig.from_schema(schema)
    print(obj)
    obj['changed'] = True
    print('changed: ', obj['changed'])
    print('state: ', obj['state'])
    print('parameter[\'state\']: ', obj['parameter']['state'])
    print('explorer[\'state\']: ', obj['explorer']['state'])
    print(obj)
    import tempfile
    tmpdir = tempfile.mkdtemp()
    print('tmpdir: ', tmpdir)
    cconfig.to_dir(tmpdir, obj, schema=schema)
Esempio n. 4
0
def main():
    schema_decl = (
        # path, type, subschema
        ('conf', 'mapping', (
            ('explorer', str),
            ('file', str),
            ('manifest', str),
            ('transport', str),
            ('type', str),
        )),
        ('explorer', dict, (
            ('state', str),
        )),
    )

    schema = cconfig.Schema(schema_decl)
    obj = cconfig.from_schema(schema)
    pprint.pprint(obj)