def do_build(shutit): """Runs build phase, building any modules that we've determined need building. """ cfg = shutit.cfg shutit.log('PHASE: build, repository work', code='32') shutit.log(shutit_util.print_config(cfg)) if cfg['build']['interactive'] >= 3: print ('\nNow building any modules that need building' + shutit_util.colour('32', '\n\n[Hit return to continue]\n')) shutit_util.util_raw_input(shutit=shutit) module_id_list = shutit_util.module_ids(shutit) if cfg['build']['deps_only']: module_id_list_build_only = filter(lambda x: cfg[x]['shutit.core.module.build'], module_id_list) for module_id in module_id_list: module = shutit.shutit_map[module_id] shutit.log('considering whether to build: ' + module.module_id, code='32') if cfg[module.module_id]['shutit.core.module.build']: if cfg['build']['delivery'] not in module.ok_delivery_methods: shutit.fail('Module: ' + module.module_id + ' can only be built with one of these --delivery methods: ' + str(module.ok_delivery_methods) + '\nSee shutit build -h for more info, or try adding: --delivery <method> to your shutit invocation') if shutit_util.is_installed(shutit,module): cfg['build']['report'] = (cfg['build']['report'] + '\nBuilt already: ' + module.module_id + ' with run order: ' + str(module.run_order)) else: # We move to the module directory to perform the build, returning immediately afterwards. if cfg['build']['deps_only'] and module_id == module_id_list_build_only[-1]: # If this is the last module, and we are only building deps, stop here. cfg['build']['report'] = (cfg['build']['report'] + '\nSkipping: ' + module.module_id + ' with run order: ' + str(module.run_order) + '\n\tas this is the final module and we are building dependencies only') else: revert_dir = os.getcwd() cfg['environment'][cfg['build']['current_environment_id']]['module_root_dir'] = os.path.dirname(module.__module_file) shutit.chdir(cfg['environment'][cfg['build']['current_environment_id']]['module_root_dir']) shutit.login(prompt_prefix=module_id,command='bash') build_module(shutit, module) shutit.logout() shutit.chdir(revert_dir) if shutit_util.is_installed(shutit, module): shutit.log('Starting module') if not module.start(shutit): shutit.fail(module.module_id + ' failed on start', child=shutit.pexpect_children['target_child'])
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() os.chdir(sys.path[0]) shutit_srv.start() os.chdir(revert_dir) 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) config_collection(shutit) conn_target(shutit) 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. config_collection_for_built(shutit) if 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, force_stdout=True, code="32") if cfg["build"]["build_log"]: cfg["build"]["report_final_messages"] += "Build 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_build(shutit): """Runs build phase, building any modules that we've determined need building. """ cfg = shutit.cfg shutit.log("PHASE: build, repository work", code="32") shutit.log(shutit_util.print_config(cfg)) if cfg["build"]["interactive"] >= 3: print ( "\nNow building any modules that need building" + shutit_util.colour("32", "\n\n[Hit return to continue]\n") ) shutit_util.util_raw_input(shutit=shutit) module_id_list = module_ids(shutit) if cfg["build"]["deps_only"]: module_id_list_build_only = filter(lambda x: cfg[x]["shutit.core.module.build"], module_id_list) for module_id in module_id_list: module = shutit.shutit_map[module_id] shutit.log("considering whether to build: " + module.module_id, code="32") if cfg[module.module_id]["shutit.core.module.build"]: if cfg["build"]["delivery"] not in module.ok_delivery_methods: shutit.fail( "Module: " + module.module_id + " can only be built with one of these --delivery methods: " + str(module.ok_delivery_methods) + "\nSee shutit build -h for more info, or try adding: --delivery <method> to your shutit invocation" ) if is_installed(shutit, module): cfg["build"]["report"] = ( cfg["build"]["report"] + "\nBuilt already: " + module.module_id + " with run order: " + str(module.run_order) ) else: # We move to the module directory to perform the build, returning immediately afterwards. if cfg["build"]["deps_only"] and module_id == module_id_list_build_only[-1]: # If this is the last module, and we are only building deps, stop here. cfg["build"]["report"] = ( cfg["build"]["report"] + "\nSkipping: " + module.module_id + " with run order: " + str(module.run_order) + "\n\tas this is the final module and we are building dependencies only" ) else: revert_dir = os.getcwd() cfg["environment"][cfg["build"]["current_environment_id"]]["module_root_dir"] = os.path.dirname( module.__module_file ) shutit.chdir(cfg["environment"][cfg["build"]["current_environment_id"]]["module_root_dir"]) shutit.login(prompt_prefix=module_id, command="bash") build_module(shutit, module) shutit.logout() shutit.chdir(revert_dir) if is_installed(shutit, module): shutit.log("Starting module") if not module.start(shutit): shutit.fail(module.module_id + " failed on start", child=shutit.pexpect_children["target_child"])
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() os.chdir(sys.path[0]) shutit_srv.start() os.chdir(revert_dir) 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) config_collection(shutit) conn_target(shutit) 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 library | 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 library | 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. config_collection_for_built(shutit) if 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, force_stdout=True, code='32') if cfg['build']['build_log']: cfg['build']['report_final_messages'] += "Build 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(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 - 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() os.chdir(sys.path[0]) shutit_srv.start() os.chdir(revert_dir) 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) config_collection(shutit) conn_target(shutit) 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. config_collection_for_built(shutit) if 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, force_stdout=True, code='32') if cfg['build']['build_log']: cfg['build']['report_final_messages'] += "Build 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_build(shutit): """Runs build phase, building any modules that we've determined need building. """ cfg = shutit.cfg shutit.log('PHASE: build, repository work', code='32') shutit.log(shutit_util.print_config(cfg)) if cfg['build']['interactive'] >= 3: print('\nNow building any modules that need building' + shutit_util.colour('32', '\n\n[Hit return to continue]\n')) shutit_util.util_raw_input(shutit=shutit) module_id_list = module_ids(shutit) if cfg['build']['deps_only']: module_id_list_build_only = filter( lambda x: cfg[x]['shutit.core.module.build'], module_id_list) for module_id in module_id_list: module = shutit.shutit_map[module_id] shutit.log('considering whether to build: ' + module.module_id, code='32') if cfg[module.module_id]['shutit.core.module.build']: if cfg['build']['delivery'] not in module.ok_delivery_methods: shutit.fail( 'Module: ' + module.module_id + ' can only be built with one of these --delivery methods: ' + str(module.ok_delivery_methods) + '\nSee shutit build -h for more info, or try adding: --delivery <method> to your shutit invocation' ) if is_installed(shutit, module): cfg['build']['report'] = (cfg['build']['report'] + '\nBuilt already: ' + module.module_id + ' with run order: ' + str(module.run_order)) else: # We move to the module directory to perform the build, returning immediately afterwards. if cfg['build'][ 'deps_only'] and module_id == module_id_list_build_only[ -1]: # If this is the last module, and we are only building deps, stop here. cfg['build']['report'] = ( cfg['build']['report'] + '\nSkipping: ' + module.module_id + ' with run order: ' + str(module.run_order) + '\n\tas this is the final module and we are building dependencies only' ) else: revert_dir = os.getcwd() cfg['environment'][cfg['build']['current_environment_id']][ 'module_root_dir'] = os.path.dirname( module.__module_file) shutit.chdir(cfg['environment'][cfg['build'][ 'current_environment_id']]['module_root_dir']) shutit.login(prompt_prefix=module_id, command='bash') build_module(shutit, module) shutit.logout() shutit.chdir(revert_dir) if is_installed(shutit, module): shutit.log('Starting module') if not module.start(shutit): shutit.fail(module.module_id + ' failed on start', child=shutit.pexpect_children['target_child'])
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 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 build(self, shutit): # Some useful API calls for reference. See shutit's docs for more info and options: # # ISSUING BASH COMMANDS # shutit.send(send,expect=<default>) - Send a command, wait for expect (string or compiled regexp) # to be seen before continuing. By default this is managed # by ShutIt with shell prompts. # shutit.multisend(send,send_dict) - Send a command, dict contains {expect1:response1,expect2:response2,...} # shutit.send_and_get_output(send) - Returns the output of the sent command # shutit.send_and_match_output(send, matches) # - Returns True if any lines in output match any of # the regexp strings in the matches list # shutit.send_until(send,regexps) - Send command over and over until one of the regexps seen in the output. # shutit.run_script(script) - Run the passed-in string as a script # shutit.install(package) - Install a package # shutit.remove(package) - Remove a package # shutit.login(user='******', command='su -') # - Log user in with given command, and set up prompt and expects. # Use this if your env (or more specifically, prompt) changes at all, # eg reboot, bash, ssh # shutit.logout(command='exit') - Clean up from a login. # # COMMAND HELPER FUNCTIONS # shutit.add_to_bashrc(line) - Add a line to bashrc # shutit.get_url(fname, locations) - Get a file via url from locations specified in a list # shutit.get_ip_address() - Returns the ip address of the target # shutit.command_available(command) - Returns true if the command is available to run # # LOGGING AND DEBUG # shutit.log(msg,add_final_message=False) - # Send a message to the log. add_final_message adds message to # output at end of build # shutit.pause_point(msg='') - Give control of the terminal to the user # shutit.step_through(msg='') - Give control to the user and allow them to step through commands # # SENDING FILES/TEXT # shutit.send_file(path, contents) - Send file to path on target with given contents as a string # shutit.send_host_file(path, hostfilepath) # - Send file from host machine to path on the target # shutit.send_host_dir(path, hostfilepath) # - Send directory and contents to path on the target # shutit.insert_text(text, fname, pattern) # - Insert text into file fname after the first occurrence of # regexp pattern. # shutit.delete_text(text, fname, pattern) # - Delete text from file fname after the first occurrence of # regexp pattern. # shutit.replace_text(text, fname, pattern) # - Replace text from file fname after the first occurrence of # regexp pattern. # ENVIRONMENT QUERYING # shutit.host_file_exists(filename, directory=False) # - Returns True if file exists on host # shutit.file_exists(filename, directory=False) # - Returns True if file exists on target # shutit.user_exists(user) - Returns True if the user exists on the target # shutit.package_installed(package) - Returns True if the package exists on the target # shutit.set_password(password, user='') # - Set password for a given user on target # # USER INTERACTION # shutit.get_input(msg,default,valid[],boolean?,ispass?) # - Get input from user and return output # shutit.fail(msg) - Fail the program and exit with status 1 # cfg = shutit.cfg shutit.send_file(cfg['build']['build_db_dir'] + '/' + cfg['build']['build_id'] + '/' + cfg['build']['build_id'] + '.cfg', shutit_util.print_config(cfg)) return True