def update_modules(to_build, cfg): """ Updates modules to be built with the passed-in config. Updating each individual module section will propogate the changes to STATUS as well (as the references are the same). Note that we have to apply overrides in a specific order - 1) reset the modules being built to the defaults 2) set any modules selected for build as build = True 3) reset configs using config_collection_for_built 4) apply config overrides """ global STATUS selected = set(to_build) for module_id in shutit.cfg: if module_id in ORIG_MOD_CFG and 'shutit.core.module.build' in ORIG_MOD_CFG[ module_id]: shutit.cfg[module_id]['shutit.core.module.build'] = ORIG_MOD_CFG[ module_id]['shutit.core.module.build'] if module_id in selected: shutit.cfg[module_id]['shutit.core.module.build'] = True if cfg is not None: sec, key, val = cfg ORIG_MOD_CFG[sec][key] = val for module_id in ORIG_MOD_CFG: for cfgkey in ORIG_MOD_CFG[module_id]: if cfgkey == 'shutit.core.module.build': continue shutit.cfg[module_id][cfgkey] = ORIG_MOD_CFG[module_id][cfgkey] errs = [] errs.extend(shutit_main.check_deps(shutit)) # There is a complexity here in that module configs may depend on # configs from other modules (!). We assume this won't happen as we # would have to override each module at the correct time. shutit_main.config_collection_for_built(shutit) errs.extend(shutit_main.check_conflicts(shutit)) # Cache first errs.extend(shutit_main.check_ready(shutit, throw_error=False)) errs.extend(shutit_main.check_ready(shutit)) STATUS['errs'] = [err[0] for err in errs] STATUS['modules'] = [{ "module_id": module_id, "description": shutit.shutit_map[module_id].description, "run_order": float(shutit.shutit_map[module_id].run_order), "build": shutit.cfg[module_id]['shutit.core.module.build'], "selected": module_id in selected } for module_id in shutit_main.allowed_module_ids(shutit)]
def update_modules(to_build, cfg): """ Updates modules to be built with the passed-in config. Updating each individual module section will propogate the changes to STATUS as well (as the references are the same). Note that we have to apply overrides in a specific order - 1) reset the modules being built to the defaults 2) set any modules selected for build as build = True 3) reset configs using config_collection_for_built 4) apply config overrides """ global STATUS selected = set(to_build) for mid in shutit.cfg: if mid in orig_mod_cfg and "build" in orig_mod_cfg[mid]: shutit.cfg[mid]["build"] = orig_mod_cfg[mid]["build"] if mid in selected: shutit.cfg[mid]["build"] = True # There is a complexity here in that module configs may depend on # configs from other modules (!). We assume this won't happen as we # would have to override each module at the correct time. shutit_main.config_collection_for_built(shutit) if cfg is not None: sec, key, val = cfg orig_mod_cfg[sec][key] = val for mid in orig_mod_cfg: for cfgkey in orig_mod_cfg[mid]: if cfgkey == "build": continue shutit.cfg[mid][cfgkey] = orig_mod_cfg[mid][cfgkey] errs = [] errs.extend(shutit_main.check_deps(shutit)) errs.extend(shutit_main.check_conflicts(shutit)) errs.extend(shutit_main.check_ready(shutit)) # TODO: display an error if (selected and not build) STATUS["errs"] = [err[0] for err in errs] STATUS["modules"] = [ { "module_id": mid, "description": shutit.shutit_map[mid].description, "run_order": float(shutit.shutit_map[mid].run_order), "build": shutit.cfg[mid]["build"], "selected": mid in selected, } for mid in shutit_main.module_ids(shutit) ]
def update_modules(to_build, cfg): """ Updates modules to be built with the passed-in config. Updating each individual module section will propogate the changes to STATUS as well (as the references are the same). Note that we have to apply overrides in a specific order - 1) reset the modules being built to the defaults 2) set any modules selected for build as build = True 3) reset configs using config_collection_for_built 4) apply config overrides """ global STATUS selected = set(to_build) for module_id in shutit.cfg: if module_id in ORIG_MOD_CFG and 'shutit.core.module.build' in ORIG_MOD_CFG[module_id]: shutit.cfg[module_id]['shutit.core.module.build'] = ORIG_MOD_CFG[module_id]['shutit.core.module.build'] if module_id in selected: shutit.cfg[module_id]['shutit.core.module.build'] = True if cfg is not None: sec, key, val = cfg ORIG_MOD_CFG[sec][key] = val for module_id in ORIG_MOD_CFG: for cfgkey in ORIG_MOD_CFG[module_id]: if cfgkey == 'shutit.core.module.build': continue shutit.cfg[module_id][cfgkey] = ORIG_MOD_CFG[module_id][cfgkey] errs = [] errs.extend(shutit_main.check_deps(shutit)) # There is a complexity here in that module configs may depend on # configs from other modules (!). We assume this won't happen as we # would have to override each module at the correct time. shutit_main.config_collection_for_built(shutit) errs.extend(shutit_main.check_conflicts(shutit)) # Cache first errs.extend(shutit_main.check_ready(shutit, throw_error=False)) errs.extend(shutit_main.check_ready(shutit)) STATUS['errs'] = [err[0] for err in errs] STATUS['modules'] = [ { "module_id": module_id, "description": shutit.shutit_map[module_id].description, "run_order": float(shutit.shutit_map[module_id].run_order), "build": shutit.cfg[module_id]['shutit.core.module.build'], "selected": module_id in selected } for module_id in shutit_main.allowed_module_ids(shutit) ]
def reset_thread(): global ORIG_MOD_CFG global shutit # Start with a fresh shutit object shutit = shutit_global.shutit = shutit_global.init() # This has already happened but we have to do it again on top of our new # shutit object shutit_util.parse_args(shutit) shutit.cfg['build']['interactive'] = 0 # The rest of the loading from shutit_main shutit_util.load_configs(shutit) shutit_util.load_mod_from_file( shutit, os.path.join(shutit.shutit_main_dir, 'shutit_setup.py')) shutit_util.load_shutit_modules(shutit) shutit_main.init_shutit_map(shutit) shutit_main.config_collection(shutit) # Here we can set the starting image. if STATUS['image_tag'] != '': shutit.cfg['target']['docker_image'] = STATUS['image_tag'] else: STATUS['image_tag'] = shutit.cfg['target']['docker_image'] shutit_main.conn_target(shutit) shutit_main.config_collection_for_built(shutit) # Some hacks for server mode shutit.cfg['build']['build_log_file'] = StringIO.StringIO() shutit.cfg['build']['interactive'] = 0 STATUS['cid'] = shutit.cfg['target']['container_id'] for module_id in shutit.shutit_map: ORIG_MOD_CFG[module_id] = STATUS['cfg'][module_id] = shutit.cfg[ module_id] # Add in core sections for module_id in ['repository', 'target']: ORIG_MOD_CFG[module_id] = STATUS['cfg'][module_id] = shutit.cfg[ module_id] # Make sure that ORIG_MOD_CFG can be updated seperately to # STATUS and shutit.cfg (which remain linked), as it will hold # our overrides ORIG_MOD_CFG = copy.deepcopy(ORIG_MOD_CFG) update_modules([], None) STATUS['resetting'] = False
def reset_thread(): global ORIG_MOD_CFG global shutit # Start with a fresh shutit object shutit = shutit_global.shutit = shutit_global.init() # This has already happened but we have to do it again on top of our new # shutit object util.parse_args(shutit) shutit.cfg['build']['interactive'] = 0 # The rest of the loading from shutit_main util.load_configs(shutit) util.load_mod_from_file(shutit, os.path.join(shutit.shutit_main_dir, 'setup.py')) util.load_shutit_modules(shutit) shutit_main.init_shutit_map(shutit) shutit_main.config_collection(shutit) # Here we can set the starting image. if STATUS['image_tag'] != '': shutit.cfg['target']['docker_image'] = STATUS['image_tag'] else: STATUS['image_tag'] = shutit.cfg['target']['docker_image'] shutit_main.conn_target(shutit) shutit_main.config_collection_for_built(shutit) # Some hacks for server mode shutit.cfg['build']['build_log'] = StringIO.StringIO() shutit.cfg['build']['interactive'] = 0 STATUS['cid'] = shutit.cfg['target']['container_id'] for module_id in shutit.shutit_map: ORIG_MOD_CFG[module_id] = STATUS['cfg'][module_id] = shutit.cfg[module_id] # Add in core sections for module_id in ['repository', 'target']: ORIG_MOD_CFG[module_id] = STATUS['cfg'][module_id] = shutit.cfg[module_id] # Make sure that ORIG_MOD_CFG can be updated seperately to # STATUS and shutit.cfg (which remain linked), as it will hold # our overrides ORIG_MOD_CFG = copy.deepcopy(ORIG_MOD_CFG) update_modules([], None) STATUS['resetting'] = False