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_util.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_util.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 do_interactive_modules(): shutit = shutit_global.shutit cfg = shutit.cfg errs = [] while True: shutit_util.list_modules(long_output=False,sort_order='run_order') # Which module do you want to toggle? module_id = shutit_util.util_raw_input(prompt='Which module id do you want to toggle?\n(just hit return to continue with build)\n(you can enter a substring if it is uniquely matching)\n') if module_id: try: _=cfg[module_id] except: matched_to = [] for m in cfg.keys(): if re.match('.*'+module_id+'.*',m): matched_to.append(m) if len(matched_to) > 1: print 'Please input a uniquely matchable module id. Matches were: ' + str(matched_to) continue elif len(matched_to) == 0: print 'Please input a valid module id' else: module_id = matched_to[0] cfg[module_id]['shutit.core.module.build'] = not cfg[module_id]['shutit.core.module.build'] if not shutit_util.config_collection_for_built(throw_error=False): cfg[module_id]['shutit.core.module.build'] = not cfg[module_id]['shutit.core.module.build'] shutit_util.util_raw_input(prompt='Hit return to continue.\n') continue # If true, set up config for that module if cfg[module_id]['shutit.core.module.build']: # TODO: does this catch all the ones switched on? Once done, get configs for all those. newcfg_list = [] while True: print shutit_util.print_config(cfg,module_id=module_id) name = shutit_util.util_raw_input(prompt='Above is the config for that module. Hit return to continue, or a config item you want to update.\n') if name: doing_list = False while True: if doing_list: val_type = shutit_util.util_raw_input(prompt='Input the type for the next list item: b(oolean), s(tring).\n') if val_type not in ('b','s',''): continue else: val_type = shutit_util.util_raw_input(prompt='Input the type for that config item: b(oolean), s(tring), l(ist).\n') if val_type not in ('b','s','l',''): continue if val_type == 's': val = shutit_util.util_raw_input(prompt='Input the value new for that config item.\n') if doing_list: newcfg_list.append(val) else: break elif val_type == 'b': val = shutit_util.util_raw_input(prompt='Input the value new for the boolean (t/f).\n') if doing_list: if val == 't': newcfg_list.append(True) elif val == 'f': newcfg_list.append(False) else: print 'Input t or f please' continue else: break elif val_type == 'l': doing_list = True newcfg_list = [] elif val_type == '': break # TODO: handle blank/None if doing_list: cfg[module_id][name] = newcfg_list else: cfg[module_id][name] = val else: break else: pass # TODO: if removing, get any that depend on it, and remove those too else: break return errs
def main(): """Main ShutIt function. Handles the configured actions: - skeleton - create skeleton module - list_configs - output computed configuration - depgraph - output digraph of module dependencies """ if sys.version_info.major == 2: if sys.version_info.minor < 7: shutit_global.shutit.fail('Python version must be 2.7+') shutit = shutit_global.shutit cfg = shutit.cfg shutit.log('# ShutIt Started... ',transient=True) shutit_util.parse_args() shutit.log('# Loading configs...',transient=True) shutit_util.load_configs() if shutit.action['skeleton']: shutit_skeleton.create_skeleton() shutit.build['completed'] = True return # Try and ensure shutit is on the path - makes onboarding easier # Only do this if we're in a terminal if shutit_util.determine_interactive() and spawn.find_executable('shutit') is None: setup_shutit_path() shutit_util.load_mod_from_file(os.path.join(shutit.shutit_main_dir, 'shutit_setup.py')) shutit_util.load_shutit_modules() shutit.log('ShutIt modules loaded',level=logging.INFO) init_shutit_map(shutit) shutit_util.config_collection() shutit.log('Configuration loaded',level=logging.INFO) if shutit.action['list_modules']: shutit_util.list_modules() shutit_util.handle_exit() conn_target(shutit) shutit.log('Connected to target',level=logging.INFO) if shutit.build['interactive'] > 0 and shutit.build['choose_config']: errs = do_interactive_modules() else: errs = [] errs.extend(check_deps()) if shutit.action['list_deps']: # Show dependency graph digraph = 'digraph depgraph {\n' digraph += '\n'.join([ make_dep_graph(module) for module_id, module in shutit.shutit_map.items() if module_id in cfg and cfg[module_id]['shutit.core.module.build'] ]) digraph += '\n}' f = file(shutit.build['log_config_path'] + '/digraph.txt','w') f.write(digraph) f.close() digraph_all = 'digraph depgraph {\n' digraph_all += '\n'.join([ make_dep_graph(module) for module_id, module in shutit.shutit_map.items() ]) digraph_all += '\n}' f = file(shutit.build['log_config_path'] + '/digraph_all.txt','w') f.write(digraph_all) f.close() shutit.log('\n================================================================================\n' + digraph_all) shutit.log('\nAbove is the digraph for all modules seen in this shutit invocation. Use graphviz to render into an image, eg\n\n\tshutit depgraph -m mylibrary | dot -Tpng -o depgraph.png\n') shutit.log('\n================================================================================\n') shutit.log('\n\n' + digraph) shutit.log('\n================================================================================\n' + digraph) shutit.log('\nAbove is the digraph for all modules configured to be built in this shutit invocation. Use graphviz to render into an image, eg\n\n\tshutit depgraph -m mylibrary | dot -Tpng -o depgraph.png\n') shutit.log('\n================================================================================\n') # Exit now shutit_util.handle_exit() # Dependency validation done, now collect configs of those marked for build. shutit_util.config_collection_for_built() if shutit.action['list_configs'] or shutit.build['loglevel'] <= logging.DEBUG: # Set build completed shutit.build['completed'] = True shutit.log('================================================================================') shutit.log('Config details placed in: ' + shutit.build['log_config_path']) shutit.log('================================================================================') shutit.log('To render the digraph of this build into an image run eg:\n\ndot -Tgv -o ' + shutit.build['log_config_path'] + '/digraph.gv ' + shutit.build['log_config_path'] + '/digraph.txt && dot -Tpdf -o digraph.pdf ' + shutit.build['log_config_path'] + '/digraph.gv\n\n') shutit.log('================================================================================') shutit.log('To render the digraph of all visible modules into an image, run eg:\n\ndot -Tgv -o ' + shutit.build['log_config_path'] + '/digraph_all.gv ' + shutit.build['log_config_path'] + '/digraph_all.txt && dot -Tpdf -o digraph_all.pdf ' + shutit.build['log_config_path'] + '/digraph_all.gv\n\n') shutit.log('================================================================================') shutit.log('\nConfiguration details have been written to the folder: ' + shutit.build['log_config_path'] + '\n') shutit.log('================================================================================') if shutit.action['list_configs']: return # Check for conflicts now. errs.extend(check_conflicts(shutit)) # Cache the results of check_ready at the start. errs.extend(check_ready(throw_error=False)) if errs: shutit.log(shutit_util.print_modules(), level=logging.ERROR) child = None for err in errs: shutit.log(err[0], level=logging.ERROR) if not child and len(err) > 1: child = err[1] shutit.fail("Encountered some errors, quitting", shutit_pexpect_child=child) do_remove() do_build() do_test() do_finalize() finalize_target() shutit.log(shutit_util.build_report('#Module: N/A (END)'), level=logging.DEBUG) # Show final report messages (ie messages to show after standard report). if shutit.build['report_final_messages'] != '': shutit.log(shutit.build['report_final_messages'], level=logging.INFO) # Mark the build as completed shutit.build['completed'] = True shutit.log('ShutIt run finished',level=logging.INFO) shutit_util.handle_exit(exit_code=0)
def main(): """Main ShutIt function. Handles the configured actions: - skeleton - create skeleton module - serve - run as a server - list_configs - output computed configuration - depgraph - output digraph of module dependencies """ if sys.version_info.major == 2: if sys.version_info.minor < 7: shutit_global.shutit.fail('Python version must be 2.7+') shutit = shutit_global.shutit cfg = shutit.cfg shutit_util.parse_args(shutit) if cfg['action']['skeleton']: shutit_util.create_skeleton(shutit) cfg['build']['completed'] = True return if cfg['action']['serve']: import shutit_srv cfg['build']['interactive'] = 0 revert_dir = os.getcwd() # Move to path of this file os.chdir(os.path.abspath(os.path.dirname(__file__))) shutit_srv.start() os.chdir(os.path.dirname(shutit_util.find_asset('web/index.html'))) return shutit_util.load_configs(shutit) # Try and ensure shutit is on the path - makes onboarding easier # Only do this if we're in a terminal if shutit_util.determine_interactive() and spawn.find_executable('shutit') is None: setup_shutit_path(cfg) shutit_util.load_mod_from_file(shutit, os.path.join(shutit.shutit_main_dir, 'shutit_setup.py')) shutit_util.load_shutit_modules(shutit) if cfg['action']['list_modules']: shutit_util.list_modules(shutit) sys.exit(0) init_shutit_map(shutit) shutit_util.config_collection(shutit) conn_target(shutit) if cfg['build']['interactive'] > 0 and cfg['build']['choose_config']: errs = do_interactive_modules(shutit) else: errs = [] errs.extend(check_deps(shutit)) if cfg['action']['list_deps']: # Show dependency graph digraph = 'digraph depgraph {\n' digraph = digraph + '\n'.join([ make_dep_graph(module) for module_id, module in shutit.shutit_map.items() if module_id in cfg and cfg[module_id]['shutit.core.module.build'] ]) digraph = digraph + '\n}' f = file(cfg['build']['log_config_path'] + '/digraph.txt','w') f.write(digraph) f.close() digraph_all = 'digraph depgraph {\n' digraph_all = digraph_all + '\n'.join([ make_dep_graph(module) for module_id, module in shutit.shutit_map.items() ]) digraph_all = digraph_all + '\n}' f = file(cfg['build']['log_config_path'] + '/digraph_all.txt','w') f.write(digraph_all) f.close() shutit.log('\n================================================================================\n' + digraph_all, force_stdout=True) shutit.log('\nAbove is the digraph for all modules seen in this shutit invocation. Use graphviz to render into an image, eg\n\n\tshutit depgraph -m mylibrary | dot -Tpng -o depgraph.png\n', force_stdout=True) shutit.log('\n================================================================================\n', force_stdout=True) shutit.log('\n\n' + digraph, force_stdout=True) shutit.log('\n================================================================================\n' + digraph, force_stdout=True) shutit.log('\nAbove is the digraph for all modules configured to be built in this shutit invocation. Use graphviz to render into an image, eg\n\n\tshutit depgraph -m mylibrary | dot -Tpng -o depgraph.png\n', force_stdout=True) shutit.log('\n================================================================================\n', force_stdout=True) # Exit now sys.exit(0) # Dependency validation done, now collect configs of those marked for build. shutit_util.config_collection_for_built(shutit) if False and (cfg['action']['list_configs'] or cfg['build']['debug']): shutit.log(shutit_util.print_config(cfg, history=cfg['list_configs']['cfghistory']), force_stdout=True) # Set build completed cfg['build']['completed'] = True f = file(cfg['build']['log_config_path'] + '/cfg.txt','w') f.write(shutit_util.print_config(cfg, history=cfg['list_configs']['cfghistory'])) f.close() shutit.log('================================================================================', force_stdout=True) shutit.log('Config details placed in: ' + cfg['build']['log_config_path'], force_stdout=True) shutit.log('================================================================================', force_stdout=True) shutit.log('To render the digraph of this build into an image run eg:\n\ndot -Tgv -o ' + cfg['build']['log_config_path'] + '/digraph.gv ' + cfg['build']['log_config_path'] + '/digraph.txt && dot -Tpdf -o digraph.pdf ' + cfg['build']['log_config_path'] + '/digraph.gv\n\n', force_stdout=True) shutit.log('================================================================================', force_stdout=True) shutit.log('To render the digraph of all visible modules into an image, run eg:\n\ndot -Tgv -o ' + cfg['build']['log_config_path'] + '/digraph_all.gv ' + cfg['build']['log_config_path'] + '/digraph_all.txt && dot -Tpdf -o digraph_all.pdf ' + cfg['build']['log_config_path'] + '/digraph_all.gv\n\n', force_stdout=True) shutit.log('================================================================================', force_stdout=True) shutit.log('\nConfiguration details have been written to the folder: ' + cfg['build']['log_config_path'] + '\n', force_stdout=True) shutit.log('================================================================================', force_stdout=True) if cfg['action']['list_configs']: return # Check for conflicts now. errs.extend(check_conflicts(shutit)) # Cache the results of check_ready at the start. errs.extend(check_ready(shutit, throw_error=False)) if errs: shutit.log(print_modules(shutit), code='31') child = None for err in errs: shutit.log(err[0], force_stdout=True, code='31') if not child and len(err) > 1: child = err[1] shutit.fail("Encountered some errors, quitting", child=child) shutit.record_config() do_remove(shutit) do_build(shutit) do_test(shutit) do_finalize(shutit) finalize_target(shutit) shutit.log(shutit_util.build_report(shutit, '#Module: N/A (END)'), prefix=False, code='32') if cfg['build']['build_log']: cfg['build']['report_final_messages'] += "\nBuild log file: " + cfg['host']['logfile'] # Show final report messages (ie messages to show after standard report). if cfg['build']['report_final_messages'] != '': shutit.log(cfg['build']['report_final_messages'], prefix=False, force_stdout=True, code='31') if cfg['build']['interactive'] >= 3: shutit.log('\n' + 'The build is complete. You should now have a target ' + 'called ' + cfg['target']['name'] + ' and a new image if you chose to commit it.\n\n' + 'Look and play with the following files from the newly-created ' + 'module directory to dig deeper:\n\n configs/build.cnf\n ' + '*.py\n\nYou can rebuild at any time by running the supplied ' + './build.sh and run with the supplied ./run.sh. These may need ' + 'tweaking for your particular environment, eg sudo\n\n' + 'You can inspect the details of the build in the target image\'s ' + cfg['build']['build_db_dir'] + ' directory.', force_stdout=True, code='32') # Mark the build as completed cfg['build']['completed'] = True
def do_interactive_modules(): shutit = shutit_global.shutit cfg = shutit.cfg errs = [] while True: shutit_util.list_modules(long_output=False, sort_order='run_order') # Which module do you want to toggle? module_id = shutit_util.util_raw_input( prompt= 'Which module id do you want to toggle?\n(just hit return to continue with build)\n' ) if module_id: try: _ = cfg[module_id] except: print 'Please input a valid module id' continue cfg[module_id]['shutit.core.module.build'] = not cfg[module_id][ 'shutit.core.module.build'] if not shutit_util.config_collection_for_built(throw_error=False): cfg[module_id]['shutit.core.module.build'] = not cfg[ module_id]['shutit.core.module.build'] shutit_util.util_raw_input(prompt='Hit return to continue.\n') continue # If true, set up config for that module if cfg[module_id]['shutit.core.module.build']: # TODO: does this catch all the ones switched on? Once done, get configs for all those. newcfg_list = [] while True: print shutit_util.print_config(cfg, module_id=module_id) name = shutit_util.util_raw_input( prompt= 'Above is the config for that module. Hit return to continue, or a config item you want to update.\n' ) if name: doing_list = False while True: if doing_list: val_type = shutit_util.util_raw_input( prompt= 'Input the type for the next list item: b(oolean), s(tring).\n' ) if val_type not in ('b', 's', ''): continue else: val_type = shutit_util.util_raw_input( prompt= 'Input the type for that config item: b(oolean), s(tring), l(ist).\n' ) if val_type not in ('b', 's', 'l', ''): continue if val_type == 's': val = shutit_util.util_raw_input( prompt= 'Input the value new for that config item.\n' ) if doing_list: newcfg_list.append(val) else: break elif val_type == 'b': val = shutit_util.util_raw_input( prompt= 'Input the value new for the boolean (t/f).\n' ) if doing_list: if val == 't': newcfg_list.append(True) elif val == 'f': newcfg_list.append(False) else: print 'Input t or f please' continue else: break elif val_type == 'l': doing_list = True newcfg_list = [] elif val_type == '': break # TODO: handle blank/None if doing_list: cfg[module_id][name] = newcfg_list else: cfg[module_id][name] = val else: break else: pass # TODO: if removing, get any that depend on it, and remove those too else: break return errs
def main(): """Main ShutIt function. Handles the configured actions: - skeleton - create skeleton module - list_configs - output computed configuration - depgraph - output digraph of module dependencies """ if sys.version_info.major == 2: if sys.version_info.minor < 7: shutit_global.shutit.fail('Python version must be 2.7+') shutit = shutit_global.shutit cfg = shutit.cfg shutit.log('ShutIt Started... ', transient=True, newline=False) shutit_util.parse_args() if shutit.action['skeleton']: shutit_util.create_skeleton() shutit.build['completed'] = True return shutit.log('Loading configs...', transient=True) shutit_util.load_configs() # Try and ensure shutit is on the path - makes onboarding easier # Only do this if we're in a terminal if shutit_util.determine_interactive( ) and spawn.find_executable('shutit') is None: setup_shutit_path(cfg) shutit_util.load_mod_from_file( os.path.join(shutit.shutit_main_dir, 'shutit_setup.py')) shutit_util.load_shutit_modules() shutit.log('ShutIt modules loaded', level=logging.INFO) init_shutit_map(shutit) shutit_util.config_collection() shutit.log('Configuration loaded', level=logging.INFO) if shutit.action['list_modules']: shutit_util.list_modules() shutit_util.handle_exit() conn_target(shutit) shutit.log('Connected to target', level=logging.INFO) if shutit.build['interactive'] > 0 and shutit.build['choose_config']: errs = do_interactive_modules() else: errs = [] errs.extend(check_deps()) if shutit.action['list_deps']: # Show dependency graph digraph = 'digraph depgraph {\n' digraph += '\n'.join([ make_dep_graph(module) for module_id, module in shutit.shutit_map.items() if module_id in cfg and cfg[module_id]['shutit.core.module.build'] ]) digraph += '\n}' f = file(shutit.build['log_config_path'] + '/digraph.txt', 'w') f.write(digraph) f.close() digraph_all = 'digraph depgraph {\n' digraph_all += '\n'.join([ make_dep_graph(module) for module_id, module in shutit.shutit_map.items() ]) digraph_all += '\n}' f = file(shutit.build['log_config_path'] + '/digraph_all.txt', 'w') f.write(digraph_all) f.close() shutit.log( '\n================================================================================\n' + digraph_all) shutit.log( '\nAbove is the digraph for all modules seen in this shutit invocation. Use graphviz to render into an image, eg\n\n\tshutit depgraph -m mylibrary | dot -Tpng -o depgraph.png\n' ) shutit.log( '\n================================================================================\n' ) shutit.log('\n\n' + digraph) shutit.log( '\n================================================================================\n' + digraph) shutit.log( '\nAbove is the digraph for all modules configured to be built in this shutit invocation. Use graphviz to render into an image, eg\n\n\tshutit depgraph -m mylibrary | dot -Tpng -o depgraph.png\n' ) shutit.log( '\n================================================================================\n' ) # Exit now shutit_util.handle_exit() # Dependency validation done, now collect configs of those marked for build. shutit_util.config_collection_for_built() if shutit.action[ 'list_configs'] or shutit.build['loglevel'] <= logging.DEBUG: # Set build completed shutit.build['completed'] = True shutit.log( '================================================================================' ) shutit.log('Config details placed in: ' + shutit.build['log_config_path']) shutit.log( '================================================================================' ) shutit.log( 'To render the digraph of this build into an image run eg:\n\ndot -Tgv -o ' + shutit.build['log_config_path'] + '/digraph.gv ' + shutit.build['log_config_path'] + '/digraph.txt && dot -Tpdf -o digraph.pdf ' + shutit.build['log_config_path'] + '/digraph.gv\n\n') shutit.log( '================================================================================' ) shutit.log( 'To render the digraph of all visible modules into an image, run eg:\n\ndot -Tgv -o ' + shutit.build['log_config_path'] + '/digraph_all.gv ' + shutit.build['log_config_path'] + '/digraph_all.txt && dot -Tpdf -o digraph_all.pdf ' + shutit.build['log_config_path'] + '/digraph_all.gv\n\n') shutit.log( '================================================================================' ) shutit.log( '\nConfiguration details have been written to the folder: ' + shutit.build['log_config_path'] + '\n') shutit.log( '================================================================================' ) if shutit.action['list_configs']: return # Check for conflicts now. errs.extend(check_conflicts(shutit)) # Cache the results of check_ready at the start. errs.extend(check_ready(throw_error=False)) if errs: shutit.log(shutit_util.print_modules(), level=logging.ERROR) child = None for err in errs: shutit.log(err[0], level=logging.ERROR) if not child and len(err) > 1: child = err[1] shutit.fail("Encountered some errors, quitting", shutit_pexpect_child=child) do_remove() do_build() do_test() do_finalize() finalize_target() shutit.log(shutit_util.build_report('#Module: N/A (END)'), level=logging.DEBUG) # Show final report messages (ie messages to show after standard report). if shutit.build['report_final_messages'] != '': shutit.log(shutit.build['report_final_messages'], level=logging.INFO) if shutit.build['interactive'] >= 3: shutit.log( '\n' + 'The build is complete. You should now have a target called ' + shutit.target['name'] + ' and a new image if you chose to commit it.\n\nLook and play with the following files from the newly-created module directory to dig deeper:\n\n configs/build.cnf\n *.py\n\nYou can rebuild at any time by running the supplied ./build.sh and run with the supplied ./run.sh. These may need tweaking for your particular environment, eg sudo', level=logging.DEBUG) # Mark the build as completed shutit.build['completed'] = True shutit.log('ShutIt run finished', level=logging.INFO) shutit_util.handle_exit(0)
def do_interactive_modules(shutit): cfg = shutit.cfg errs = [] while True: shutit_util.list_modules(shutit, long_output=False, sort_order='run_order') # Which module do you want to toggle? module_id = shutit_util.util_raw_input( shutit, prompt= 'Which module id do you want to toggle?\n(just hit return to continue with build)\n(you can enter a substring if it is uniquely matching)\n' ) if module_id: try: _ = cfg[module_id] except NameError: matched_to = [] for m in cfg.keys(): if re.match('.*' + module_id + '.*', m): matched_to.append(m) if len(matched_to) > 1: print( 'Please input a uniquely matchable module id. Matches were: ' + str(matched_to)) continue elif len(matched_to) == 0: print('Please input a valid module id') else: module_id = matched_to[0] cfg[module_id]['shutit.core.module.build'] = not cfg[module_id][ 'shutit.core.module.build'] if not shutit_util.config_collection_for_built(shutit, throw_error=False): cfg[module_id]['shutit.core.module.build'] = not cfg[ module_id]['shutit.core.module.build'] shutit_util.util_raw_input(shutit, prompt='Hit return to continue.\n') continue # If true, set up config for that module if cfg[module_id]['shutit.core.module.build']: # TODO: does this catch all the ones switched on? Once done, get configs for all those. newcfg_list = [] while True: print( shutit_util.print_config(shutit, cfg, module_id=module_id)) name = shutit_util.util_raw_input( shutit, prompt= 'Above is the config for that module. Hit return to continue, or a config item you want to update.\n' ) if name: doing_list = False while True: if doing_list: val_type = shutit_util.util_raw_input( shutit, prompt= 'Input the type for the next list item: b(oolean), s(tring).\n' ) if val_type not in ('b', 's', ''): continue else: val_type = shutit_util.util_raw_input( shutit, prompt= 'Input the type for that config item: b(oolean), s(tring), l(ist).\n' ) if val_type not in ('b', 's', 'l', ''): continue if val_type == 's': val = shutit_util.util_raw_input( shutit, prompt= 'Input the value new for that config item.\n' ) if doing_list: newcfg_list.append(val) else: break elif val_type == 'b': val = shutit_util.util_raw_input( shutit, prompt= 'Input the value new for the boolean (t/f).\n' ) if doing_list: if val == 't': newcfg_list.append(True) elif val == 'f': newcfg_list.append(False) else: print('Input t or f please') continue else: break elif val_type == 'l': doing_list = True newcfg_list = [] elif val_type == '': break # TODO: handle blank/None if doing_list: cfg[module_id][name] = newcfg_list else: cfg[module_id][name] = val else: break else: pass # TODO: if removing, get any that depend on it, and remove those too else: break return errs
def do_lists(shutit): if shutit.action['list_deps']: cfg = shutit.cfg # Show dependency graph digraph = 'digraph depgraph {\n' digraph += '\n'.join([ make_dep_graph(module) for module_id, module in shutit.shutit_map.items() if module_id in cfg and cfg[module_id]['shutit.core.module.build'] ]) digraph += '\n}' f = open(shutit.build['log_config_path'] + '/digraph.txt', 'w') f.write(digraph) f.close() digraph_all = 'digraph depgraph {\n' digraph_all += '\n'.join([ make_dep_graph(module) for module_id, module in shutit.shutit_map.items() ]) digraph_all += '\n}' fname = shutit.build['log_config_path'] + '/digraph_all.txt' f = open(fname, 'w') f.write(digraph_all) f.close() shutit.log( '\n================================================================================\n' + digraph_all) shutit.log( '\nAbove is the digraph for ALL MODULES SEEN in this ShutIt invocation. Use graphviz to render into an image, eg\n\n\tcat ' + fname + ' | dot -Tpng -o depgraph.png\n') shutit.log( '\n================================================================================\n' ) fname = shutit.build['log_config_path'] + '/digraph_this.txt' f = open(fname, 'w') f.write(digraph_all) f.close() shutit.log('\n\n' + digraph) shutit.log( '\n================================================================================\n' + digraph) shutit.log( '\nAbove is the digraph for all modules configured to be built IN THIS ShutIt invocation. Use graphviz to render into an image, eg\n\ncat ' + fname + ' | dot -Tpng -o depgraph.png\n') shutit.log( '\n================================================================================\n' ) # Exit now shutit_util.handle_exit(shutit=shutit) # Dependency validation done, now collect configs of those marked for build. shutit_util.config_collection_for_built(shutit) if shutit.action[ 'list_configs'] or shutit.build['loglevel'] <= logging.DEBUG: # Set build completed shutit.build['completed'] = True shutit.log( '================================================================================' ) shutit.log('Config details placed in: ' + shutit.build['log_config_path']) shutit.log( '================================================================================' ) shutit.log( 'To render the digraph of this build into an image run eg:\n\ndot -Tgv -o ' + shutit.build['log_config_path'] + '/digraph.gv ' + shutit.build['log_config_path'] + '/digraph.txt && dot -Tpdf -o digraph.pdf ' + shutit.build['log_config_path'] + '/digraph.gv\n\n') shutit.log( '================================================================================' ) shutit.log( 'To render the digraph of all visible modules into an image, run eg:\n\ndot -Tgv -o ' + shutit.build['log_config_path'] + '/digraph_all.gv ' + shutit.build['log_config_path'] + '/digraph_all.txt && dot -Tpdf -o digraph_all.pdf ' + shutit.build['log_config_path'] + '/digraph_all.gv\n\n') shutit.log( '================================================================================' ) shutit.log( '\nConfiguration details have been written to the folder: ' + shutit.build['log_config_path'] + '\n') shutit.log( '================================================================================' ) if shutit.action['list_configs']: return