def test_patch_complex(): c = ConfigDict({ "a": 1, "b": { "x": 3, "y": 4 }, "c": { "x": 5, "y": 6 }, "d": { "x": 7, "y": 8 } }) d = {"a": 2, "b": {"z": 5}, "c": [1, 2], "d": {"y": 9}} c.patch(d) assert c.a == 2 assert c.b.x == 3 assert c.b.y == 4 assert c.b.z == 5 assert c.c == [1, 2] assert c.d.x == 7 assert c.d.y == 9
def read(text): if isinstance(text, File): text = text.read_all() t = env.from_string(text) data = yaml.load(t.render(context or dict())) conf = ConfigDict(data) if 'patches' in conf and patchable: leaf = conf parent = leaf['patches'] del leaf['patches'] parent = File(f.parent.child(parent)) conf = read(parent) conf.patch(leaf) return conf
def test_patch_complex(): c = ConfigDict({ "a": 1, "b": {"x": 3, "y": 4}, "c": {"x": 5, "y": 6}, "d": {"x": 7, "y": 8} }) d = {"a": 2, "b": {"z": 5}, "c": [1, 2], "d": {"y": 9}} c.patch(d) assert c.a == 2 assert c.b.x == 3 assert c.b.y == 4 assert c.b.z == 5 assert c.c == [1, 2] assert c.d.x == 7 assert c.d.y == 9
def _load(cls, project_name, env='build', context=None, conf_path=None): if project_name in __PROJECTS__: return __PROJECTS__[project_name] settings = __ENV__.get(env, None) if not settings: file_name = env + '.yaml' if conf_path: file_name = Folder(conf_path).child(file_name) settings = yinja.load(file_name, context=context) __ENV__[env] = settings config = ConfigDict() config.update(settings.config) config.patch(settings.projects.get(project_name, dict())) project_type = config.get('type_name', 'gitbot.lib.build.Project') project_class = load_python_object(project_type) project = project_class(project_name, config, env, settings, context, conf_path) __PROJECTS__[project_name] = project return project
def publish_stack(config, params=None, debug=False, wait=False, **kwargs): if isinstance(config, File): file_path = config.path config = yaml.load(config.read_all()) config["file_path"] = file_path uploaded = upload_stack(config, **kwargs) config = uploaded.config main_stack = _get_main_stack(uploaded.config, uploaded.files) try: main = uploaded.result[main_stack] except KeyError: raise Exception("Cannot find the main stack[{main}]".format(main=main_stack)) try: stack_name = config.publish.stack_name except AttributeError: raise Exception("Stack name is required in configuration[publish.stack_name].") defaults = get_params(config) args = ConfigDict({name: info["value"] for name, info in defaults.iteritems()}) args.patch(params) params = args region = config.publish.get("region", "us-east-1") # Connect to cloud formation and create the stack cf = connect_cf(region, **kwargs) try: cf.describe_stacks(stack_name) update = True except: update = False params = _transform_params(config.flatten(), params, uploaded.result) fn = cf.update_stack if update else cf.create_stack try: fn( stack_name, disable_rollback=debug, capabilities=["CAPABILITY_IAM"], template_url=main["url"], parameters=params, ) except BotoServerError as bse: try: error = json.loads(bse.error_message) except: raise bse try: message = error["Error"]["Message"] except KeyError: raise bse if message == "No updates are to be performed.": print "Stack is already up to date." wait = False else: raise bse if wait: __wait_while_status(cf, "CREATE_IN_PROGRESS" if not update else "UPDATE_IN_PROGRESS") return stack_name
def test_patch_simple(): c = ConfigDict({"a": 1, "b": {"c": 3, "e": 4}}) d = {"b": {"e": 5}} c.patch(d) assert c.b.c == 3 assert c.b.e == 5