signature stringlengths 8 3.44k | body stringlengths 0 1.41M | docstring stringlengths 1 122k | id stringlengths 5 17 |
|---|---|---|---|
def get_distro_info(self,<EOL>shutit_pexpect_child=None,<EOL>loglevel=logging.DEBUG): | shutit_global.shutit_global_object.yield_to_draw()<EOL>shutit_pexpect_child = shutit_pexpect_child or self.get_current_shutit_pexpect_session().pexpect_child<EOL>shutit_pexpect_session = self.get_shutit_pexpect_session_from_child(shutit_pexpect_child)<EOL>return shutit_pexpect_session.get_distro_info(loglevel=loglevel)... | Get information about which distro we are using, placing it in the environment object.
Fails if distro could not be determined.
Should be called with the container is started up, and uses as core info
as possible.
Note: if the install type is apt, it issues the following:
-... | f10347:c2:m58 |
def lsb_release(self,<EOL>shutit_pexpect_child=None,<EOL>loglevel=logging.DEBUG): | shutit_global.shutit_global_object.yield_to_draw()<EOL>shutit_pexpect_child = shutit_pexpect_child or self.get_current_shutit_pexpect_session().pexpect_child<EOL>shutit_pexpect_session = self.get_shutit_pexpect_session_from_child(shutit_pexpect_child)<EOL>return shutit_pexpect_session.lsb_release(loglevel=loglevel)<EOL... | Get distro information from lsb_release. | f10347:c2:m59 |
def set_password(self,<EOL>password,<EOL>user='<STR_LIT>',<EOL>shutit_pexpect_child=None,<EOL>note=None): | shutit_global.shutit_global_object.yield_to_draw()<EOL>shutit_pexpect_child = shutit_pexpect_child or self.get_current_shutit_pexpect_session().pexpect_child<EOL>shutit_pexpect_session = self.get_shutit_pexpect_session_from_child(shutit_pexpect_child)<EOL>return shutit_pexpect_session.set_password(password,user=user,no... | Sets the password for the current user or passed-in user.
As a side effect, installs the "password" package.
@param user: username to set the password for. Defaults to '' (i.e. current user)
@param password: password to set for the user
@param shutit_pexpect_child: See ... | f10347:c2:m60 |
def whoami(self,<EOL>note=None,<EOL>shutit_pexpect_child=None,<EOL>loglevel=logging.DEBUG): | shutit_global.shutit_global_object.yield_to_draw()<EOL>shutit_pexpect_child = shutit_pexpect_child or self.get_current_shutit_pexpect_session().pexpect_child<EOL>shutit_pexpect_session = self.get_shutit_pexpect_session_from_child(shutit_pexpect_child)<EOL>return shutit_pexpect_session.whoami(note=note,loglevel=loglevel... | Returns the current user by executing "whoami".
@param note: See send()
@return: the output of "whoami"
@rtype: string | f10347:c2:m61 |
def is_user_id_available(self,<EOL>user_id,<EOL>shutit_pexpect_child=None,<EOL>note=None,<EOL>loglevel=logging.DEBUG): | shutit_global.shutit_global_object.yield_to_draw()<EOL>shutit_pexpect_child = shutit_pexpect_child or self.get_current_shutit_pexpect_session().pexpect_child<EOL>shutit_pexpect_session = self.get_shutit_pexpect_session_from_child(shutit_pexpect_child)<EOL>return shutit_pexpect_session.is_user_id_available(user_id,<EOL>... | Determine whether the specified user_id available.
@param user_id: User id to be checked.
@param shutit_pexpect_child: See send()
@param note: See send()
@type user_id: integer
@rtype: boolean
@return: True is the specified user id is not use... | f10347:c2:m62 |
def push_repository(self,<EOL>repository,<EOL>docker_executable='<STR_LIT>',<EOL>shutit_pexpect_child=None,<EOL>expect=None,<EOL>note=None,<EOL>loglevel=logging.INFO): | shutit_global.shutit_global_object.yield_to_draw()<EOL>self.handle_note(note)<EOL>shutit_pexpect_child = shutit_pexpect_child or self.get_shutit_pexpect_session_from_id('<STR_LIT>').pexpect_child<EOL>expect = expect or self.expect_prompts['<STR_LIT>']<EOL>send = docker_executable + '<STR_L... | Pushes the repository.
@param repository: Repository to push.
@param docker_executable: Defaults to 'docker'
@param expect: See send()
@param shutit_pexpect_child: See send()
@type repository: string
@type docker_executabl... | f10347:c2:m63 |
def do_repository_work(self,<EOL>repo_name,<EOL>repo_tag=None,<EOL>docker_executable='<STR_LIT>',<EOL>password=None,<EOL>force=None,<EOL>loglevel=logging.DEBUG,<EOL>note=None,<EOL>tag=None,<EOL>push=None,<EOL>export=None,<EOL>save=None): | shutit_global.shutit_global_object.yield_to_draw()<EOL>self.handle_note(note)<EOL>shutit_pexpect_session = self.get_current_shutit_pexpect_session()<EOL>if tag is None:<EOL><INDENT>tag = self.repository['<STR_LIT>']<EOL><DEDENT>if push is None:<EOL><INDENT>push = self.repository['<STR_LIT>']<EOL><DEDENT>if export ... | Commit, tag, push, tar a docker container based on the configuration we have.
@param repo_name: Name of the repository.
@param docker_executable: Defaults to 'docker'
@param password:
@param force:
@type repo_name: string
@type docker_executable: ... | f10347:c2:m64 |
def get_config(self,<EOL>module_id,<EOL>option,<EOL>default=None,<EOL>boolean=False,<EOL>secret=False,<EOL>forceask=False,<EOL>forcenone=False,<EOL>hint=None): | shutit_global.shutit_global_object.yield_to_draw()<EOL>cfg = self.cfg<EOL>if module_id not in cfg.keys():<EOL><INDENT>cfg[module_id] = {}<EOL><DEDENT>if not self.config_parser.has_section(module_id):<EOL><INDENT>self.config_parser.add_section(module_id)<EOL><DEDENT>if not forceask and self.config_parser.has_option(modu... | Gets a specific config from the config files, allowing for a default.
Handles booleans vs strings appropriately.
@param module_id: module id this relates to, eg com.mycorp.mymodule.mymodule
@param option: config item to set
@param default: default value if not set in file... | f10347:c2:m65 |
def get_emailer(self, cfg_section): | shutit_global.shutit_global_object.yield_to_draw()<EOL>import emailer<EOL>return emailer.Emailer(cfg_section, self)<EOL> | Sends an email using the mailer | f10347:c2:m68 |
def get_shutit_pexpect_session_from_child(self, shutit_pexpect_child): | shutit_global.shutit_global_object.yield_to_draw()<EOL>if not isinstance(shutit_pexpect_child, pexpect.pty_spawn.spawn):<EOL><INDENT>self.fail('<STR_LIT>' + str(type(shutit_pexpect_child)),throw_exception=True) <EOL><DEDENT>for key in self.shutit_pexpect_sessions:<EOL><INDENT>if self.shutit_pexpect_sessions[key].pexpec... | Given a pexpect/child object, return the shutit_pexpect_session object. | f10347:c2:m70 |
def get_shutit_pexpect_session_id(self, shutit_pexpect_child): | shutit_global.shutit_global_object.yield_to_draw()<EOL>if not isinstance(shutit_pexpect_child, pexpect.pty_spawn.spawn):<EOL><INDENT>self.fail('<STR_LIT>',throw_exception=True) <EOL><DEDENT>for key in self.shutit_pexpect_sessions:<EOL><INDENT>if self.shutit_pexpect_sessions[key].pexpect_child == shutit_pexpect_child:<E... | Given a pexpect child object, return the shutit_pexpect_session_id object. | f10347:c2:m71 |
def get_shutit_pexpect_session_from_id(self, shutit_pexpect_id): | shutit_global.shutit_global_object.yield_to_draw()<EOL>for key in self.shutit_pexpect_sessions:<EOL><INDENT>if self.shutit_pexpect_sessions[key].pexpect_session_id == shutit_pexpect_id:<EOL><INDENT>return self.shutit_pexpect_sessions[key]<EOL><DEDENT><DEDENT>return self.fail('<STR_LIT>',throw_exception=True)<EOL> | Get the pexpect session from the given identifier. | f10347:c2:m72 |
def get_commands(self): | shutit_global.shutit_global_object.yield_to_draw()<EOL>s = '<STR_LIT>'<EOL>for c in self.build['<STR_LIT>']:<EOL><INDENT>if isinstance(c, str):<EOL><INDENT>if c and c[<NUM_LIT:0>] != '<STR_LIT:U+0020>':<EOL><INDENT>s += c + '<STR_LIT:\n>'<EOL><DEDENT><DEDENT><DEDENT>return s<EOL> | Gets command that have been run and have not been redacted. | f10347:c2:m77 |
def build_report(self, msg='<STR_LIT>'): | shutit_global.shutit_global_object.yield_to_draw()<EOL>s = '<STR_LIT:\n>'<EOL>s += '<STR_LIT>'<EOL>s += '<STR_LIT>' + shutit_global.shutit_global_object.build_id + '<STR_LIT:\n>'<EOL>s += self.get_commands()<EOL>s += '<STR_LIT>' + shutit_global.shutit_global_object.build_id + '<STR_LIT:\n>'<EOL>s += '<STR_LIT>'<EOL>s +... | Resposible for constructing a report to be output as part of the build.
Returns report as a string. | f10347:c2:m78 |
def match_string(self, string_to_match, regexp): | shutit_global.shutit_global_object.yield_to_draw()<EOL>if not isinstance(string_to_match, str):<EOL><INDENT>return None<EOL><DEDENT>lines = string_to_match.split('<STR_LIT:\r\n>')<EOL>new_lines = []<EOL>for line in lines:<EOL><INDENT>new_lines = new_lines + line.split('<STR_LIT:\r>')<EOL><DEDENT>for line in lines:<EOL>... | Get regular expression from the first of the lines passed
in in string that matched. Handles first group of regexp as
a return value.
@param string_to_match: String to match on
@param regexp: Regexp to check (per-line) against string
@type string_to_match: string
@type ... | f10347:c2:m79 |
def module_ids(self, rev=False): | shutit_global.shutit_global_object.yield_to_draw()<EOL>ids = sorted(list(self.shutit_map.keys()),key=lambda module_id: self.shutit_map[module_id].run_order)<EOL>if rev:<EOL><INDENT>return list(reversed(ids))<EOL><DEDENT>return ids<EOL> | Gets a list of module ids guaranteed to be sorted by run_order, ignoring conn modules
(run order < 0). | f10347:c2:m80 |
def is_to_be_built_or_is_installed(self, shutit_module_obj): | shutit_global.shutit_global_object.yield_to_draw()<EOL>cfg = self.cfg<EOL>if cfg[shutit_module_obj.module_id]['<STR_LIT>']:<EOL><INDENT>return True<EOL><DEDENT>return self.is_installed(shutit_module_obj)<EOL> | Returns true if this module is configured to be built, or if it is already installed. | f10347:c2:m81 |
def is_installed(self, shutit_module_obj): | shutit_global.shutit_global_object.yield_to_draw()<EOL>if shutit_module_obj.module_id in self.get_current_shutit_pexpect_session_environment().modules_installed:<EOL><INDENT>return True<EOL><DEDENT>if shutit_module_obj.module_id in self.get_current_shutit_pexpect_session_environment().modules_not_installed:<EOL><INDENT... | Returns true if this module is installed.
Uses cache where possible. | f10347:c2:m82 |
def allowed_image(self, module_id): | shutit_global.shutit_global_object.yield_to_draw()<EOL>self.log("<STR_LIT>" + module_id,level=logging.DEBUG)<EOL>cfg = self.cfg<EOL>if self.build['<STR_LIT>']:<EOL><INDENT>self.log("<STR_LIT>" + module_id,level=logging.DEBUG)<EOL>return True<EOL><DEDENT>self.log(str(cfg[module_id]['<STR_LIT>']),level=logging.DEBUG)<EOL... | Given a module id, determine whether the image is allowed to be built. | f10347:c2:m84 |
def print_modules(self): | shutit_global.shutit_global_object.yield_to_draw()<EOL>cfg = self.cfg<EOL>module_string = '<STR_LIT>'<EOL>module_string += '<STR_LIT>'<EOL>module_string += '<STR_LIT>'<EOL>for module_id in self.module_ids():<EOL><INDENT>module_string += '<STR_LIT:U+0020>' + str(self.shutit_map[module_id].run_order) + '<STR_LIT:U+0020>'... | Returns a string table representing the modules in the ShutIt module map. | f10347:c2:m85 |
def load_shutit_modules(self): | shutit_global.shutit_global_object.yield_to_draw()<EOL>if self.loglevel <= logging.DEBUG:<EOL><INDENT>self.log('<STR_LIT>',level=logging.DEBUG)<EOL>self.log(self.host['<STR_LIT>'],level=logging.DEBUG)<EOL><DEDENT>for shutit_module_path in self.host['<STR_LIT>']:<EOL><INDENT>self.load_all_from_path(shutit_module_path)<E... | Responsible for loading the shutit modules based on the configured module
paths. | f10347:c2:m86 |
def get_command(self, command): | shutit_global.shutit_global_object.yield_to_draw()<EOL>if command in ('<STR_LIT>','<STR_LIT>','<STR_LIT>'):<EOL><INDENT>if self.get_current_shutit_pexpect_session_environment().distro == '<STR_LIT>':<EOL><INDENT>return '<STR_LIT:g>' + command<EOL><DEDENT><DEDENT>return command<EOL> | Helper function for osx - return gnu utils rather than default for
eg head and md5sum where possible and needed. | f10347:c2:m87 |
def get_send_command(self, send): | shutit_global.shutit_global_object.yield_to_draw()<EOL>if send is None:<EOL><INDENT>return send<EOL><DEDENT>cmd_arr = send.split()<EOL>if cmd_arr and cmd_arr[<NUM_LIT:0>] in ('<STR_LIT>','<STR_LIT>','<STR_LIT>'):<EOL><INDENT>newcmd = self.get_command(cmd_arr[<NUM_LIT:0>])<EOL>send = send.replace(cmd_arr[<NUM_LIT:0>],ne... | Internal helper function to get command that's really sent | f10347:c2:m88 |
def load_configs(self): | shutit_global.shutit_global_object.yield_to_draw()<EOL>configs = [('<STR_LIT>', StringIO(default_cnf)), os.path.expanduser('<STR_LIT>'), os.path.join(self.host['<STR_LIT>'], '<STR_LIT>'), '<STR_LIT>']<EOL>for config_file_name in self.build['<STR_LIT>']:<EOL><INDENT>run_config_file = os.path.expanduser(config_file_name)... | Responsible for loading config files into ShutIt.
Recurses down from configured shutit module paths. | f10347:c2:m89 |
def get_base_config(self): | shutit_global.shutit_global_object.yield_to_draw()<EOL>cp = self.config_parser<EOL>self.build['<STR_LIT>'] = cp.getboolean('<STR_LIT>', '<STR_LIT>')<EOL>self.build['<STR_LIT>'] = cp.get('<STR_LIT>', '<STR_LIT>')<EOL>self.build['<STR_LIT>'] = cp.get('<STR_LIT>', '<STR_... | Responsible for getting core configuration from config files. | f10347:c2:m90 |
def load_all_from_path(self, path): | shutit_global.shutit_global_object.yield_to_draw()<EOL>path = os.path.abspath(path)<EOL>if os.path.abspath(path) == self.shutit_main_dir:<EOL><INDENT>return<EOL><DEDENT>if not os.path.exists(path):<EOL><INDENT>return<EOL><DEDENT>if os.path.exists(path + '<STR_LIT>') and not self.build['<STR_LIT>']:<EOL><INDENT>self.log... | Dynamically imports files within the same directory (in the end, the path). | f10347:c2:m91 |
def load_mod_from_file(self, fpath): | shutit_global.shutit_global_object.yield_to_draw()<EOL>fpath = os.path.abspath(fpath)<EOL>file_ext = os.path.splitext(os.path.split(fpath)[-<NUM_LIT:1>])[-<NUM_LIT:1>]<EOL>if file_ext.lower() != '<STR_LIT>':<EOL><INDENT>return<EOL><DEDENT>with open(fpath) as f:<EOL><INDENT>content = f.read().splitlines()<EOL><DEDENT>ok... | Loads modules from a .py file into ShutIt if there are no modules from
this file already.
We expect to have a callable 'module/0' which returns one or more module
objects.
If this doesn't exist we assume that the .py file works in the old style
(automatically inserting the module... | f10347:c2:m92 |
def config_collection_for_built(self, throw_error=True,silent=False): | shutit_global.shutit_global_object.yield_to_draw()<EOL>self.log('<STR_LIT>',level=logging.DEBUG)<EOL>cfg = self.cfg<EOL>for module_id in self.module_ids():<EOL><INDENT>if (self.is_to_be_built_or_is_installed(self.shutit_map[module_id]) and<EOL>not self.shutit_map[module_id].get_config(self)):<EOL><INDENT>self.fail(modu... | Collect configuration for modules that are being built.
When this is called we should know what's being built (ie after
dependency resolution). | f10347:c2:m93 |
def config_collection(self): | shutit_global.shutit_global_object.yield_to_draw()<EOL>self.log('<STR_LIT>',level=logging.DEBUG)<EOL>cfg = self.cfg<EOL>for module_id in self.module_ids():<EOL><INDENT>self.get_config(module_id, '<STR_LIT>', None, boolean=True, forcenone=True)<EOL>self.get_config(module_id, '<STR_LIT>', False, boolean=True)<EOL>self.ge... | Collect core config from config files for all seen modules. | f10347:c2:m94 |
def do_list_modules(self, long_output=None,sort_order=None): | shutit_global.shutit_global_object.yield_to_draw()<EOL>cfg = self.cfg<EOL>table_list = []<EOL>if long_output is None:<EOL><INDENT>long_output = self.list_modules['<STR_LIT>']<EOL><DEDENT>if sort_order is None:<EOL><INDENT>sort_order = self.list_modules['<STR_LIT>']<EOL><DEDENT>if long_output:<EOL><INDENT>table_list.app... | Display a list of loaded modules.
Config items:
- shutit.list_modules['long']
If set, also print each module's run order value
- shutit.list_modules['sort']
Select the column by which the list is ordered:
- id: sort th... | f10347:c2:m95 |
def print_config(self, cfg, hide_password=True, history=False, module_id=None): | shutit_global.shutit_global_object.yield_to_draw()<EOL>cp = self.config_parser<EOL>s = '<STR_LIT>'<EOL>keys1 = list(cfg.keys())<EOL>if keys1:<EOL><INDENT>keys1.sort()<EOL><DEDENT>for k in keys1:<EOL><INDENT>if module_id is not None and k != module_id:<EOL><INDENT>continue<EOL><DEDENT>if isinstance(k, str) and isinstanc... | Returns a string representing the config of this ShutIt run. | f10347:c2:m96 |
def process_args(self, args): | shutit_global.shutit_global_object.yield_to_draw()<EOL>assert isinstance(args,ShutItInit), shutit_util.print_debug()<EOL>if args.action == '<STR_LIT:version>':<EOL><INDENT>shutit_global.shutit_global_object.shutit_print('<STR_LIT>' + shutit.shutit_version)<EOL>shutit_global.shutit_global_object.handle_exit(exit_code=<N... | Process the args we have. 'args' is always a ShutItInit object. | f10347:c2:m97 |
def get_configs(self, configs): | shutit_global.shutit_global_object.yield_to_draw()<EOL>cp = LayerConfigParser()<EOL>fail_str = '<STR_LIT>'<EOL>files = []<EOL>for config_file in configs:<EOL><INDENT>if isinstance(config_file, tuple):<EOL><INDENT>continue<EOL><DEDENT>if not shutit_util.is_file_secure(config_file):<EOL><INDENT>fail_str = fail_str + ... | Reads config files in, checking their security first
(in case passwords/sensitive info is in them). | f10347:c2:m101 |
def parse_args(self): | shutit_global.shutit_global_object.yield_to_draw()<EOL>actions = ['<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT:version>']<EOL>if len(sys.argv) == <NUM_LIT:1> or (len(sys.argv) > <NUM_LIT:1> and sys.argv[<NUM_LIT:1>] not in actions<EOL>and '<STR_LIT>' not in sys.argv and '<STR_... | r"""Responsible for parsing arguments from the command line.
Environment variables:
SHUTIT_OPTIONS:
Loads command line options from the environment (if set).
Behaves like GREP_OPTIONS:
- space separated list of arguments
- backslash before a space escapes... | f10347:c2:m102 |
def check_deps(self): | shutit_global.shutit_global_object.yield_to_draw()<EOL>cfg = self.cfg<EOL>self.log('<STR_LIT>', level=logging.DEBUG)<EOL>self.pause_point('<STR_LIT>', print_input=False, level=<NUM_LIT:3>)<EOL>to_build = [<EOL>self.shutit_map[module_id] for module_id in self.shutit_map<EOL>if module_id in cfg and cfg[module_id]['<STR_L... | Dependency checking phase is performed in this method. | f10347:c2:m112 |
def check_conflicts(self): | shutit_global.shutit_global_object.yield_to_draw()<EOL>cfg = self.cfg<EOL>self.log('<STR_LIT>', level=logging.DEBUG)<EOL>errs = []<EOL>self.pause_point('<STR_LIT>', print_input=False, level=<NUM_LIT:3>)<EOL>for module_id in self.module_ids():<EOL><INDENT>if not cfg[module_id]['<STR_LIT>']:<EOL><INDENT>continue<EOL><DED... | Checks for any conflicts between modules configured to be built. | f10347:c2:m113 |
def check_ready(self, throw_error=True): | shutit_global.shutit_global_object.yield_to_draw()<EOL>cfg = self.cfg<EOL>self.log('<STR_LIT>', level=logging.DEBUG)<EOL>errs = []<EOL>self.pause_point('<STR_LIT>', print_input=False, level=<NUM_LIT:3>)<EOL>for module_id in self.module_ids():<EOL><INDENT>module = self.shutit_map[module_id]<EOL>self.log('<STR_LIT>' + mo... | Check that all modules are ready to be built, calling check_ready on
each of those configured to be built and not already installed
(see shutit.is_installed). | f10347:c2:m114 |
def do_remove(self, loglevel=logging.DEBUG): | shutit_global.shutit_global_object.yield_to_draw()<EOL>cfg = self.cfg<EOL>self.log('<STR_LIT>', level=loglevel)<EOL>self.pause_point('<STR_LIT>', print_input=False, level=<NUM_LIT:3>)<EOL>for module_id in self.module_ids():<EOL><INDENT>module = self.shutit_map[module_id]<EOL>self.log('<STR_LIT>' + module_id, level=logg... | Remove modules by calling remove method on those configured for removal. | f10347:c2:m115 |
def build_module(self, module, loglevel=logging.DEBUG): | shutit_global.shutit_global_object.yield_to_draw()<EOL>cfg = self.cfg<EOL>self.log('<STR_LIT>' + module.module_id + '<STR_LIT>' + str(module.run_order), level=logging.INFO)<EOL>self.build['<STR_LIT>'] = (self.build['<STR_LIT>'] + '<STR_LIT>' + module.module_id + '<STR_LIT>' + str(module.run_order))<EOL>if not module.bu... | Build passed-in module. | f10347:c2:m116 |
def do_build(self): | shutit_global.shutit_global_object.yield_to_draw()<EOL>cfg = self.cfg<EOL>self.log('<STR_LIT>', level=logging.DEBUG)<EOL>module_id_list = self.module_ids()<EOL>if self.build['<STR_LIT>']:<EOL><INDENT>module_id_list_build_only = filter(lambda x: cfg[x]['<STR_LIT>'], module_id_list)<EOL><DEDENT>for module_id in module_id... | Runs build phase, building any modules that we've determined
need building. | f10347:c2:m117 |
def do_finalize(self): | shutit_global.shutit_global_object.yield_to_draw()<EOL>def _finalize(self):<EOL><INDENT>self.stop_all()<EOL>self.log('<STR_LIT>' + str(self), level=logging.DEBUG)<EOL>for module_id in self.module_ids(rev=True):<EOL><INDENT>if self.is_installed(self.shutit_map[module_id]):<EOL><INDENT>self.login(prompt_prefix=module_id,... | Runs finalize phase; run after all builds are complete and all modules
have been stopped. | f10347:c2:m119 |
def stop_all(self, run_order=-<NUM_LIT:1>): | shutit_global.shutit_global_object.yield_to_draw()<EOL>for module_id in self.module_ids(rev=True):<EOL><INDENT>shutit_module_obj = self.shutit_map[module_id]<EOL>if run_order == -<NUM_LIT:1> or shutit_module_obj.run_order <= run_order:<EOL><INDENT>if self.is_installed(shutit_module_obj):<EOL><INDENT>if not shutit_modul... | Runs stop method on all modules less than the passed-in run_order.
Used when target is exporting itself mid-build, so we clean up state
before committing run files etc. | f10347:c2:m120 |
def start_all(self, run_order=-<NUM_LIT:1>): | shutit_global.shutit_global_object.yield_to_draw()<EOL>for module_id in self.module_ids():<EOL><INDENT>shutit_module_obj = self.shutit_map[module_id]<EOL>if run_order == -<NUM_LIT:1> or shutit_module_obj.run_order <= run_order:<EOL><INDENT>if self.is_installed(shutit_module_obj):<EOL><INDENT>if not shutit_module_obj.st... | Runs start method on all modules less than the passed-in run_order.
Used when target is exporting itself mid-build, so we can export a clean
target and still depended-on modules running if necessary. | f10347:c2:m121 |
def is_ready(self, shutit_module_obj): | shutit_global.shutit_global_object.yield_to_draw()<EOL>if shutit_module_obj.module_id in self.get_current_shutit_pexpect_session_environment().modules_ready:<EOL><INDENT>self.log('<STR_LIT>',level=logging.DEBUG)<EOL>return True<EOL><DEDENT>ready = shutit_module_obj.check_ready(self)<EOL>if ready:<EOL><INDENT>self.get_c... | Returns true if this module is ready to be built.
Caches the result (as it's assumed not to change during the build). | f10347:c2:m122 |
def init_shutit_map(self): | shutit_global.shutit_global_object.yield_to_draw()<EOL>modules = self.shutit_modules<EOL>if len([mod for mod in modules if mod.run_order > <NUM_LIT:0>]) < <NUM_LIT:1>:<EOL><INDENT>self.log(modules,level=logging.DEBUG)<EOL>path = '<STR_LIT::>'.join(self.host['<STR_LIT>'])<EOL>self.log('<STR_LIT>',level=logging.INFO)<EOL... | Initializes the module map of shutit based on the modules
we have gathered.
Checks we have core modules
Checks for duplicate module details.
Sets up common config.
Sets up map of modules. | f10347:c2:m123 |
def conn_target(self): | shutit_global.shutit_global_object.yield_to_draw()<EOL>conn_module = None<EOL>for mod in self.conn_modules:<EOL><INDENT>if mod.module_id == self.build['<STR_LIT>']:<EOL><INDENT>conn_module = mod<EOL>break<EOL><DEDENT><DEDENT>if conn_module is None:<EOL><INDENT>self.fail('<STR_LIT>' + self.build['<STR_LIT>']) <EOL><DEDE... | Connect to the target. | f10347:c2:m124 |
def finalize_target(self): | shutit_global.shutit_global_object.yield_to_draw()<EOL>self.pause_point('<STR_LIT>' + self.shutit_main_dir + '<STR_LIT>', print_input=False, level=<NUM_LIT:3>)<EOL>for mod in self.conn_modules:<EOL><INDENT>if mod.module_id == self.build['<STR_LIT>']:<EOL><INDENT>conn_module = mod<EOL>break<EOL><DEDENT><DEDENT>conn_modu... | Finalize the target using the core finalize method. | f10347:c2:m125 |
def resolve_dependencies(self, to_build, depender): | shutit_global.shutit_global_object.yield_to_draw()<EOL>self.log('<STR_LIT>',level=logging.DEBUG)<EOL>cfg = self.cfg<EOL>for dependee_id in depender.depends_on:<EOL><INDENT>dependee = self.shutit_map.get(dependee_id)<EOL>if (dependee and dependee not in to_build<EOL>and cfg[dependee_id]['<STR_LIT>']):<EOL><INDENT>to_bui... | Add any required dependencies. | f10347:c2:m126 |
def check_dependee_exists(self, depender, dependee, dependee_id): | shutit_global.shutit_global_object.yield_to_draw()<EOL>if dependee is None:<EOL><INDENT>return '<STR_LIT>' + dependee_id + '<STR_LIT>' + str(self.host['<STR_LIT>']) + '<STR_LIT>' + depender.module_id + '<STR_LIT>'<EOL><DEDENT>return '<STR_LIT>'<EOL> | Checks whether a depended-on module is available. | f10347:c2:m127 |
def check_dependee_build(self, depender, dependee, dependee_id): | shutit_global.shutit_global_object.yield_to_draw()<EOL>cfg = self.cfg<EOL>if not (cfg[dependee.module_id]['<STR_LIT>'] or<EOL>self.is_to_be_built_or_is_installed(dependee)):<EOL><INDENT>return '<STR_LIT>' + depender.module_id + '<STR_LIT>' + dependee_id + '<STR_LIT>'<EOL><DEDENT>return '<STR_LIT>'<EOL> | Checks whether a depended on module is configured to be built. | f10347:c2:m128 |
def destroy(self): | if self.session_type == '<STR_LIT>':<EOL><INDENT>self.logout()<EOL><DEDENT>elif self.session_type == '<STR_LIT>':<EOL><INDENT>self.logout()<EOL><DEDENT> | Finish up a session. | f10347:c2:m134 |
def add_shutit_pexpect_session_environment(pexpect_session_environment): | shutit_global.shutit_global_object.shutit_pexpect_session_environments.add(pexpect_session_environment)<EOL> | Adds an environment object to a shutit_pexpect_session object. | f10349:m0 |
def __init__(self,<EOL>shutit,<EOL>pexpect_session_id,<EOL>command,<EOL>args=None,<EOL>timeout=shutit_global.shutit_global_object.default_timeout,<EOL>maxread=<NUM_LIT>,<EOL>searchwindowsize=None,<EOL>env=None,<EOL>ignore_sighup=False,<EOL>echo=True,<EOL>preexec_fn=None,<EOL>encoding=None,<EOL>codec_errors='<STR_LIT:st... | <EOL>if not encoding and shutit_global.shutit_global_object.ispy3: <EOL><INDENT>encoding = shutit_global.shutit_global_object.default_encoding<EOL><DEDENT>assert isinstance(shutit, shutit_class.ShutIt), shutit_util.print_debug()<EOL>self.shutit = shutit<EOL>self.check_exit = True<EOL>s... | spawn a child, and manage the delaybefore send setting to 0 | f10349:c0:m0 |
def _spawn_child(self,<EOL>command,<EOL>args=None,<EOL>timeout=shutit_global.shutit_global_object.default_timeout,<EOL>maxread=<NUM_LIT>,<EOL>searchwindowsize=None,<EOL>env=None,<EOL>ignore_sighup=False,<EOL>echo=True,<EOL>preexec_fn=None,<EOL>encoding=None,<EOL>codec_errors='<STR_LIT:strict>',<EOL>dimensions=None,<EOL... | shutit = self.shutit<EOL>args = args or []<EOL>pexpect_child = pexpect.spawn(command,<EOL>args=args,<EOL>timeout=timeout,<EOL>maxread=maxread,<EOL>searchwindowsize=searchwindowsize,<EOL>env=env,<EOL>ignore_sighup=ignore_sighup,<EOL>echo=echo,<EOL>preexec_fn=preexec_fn,<EOL>encoding=encoding,<EOL>codec_errors=codec_erro... | spawn a child, and manage the delaybefore send setting to 0 | f10349:c0:m2 |
def sendline(self, sendspec): | assert not sendspec.started, shutit_util.print_debug()<EOL>shutit = self.shutit<EOL>shutit.log('<STR_LIT>' + str(id(self)) + '<STR_LIT>' + str(sendspec.send), level=logging.DEBUG)<EOL>if sendspec.expect:<EOL><INDENT>shutit.log('<STR_LIT>' + str(sendspec.expect), level=logging.DEBUG)<EOL><DEDENT>else:<EOL><INDENT>shutit... | Sends line, handling background and newline directives.
True means: 'all handled here ok'
False means: you'll need to 'expect' the right thing from here. | f10349:c0:m3 |
def wait(self, cadence=<NUM_LIT:2>, sendspec=None): | shutit = self.shutit<EOL>shutit.log('<STR_LIT>', level=logging.DEBUG)<EOL>if sendspec:<EOL><INDENT>cadence = sendspec.wait_cadence<EOL><DEDENT>shutit.log('<STR_LIT>' + str(self.login_stack), level=logging.DEBUG)<EOL>while True:<EOL><INDENT>res, res_str, background_object = self.login_stack.get_current_login_item().chec... | Does not return until all background commands are completed. | f10349:c0:m5 |
def login(self, sendspec): | user = sendspec.user<EOL>command = sendspec.send<EOL>prompt_prefix = sendspec.prompt_prefix<EOL>shutit = self.shutit<EOL>if isinstance(sendspec.password,str):<EOL><INDENT>shutit_global.shutit_global_object.secret_words_set.add(sendspec.password)<EOL><DEDENT>r_id = shutit_util.random_id()<EOL>if prompt_pr... | Logs the user in with the passed-in password and command.
Tracks the login. If used, used logout to log out again.
Assumes you are root when logging in, so no password required.
If not, override the default command for multi-level logins.
If passwords are required, see setup_prompt() and... | f10349:c0:m6 |
def logout_all(self, sendspec): | while self.login_stack.length() > <NUM_LIT:0>:<EOL><INDENT>self.logout(sendspec)<EOL><DEDENT> | Completely logs the user out of all logins in this pexpect session | f10349:c0:m7 |
def logout(self, sendspec): | <EOL>self.wait()<EOL>shutit = self.shutit<EOL>shutit.handle_note(sendspec.note,training_input=sendspec.send)<EOL>if self.login_stack.length() > <NUM_LIT:0>:<EOL><INDENT>_ = self.login_stack.pop()<EOL>if self.login_stack.length() > <NUM_LIT:0>:<EOL><INDENT>old_prompt_name = self.login_stack.get_current_login_id()<EOL>s... | Logs the user out. Assumes that login has been called.
If login has never been called, throw an error.
@param command: Command to run to log out (default=exit)
@param note: See send() | f10349:c0:m8 |
def setup_prompt(self,<EOL>prompt_name,<EOL>prefix='<STR_LIT:default>',<EOL>capture_exit_code=False,<EOL>loglevel=logging.DEBUG): | shutit = self.shutit<EOL>local_prompt = prefix + '<STR_LIT::>' + shutit_util.random_id() + '<STR_LIT>'<EOL>shutit.expect_prompts[prompt_name] = local_prompt<EOL>shutit.log('<STR_LIT>', level=logging.DEBUG)<EOL>send_str = '<STR_LIT>'<EOL>if capture_exit_code:<EOL><INDENT>send_str = r'<STR_LIT>'<EOL><DEDENT>send_str += "... | Use this when you've opened a new shell to set the PS1 to something
sane. By default, it sets up the default expect so you don't have to
worry about it and can just call shutit.send('a command').
If you want simple login and logout, please use login() and logout()
within this module.
... | f10349:c0:m9 |
def revert_prompt(self,<EOL>old_prompt_name,<EOL>new_expect=None): | shutit = self.shutit<EOL>expect = new_expect or self.default_expect<EOL>self.send(ShutItSendSpec(self,<EOL>send=('<STR_LIT>') % (old_prompt_name, old_prompt_name),<EOL>expect=expect,<EOL>check_exit=False,<EOL>fail_on_empty_before=False,<EOL>echo=False,<EOL>loglevel=logging.DEBUG,<EOL>ignore_background=True))<EOL>if not... | Reverts the prompt to the previous value (passed-in).
It should be fairly rare to need this. Most of the time you would just
exit a subshell rather than resetting the prompt.
- old_prompt_name -
- new_expect -
- child - See send() | f10349:c0:m10 |
def expect(self,<EOL>expect,<EOL>searchwindowsize=None,<EOL>maxread=None,<EOL>timeout=None,<EOL>iteration_n=<NUM_LIT:1>): | if isinstance(expect, str):<EOL><INDENT>expect = [expect]<EOL><DEDENT>if searchwindowsize != None:<EOL><INDENT>old_searchwindowsize = self.pexpect_child.searchwindowsize<EOL>self.pexpect_child.searchwindowsize = searchwindowsize<EOL><DEDENT>if maxread != None:<EOL><INDENT>old_maxread = self.pexpect_child.maxread<EOL>se... | Handle child expects, with EOF and TIMEOUT handled
iteration_n - Number of times this expect has been called for the send.
If 1, (the default) then it gets added to the pane of output
(if applicable to this run) | f10349:c0:m11 |
def replace_container(self, new_target_image_name, go_home=None): | shutit = self.shutit<EOL>shutit.log('<STR_LIT>' + new_target_image_name + '<STR_LIT>', level=logging.DEBUG)<EOL>shutit.log(shutit.print_session_state(), level=logging.DEBUG)<EOL>conn_module = None<EOL>for mod in shutit.conn_modules:<EOL><INDENT>if mod.module_id == shutit.build['<STR_LIT>']:<EOL><INDENT>conn_module = mo... | Replaces a container. Assumes we are in Docker context. | f10349:c0:m12 |
def whoami(self,<EOL>note=None,<EOL>loglevel=logging.DEBUG): | shutit = self.shutit<EOL>shutit.handle_note(note)<EOL>res = self.send_and_get_output('<STR_LIT>',<EOL>echo=False,<EOL>loglevel=loglevel).strip()<EOL>if res == '<STR_LIT>':<EOL><INDENT>res = self.send_and_get_output('<STR_LIT>',<EOL>echo=False,<EOL>loglevel=loglevel).strip()<EOL><DEDENT>shutit.handle_note_after(note=not... | Returns the current user by executing "whoami".
@param note: See send()
@return: the output of "whoami"
@rtype: string | f10349:c0:m13 |
def check_last_exit_values(self,<EOL>send,<EOL>check_exit=True,<EOL>expect=None,<EOL>exit_values=None,<EOL>retry=<NUM_LIT:0>,<EOL>retbool=False): | shutit = self.shutit<EOL>expect = expect or self.default_expect<EOL>if not self.check_exit or not check_exit:<EOL><INDENT>shutit.log('<STR_LIT>', level=logging.DEBUG)<EOL>return True<EOL><DEDENT>if exit_values is None:<EOL><INDENT>exit_values = ['<STR_LIT:0>']<EOL><DEDENT>if isinstance(exit_values, int):<EOL><INDENT>ex... | Internal function to check the exit value of the shell. Do not use. | f10349:c0:m14 |
def pause_point(self,<EOL>msg='<STR_LIT>',<EOL>print_input=True,<EOL>resize=True,<EOL>color='<STR_LIT>',<EOL>default_msg=None,<EOL>interact=False,<EOL>wait=-<NUM_LIT:1>): | shutit = self.shutit<EOL>if shutit.build['<STR_LIT>'] and shutit.loglevel not in ('<STR_LIT>',):<EOL><INDENT>self.send(ShutItSendSpec(self,<EOL>send='<STR_LIT>',<EOL>echo=False,<EOL>record_command=False,<EOL>ignore_background=True))<EOL><DEDENT>if self.in_shell:<EOL><INDENT>self.send(ShutItSendSpec(self,<EOL>send='<STR... | Inserts a pause in the build session, which allows the user to try
things out before continuing. Ignored if we are not in an interactive
mode.
Designed to help debug the build, or drop to on failure so the
situation can be debugged.
@param msg: Message to display to use... | f10349:c0:m15 |
def file_exists(self,<EOL>filename,<EOL>directory=False,<EOL>note=None,<EOL>loglevel=logging.DEBUG): | shutit = self.shutit<EOL>shutit.handle_note(note, '<STR_LIT>' + filename)<EOL>test_type = '<STR_LIT>' if directory is True else '<STR_LIT>' if directory is None else '<STR_LIT>'<EOL>test = '<STR_LIT>' % (test_type, filename)<EOL>output = self.send_and_get_output(test + '<STR_LIT>',<EOL>record_command=False,<EOL>echo=Fa... | Return True if file exists on the target host, else False
@param filename: Filename to determine the existence of.
@param directory: Indicate that the file is a directory.
@param note: See send()
@type filename: string
@type directory: boolean
@rtype: boo... | f10349:c0:m17 |
def chdir(self,<EOL>path,<EOL>timeout=shutit_global.shutit_global_object.default_timeout,<EOL>note=None,<EOL>loglevel=logging.DEBUG): | shutit = self.shutit<EOL>shutit.handle_note(note, '<STR_LIT>' + path)<EOL>shutit.log('<STR_LIT>' + path + '<STR_LIT:">', level=logging.DEBUG)<EOL>if shutit.build['<STR_LIT>'] in ('<STR_LIT>','<STR_LIT>'):<EOL><INDENT>self.send(ShutItSendSpec(self,<EOL>send='<STR_LIT>' + path + '<STR_LIT:">',<EOL>timeout=timeout,<EOL>ec... | How to change directory will depend on whether we are in delivery mode bash or docker.
@param path: Path to send file to.
@param timeout: Timeout on response
@param note: See send() | f10349:c0:m18 |
def get_file_perms(self,<EOL>filename,<EOL>note=None,<EOL>loglevel=logging.DEBUG): | shutit = self.shutit<EOL>shutit.handle_note(note)<EOL>cmd = '<STR_LIT>' + filename<EOL>self.send(ShutItSendSpec(self,<EOL>send='<STR_LIT:U+0020>' + cmd,<EOL>check_exit=False,<EOL>echo=False,<EOL>loglevel=loglevel,<EOL>ignore_background=True))<EOL>res = shutit.match_string(self.pexpect_child.before, '<STR_LIT>')<EOL>shu... | Returns the permissions of the file on the target as an octal
string triplet.
@param filename: Filename to get permissions of.
@param note: See send()
@type filename: string
@rtype: string | f10349:c0:m19 |
def add_to_bashrc(self,<EOL>line,<EOL>match_regexp=None,<EOL>note=None,<EOL>loglevel=logging.DEBUG): | shutit = self.shutit<EOL>shutit.handle_note(note)<EOL>if not shutit_util.check_regexp(match_regexp):<EOL><INDENT>shutit.fail('<STR_LIT>' + match_regexp) <EOL><DEDENT>if self.whoami() == '<STR_LIT:root>':<EOL><INDENT>shutit.add_line_to_file(line, '<STR_LIT>', match_regexp=match_regexp, loglevel=loglevel)<EOL><DEDENT>els... | Takes care of adding a line to everyone's bashrc
(/etc/bash.bashrc).
@param line: Line to add.
@param match_regexp: See add_line_to_file()
@param note: See send()
@return: See add_line_to_file() | f10349:c0:m20 |
def is_user_id_available(self,<EOL>user_id,<EOL>note=None,<EOL>loglevel=logging.DEBUG): | shutit = self.shutit<EOL>shutit.handle_note(note)<EOL>self.send(ShutItSendSpec(self,<EOL>send='<STR_LIT>' + user_id + '<STR_LIT>',<EOL>expect=self.default_expect,<EOL>echo=False,<EOL>loglevel=loglevel,<EOL>ignore_background=True))<EOL>shutit.handle_note_after(note=note)<EOL>if shutit.match_string(self.pexpect_child.bef... | Determine whether the specified user_id available.
@param user_id: User id to be checked.
@param note: See send()
@type user_id: integer
@rtype: boolean
@return: True is the specified user id is not used yet, False if it's already been assigned to a use... | f10349:c0:m21 |
def set_password(self,<EOL>password,<EOL>user='<STR_LIT>',<EOL>note=None): | shutit = self.shutit<EOL>shutit.handle_note(note)<EOL>if isinstance(password, str):<EOL><INDENT>shutit_global.shutit_global_object.secret_words_set.add(password)<EOL><DEDENT>self.install('<STR_LIT>')<EOL>if self.current_environment.install_type == '<STR_LIT>':<EOL><INDENT>self.send(ShutItSendSpec(self,<EOL>send='<STR_L... | Sets the password for the current user or passed-in user.
As a side effect, installs the "password" package.
@param user: username to set the password for. Defaults to '' (i.e. current user)
@param password: password to set for the user
@param note: See send() | f10349:c0:m22 |
def lsb_release(self,<EOL>loglevel=logging.DEBUG): | <EOL>shutit = self.shutit<EOL>d = {}<EOL>self.send(ShutItSendSpec(self,<EOL>send='<STR_LIT>',<EOL>check_exit=False,<EOL>echo=False,<EOL>loglevel=loglevel,<EOL>ignore_background=True))<EOL>res = shutit.match_string(self.pexpect_child.before, r'<STR_LIT>')<EOL>if isinstance(res, str):<EOL><INDENT>dist_string = res<EOL>d[... | Get distro information from lsb_release. | f10349:c0:m23 |
def get_url(self,<EOL>filename,<EOL>locations,<EOL>command='<STR_LIT>',<EOL>timeout=shutit_global.shutit_global_object.default_timeout,<EOL>fail_on_empty_before=True,<EOL>record_command=True,<EOL>exit_values=None,<EOL>retry=<NUM_LIT:3>,<EOL>note=None,<EOL>loglevel=logging.DEBUG): | shutit = self.shutit<EOL>shutit.handle_note(note)<EOL>if not locations or not isinstance(locations, list):<EOL><INDENT>raise ShutItFailException('<STR_LIT>')<EOL><DEDENT>retry_orig = retry<EOL>if not self.command_available(command):<EOL><INDENT>self.install('<STR_LIT>')<EOL>if not self.command_available('<STR_LIT>'):<E... | Handles the getting of a url for you.
Example:
get_url('somejar.jar', ['ftp://loc.org','http://anotherloc.com/jars'])
@param filename: name of the file to download
@param locations: list of URLs whence the file can be downloaded
@param command: ... | f10349:c0:m24 |
def user_exists(self,<EOL>user,<EOL>note=None,<EOL>loglevel=logging.DEBUG): | shutit = self.shutit<EOL>shutit.handle_note(note)<EOL>exists = False<EOL>if user == '<STR_LIT>':<EOL><INDENT>return exists<EOL><DEDENT>ret = self.send(ShutItSendSpec(self,<EOL>send='<STR_LIT>' % user,<EOL>expect=['<STR_LIT>', '<STR_LIT>'],<EOL>echo=False,<EOL>loglevel=loglevel,<EOL>ignore_background=True))<EOL>if ret:<... | Returns true if the specified username exists.
@param user: username to check for
@param note: See send()
@type user: string
@rtype: boolean | f10349:c0:m25 |
def package_installed(self,<EOL>package,<EOL>note=None,<EOL>echo=False,<EOL>loglevel=logging.DEBUG): | shutit = self.shutit<EOL>shutit.handle_note(note)<EOL>if self.current_environment.install_type == '<STR_LIT>':<EOL><INDENT>return self.send_and_get_output('<STR_LIT>' + package + """<STR_LIT>""", loglevel=loglevel, echo=echo) == '<STR_LIT:1>'<EOL><DEDENT>elif self.current_environment.install_type == '<STR_LIT>':<EOL><I... | Returns True if we can be sure the package is installed.
@param package: Package as a string, eg 'wget'.
@param note: See send()
@rtype: boolean | f10349:c0:m26 |
def is_shutit_installed(self,<EOL>module_id,<EOL>note=None,<EOL>loglevel=logging.DEBUG): | <EOL>shutit = self.shutit<EOL>shutit.handle_note(note)<EOL>if not self.current_environment.modules_recorded_cache_valid:<EOL><INDENT>if self.file_exists(shutit_global.shutit_global_object.shutit_state_dir_build_db_dir + '<STR_LIT>',directory=True):<EOL><INDENT>tmpid = shutit_util.random_id()<EOL>cmd = '<STR_LIT>' + shu... | Helper proc to determine whether shutit has installed already here by placing a file in the db.
@param module_id: Identifying string of shutit module
@param note: See send() | f10349:c0:m28 |
def ls(self,<EOL>directory,<EOL>note=None,<EOL>loglevel=logging.DEBUG): | shutit = self.shutit<EOL>shutit.handle_note(note)<EOL>if not self.file_exists(directory,directory=True):<EOL><INDENT>shutit.fail('<STR_LIT>' + directory + '<STR_LIT>', throw_exception=False) <EOL><DEDENT>files = self.send_and_get_output('<STR_LIT>' + directory,<EOL>echo=False,<EOL>loglevel=loglevel,<EOL>fail_on_empty_b... | Helper proc to list files in a directory
@param directory: directory to list. If the directory doesn't exist, shutit.fail() is called (i.e. the build fails.)
@param note: See send()
@type directory: string
@rtype: list of strings | f10349:c0:m29 |
def install(self,<EOL>package,<EOL>options=None,<EOL>timeout=shutit_global.shutit_global_object.default_timeout,<EOL>force=False,<EOL>check_exit=True,<EOL>echo=None,<EOL>reinstall=False,<EOL>run_in_background=False,<EOL>ignore_background=False,<EOL>block_other_commands=True,<EOL>note=None,<EOL>loglevel=logging.INFO): | shutit = self.shutit<EOL>if package.find('<STR_LIT:U+0020>') != -<NUM_LIT:1>:<EOL><INDENT>ok = True<EOL>for p in package.split('<STR_LIT:U+0020>'):<EOL><INDENT>if not self.install(p,options,timeout,force,check_exit,reinstall,note):<EOL><INDENT>ok = False<EOL><DEDENT><DEDENT>return ok<EOL><DEDENT>if note != None:<EOL><I... | Distro-independent install function.
Takes a package name and runs the relevant install function.
@param package: Package to install, which is run through package_map
@param timeout: Timeout (s) to wait for finish of install. Defaults to 3600.
@param options: Dictionary for spe... | f10349:c0:m30 |
def reset_terminal(self): | shutit = self.shutit<EOL>shutit.log('<STR_LIT>', level=logging.DEBUG)<EOL>self.pexpect_child.sendline()<EOL>time.sleep(<NUM_LIT:0.1>)<EOL>try:<EOL><INDENT>self.pexpect_child.read_nonblocking(size=<NUM_LIT>,timeout=<NUM_LIT:1>)<EOL><DEDENT>except pexpect.TIMEOUT:<EOL><INDENT>pass<EOL><DEDENT>time.sleep(<NUM_LIT:0.1>)<EO... | Resets the terminal to as good a state as we can try.
Tries to ensure that we have 'expect'ed the last prompt seen.
TODO: see how https://github.com/noahspurrier/pexpect/blob/master/pxssh.py handles this | f10349:c0:m31 |
def levenshtein_distance(self, a,b): | n, m = len(a), len(b)<EOL>if n > m:<EOL><INDENT>a,b = b,a<EOL>n,m = m,n<EOL><DEDENT>current = range(n+<NUM_LIT:1>)<EOL>for i in range(<NUM_LIT:1>,m+<NUM_LIT:1>):<EOL><INDENT>previous, current = current, [i]+[<NUM_LIT:0>]*n<EOL>for j in range(<NUM_LIT:1>,n+<NUM_LIT:1>):<EOL><INDENT>add, delete = previous[j]+<NUM_LIT:1>,... | This calculates the Levenshtein distance between a and b. | f10349:c0:m32 |
def get_memory(self, note=None): | shutit = self.shutit<EOL>shutit.handle_note(note)<EOL>if self.current_environment.distro == '<STR_LIT>':<EOL><INDENT>memavail = self.send_and_get_output("""<STR_LIT>""",<EOL>timeout=<NUM_LIT:3>,<EOL>echo=False)<EOL>memavail = int(memavail)<EOL>memavail *= <NUM_LIT:4><EOL><DEDENT>else:<EOL><INDENT>memavail = self.send_a... | Returns memory available for use in k as an int | f10349:c0:m33 |
def remove(self,<EOL>package,<EOL>echo=None,<EOL>options=None,<EOL>timeout=shutit_global.shutit_global_object.default_timeout,<EOL>note=None): | <EOL>shutit = self.shutit<EOL>if note != None:<EOL><INDENT>shutit.handle_note('<STR_LIT>' + package + '<STR_LIT:\n>' + note)<EOL><DEDENT>if options is None: options = {}<EOL>install_type = self.current_environment.install_type<EOL>cmd = '<STR_LIT>'<EOL>if install_type == '<STR_LIT:src>':<EOL><INDENT>return True<EOL><DE... | Distro-independent remove function.
Takes a package name and runs relevant remove function.
@param package: Package to remove, which is run through package_map.
@param options: Dict of options to pass to the remove command,
mapped by install_type.
@param timeo... | f10349:c0:m34 |
def send_and_match_output(self,<EOL>send,<EOL>matches,<EOL>retry=<NUM_LIT:3>,<EOL>strip=True,<EOL>note=None,<EOL>echo=False,<EOL>loglevel=logging.DEBUG): | shutit = self.shutit<EOL>shutit.handle_note(note)<EOL>shutit.log('<STR_LIT>' + send + '<STR_LIT>' + str(matches), level=logging.INFO)<EOL>echo = shutit.get_echo_override(echo)<EOL>output = self.send_and_get_output(send,<EOL>retry=retry,<EOL>strip=strip,<EOL>echo=echo,<EOL>loglevel=loglevel)<EOL>if isinstance(matches, s... | Returns true if the output of the command matches any of the strings in
the matches list of regexp strings. Handles matching on a per-line basis
and does not cross lines.
@param send: See send()
@param matches: String - or list of strings - of regexp(s) to check
@param retr... | f10349:c0:m35 |
def send_and_get_output(self,<EOL>send,<EOL>timeout=None,<EOL>retry=<NUM_LIT:3>,<EOL>strip=True,<EOL>preserve_newline=False,<EOL>note=None,<EOL>record_command=True,<EOL>echo=None,<EOL>fail_on_empty_before=True,<EOL>check_sudo=True,<EOL>nonewline=False,<EOL>ignore_background=False,<EOL>filter_backspaces=True,<EOL>loglev... | shutit = self.shutit<EOL>shutit.handle_note(note, command=str(send))<EOL>shutit.log('<STR_LIT>' + send, level=loglevel)<EOL>echo = shutit.get_echo_override(echo)<EOL>send = shutit.get_send_command(send)<EOL>self.send(ShutItSendSpec(self,<EOL>send=send,<EOL>check_exit=False,<EOL>retry=retry,<EOL>echo=echo,<EOL>timeout=t... | Returns the output of a command run. send() is called, and exit is not checked.
@param send: See send()
@param retry: Number of times to retry command (default 3)
@param strip: Whether to strip output (defaults to True). Strips whitespace
and ansi terminal cod... | f10349:c0:m36 |
def get_env_pass(self,user=None,msg=None,note=None): | shutit = self.shutit<EOL>shutit.handle_note(note)<EOL>user = user or self.whoami()<EOL>pw = '<STR_LIT>'<EOL>if self.current_environment.distro == '<STR_LIT>':<EOL><INDENT>return pw<EOL><DEDENT>if user not in self.current_environment.users.keys():<EOL><INDENT>self.current_environment.users.update({user:None})<EOL><DEDEN... | Gets a password from the user if one is not already recorded for this environment.
@param user: username we are getting password for
@param msg: message to put out there | f10349:c0:m37 |
def whoarewe(self,<EOL>note=None,<EOL>loglevel=logging.DEBUG): | shutit = self.shutit<EOL>shutit.handle_note(note)<EOL>res = self.send_and_get_output('<STR_LIT>',<EOL>echo=False,<EOL>loglevel=loglevel).strip()<EOL>shutit.handle_note_after(note=note)<EOL>return res<EOL> | Returns the current group.
@param note: See send()
@return: the first group found
@rtype: string | f10349:c0:m38 |
def get_distro_info(self, loglevel=logging.DEBUG): | shutit = self.shutit<EOL>install_type = '<STR_LIT>'<EOL>distro = '<STR_LIT>'<EOL>distro_version = '<STR_LIT>'<EOL>if shutit.build['<STR_LIT>'] != '<STR_LIT>':<EOL><INDENT>key = shutit.build['<STR_LIT>']<EOL>distro = shutit.build['<STR_LIT>']<EOL>install_type = package_map.INSTALL_TYPE_MAP[key]<EOL>distro_vers... | Get information about which distro we are using, placing it in the environment object.
Fails if distro could not be determined.
Should be called with the container is started up, and uses as core info
as possible.
Note: if the install type is apt, it issues the following:
-... | f10349:c0:m39 |
def multisend(self, sendspec): | shutit = self.shutit<EOL>shutit.handle_note(sendspec.note)<EOL>expect = sendspec.expect or self.default_expect<EOL>send_iteration = sendspec.send<EOL>expect_list = list(sendspec.send_dict)<EOL>n_breakout_items = <NUM_LIT:0><EOL>shutit.log('<STR_LIT>' + sendspec.send, level=logging.DEBUG)<EOL>if isinsta... | Multisend. Same as send, except it takes multiple sends and expects in a dict that are
processed while waiting for the end "expect" argument supplied.
@param send: See send()
@param send_dict: See ShutItSendSpec
@param expect: See send()
... | f10349:c0:m40 |
def send_and_require(self,<EOL>send,<EOL>regexps,<EOL>not_there=False,<EOL>echo=None,<EOL>note=None,<EOL>loglevel=logging.INFO): | shutit = self.shutit<EOL>echo = shutit.get_echo_override(echo)<EOL>return self.send_until(send,<EOL>regexps,<EOL>not_there=not_there,<EOL>cadence=<NUM_LIT:0>,<EOL>retries=<NUM_LIT:1>,<EOL>echo=echo,<EOL>note=note,<EOL>loglevel=loglevel)<EOL> | Send string and require the item in the output.
See send_until | f10349:c0:m41 |
def send_until(self,<EOL>send,<EOL>regexps,<EOL>not_there=False,<EOL>cadence=<NUM_LIT:2>,<EOL>retries=<NUM_LIT:100>,<EOL>echo=None,<EOL>note=None,<EOL>debug_command=None,<EOL>pause_point_on_fail=True,<EOL>nonewline=False,<EOL>loglevel=logging.INFO): | shutit = self.shutit<EOL>shutit.handle_note(note, command=send + '<STR_LIT>' + str(regexps))<EOL>shutit.log('<STR_LIT>' + send + '<STR_LIT>' + str(regexps), level=loglevel)<EOL>if isinstance(regexps, str):<EOL><INDENT>regexps = [regexps]<EOL><DEDENT>if not isinstance(regexps, list):<EOL><INDENT>shutit.fail('<STR_LIT>')... | Send string on a regular cadence until a string is either seen, or the timeout is triggered.
@param send: See send()
@param regexps: List of regexps to wait for.
@param not_there: If True, wait until this a regexp is not seen in the output. If False
... | f10349:c0:m42 |
def change_text(self,<EOL>text,<EOL>fname,<EOL>pattern=None,<EOL>before=False,<EOL>force=False,<EOL>delete=False,<EOL>note=None,<EOL>replace=False,<EOL>line_oriented=True,<EOL>create=True,<EOL>loglevel=logging.DEBUG): | shutit = self.shutit<EOL>shutit.handle_note(note)<EOL>fexists = self.file_exists(fname)<EOL>if not fexists:<EOL><INDENT>if create:<EOL><INDENT>self.send(ShutItSendSpec(self,<EOL>send='<STR_LIT>' + fname,<EOL>echo=False,<EOL>loglevel=loglevel,<EOL>ignore_background=True))<EOL><DEDENT>else:<EOL><INDENT>shutit.fail(fname ... | Change text in a file.
Returns None if there was no match for the regexp, True if it was matched
and replaced, and False if the file did not exist or there was some other
problem.
@param text: Text to insert.
@param fname: Filename to insert text to
@pa... | f10349:c0:m43 |
def remove_line_from_file(self,<EOL>line,<EOL>filename,<EOL>match_regexp=None,<EOL>literal=False,<EOL>note=None,<EOL>loglevel=logging.DEBUG): | shutit = self.shutit<EOL>shutit.handle_note(note)<EOL>tmp_filename = '<STR_LIT>' + shutit_util.random_id()<EOL>if self.file_exists(filename):<EOL><INDENT>if literal:<EOL><INDENT>if match_regexp is None:<EOL><INDENT>self.send(ShutItSendSpec(self,<EOL>send="""<STR_LIT>""" + line + """<STR_LIT>""" + filename + '<STR_LIT>'... | Removes line from file, if it exists.
Must be exactly the line passed in to match.
Returns True if there were no problems, False if there were.
@param line: Line to remove.
@param filename Filename to remove it from.
@param match_regexp: If supplied, a regexp to ... | f10349:c0:m44 |
def send(self, sendspec): | shutit = self.shutit<EOL>shutit.log('<STR_LIT>' + self.pexpect_session_id + '<STR_LIT>' + str(sendspec.send), level=logging.DEBUG)<EOL>if self._check_blocked(sendspec):<EOL><INDENT>shutit.log('<STR_LIT>' + str(sendspec.send) + '<STR_LIT>', level=logging.DEBUG)<EOL>return -<NUM_LIT:1><EOL><DEDENT>shutit = self.shutit<EO... | Send string as a shell command, and wait until the expected output
is seen (either a string or any from a list of strings) before
returning. The expected string will default to the currently-set
default expected string (see get_default_shutit_pexpect_session_expect)
Returns the pexpect ... | f10349:c0:m45 |
def quick_send(self, send, echo=None, loglevel=logging.INFO): | shutit = self.shutit<EOL>shutit.log('<STR_LIT>' + send, level=loglevel)<EOL>res = self.sendline(ShutItSendSpec(self,<EOL>send=send,<EOL>check_exit=False,<EOL>echo=echo,<EOL>fail_on_empty_before=False,<EOL>record_command=False,<EOL>ignore_background=True))<EOL>if not res:<EOL><INDENT>self.expect(self.default_expect)<EOL... | Quick and dirty send that ignores background tasks. Intended for internal use. | f10349:c0:m46 |
def send_file(self,<EOL>path,<EOL>contents,<EOL>echo=False,<EOL>truncate=False,<EOL>note=None,<EOL>user=None,<EOL>group=None,<EOL>loglevel=logging.INFO,<EOL>encoding=None): | shutit = self.shutit<EOL>shutit.handle_note(note, '<STR_LIT>' + path)<EOL>if shutit_global.shutit_global_object.ispy3:<EOL><INDENT>split_contents = '<STR_LIT>'.join((str(contents[:<NUM_LIT>]).split()))<EOL><DEDENT>else:<EOL><INDENT>split_contents = '<STR_LIT>'.join((contents[:<NUM_LIT>].split()))<EOL><DEDENT>strings_fr... | Sends the passed-in string as a file to the passed-in path on the
target.
@param path: Target location of file on target.
@param contents: Contents of file as a string.
@param note: See send()
@param user: Set ownership to this user (defaults to whoami)
... | f10349:c0:m47 |
def run_script(self,<EOL>script,<EOL>in_shell=True,<EOL>echo=None,<EOL>note=None,<EOL>loglevel=logging.DEBUG): | shutit = self.shutit<EOL>shutit.handle_note(note, '<STR_LIT>' + str(script))<EOL>shutit.log('<STR_LIT>' + '<STR_LIT>'.join(script.split())[:<NUM_LIT:30>] + '<STR_LIT>', level=logging.INFO)<EOL>lines = script.split('<STR_LIT:\n>')<EOL>while lines and re.match('<STR_LIT>', lines[<NUM_LIT:0>]):<EOL><INDENT>lines = lines[<... | Run the passed-in string as a script on the target's command line.
@param script: String representing the script. It will be de-indented
and stripped before being run.
@param in_shell: Indicate whether we are in a shell or not. (Default: True)
@param n... | f10349:c0:m48 |
def challenge(self,<EOL>shutit,<EOL>task_desc,<EOL>expect=None,<EOL>hints=None,<EOL>congratulations='<STR_LIT:OK>',<EOL>failed='<STR_LIT>',<EOL>expect_type='<STR_LIT>',<EOL>challenge_type='<STR_LIT>',<EOL>timeout=None,<EOL>check_exit=None,<EOL>fail_on_empty_before=True,<EOL>record_command=True,<EOL>exit_values=None,<EO... | shutit = self.shutit<EOL>if new_stage and shutit.build['<STR_LIT>']:<EOL><INDENT>if num_stages is None:<EOL><INDENT>num_stages = shutit.build['<STR_LIT>'].num_stages<EOL><DEDENT>elif shutit.build['<STR_LIT>'].num_stages < <NUM_LIT:1>:<EOL><INDENT>shutit.build['<STR_LIT>'].num_stages = num_stages<EOL><DEDENT>elif shutit... | Set the user a task to complete, success being determined by matching the output.
Either pass in regexp(s) desired from the output as a string or a list, or an md5sum of the output wanted.
@param follow_on_context On success, move to this context. A dict of information about that context.
... | f10349:c0:m49 |
def _create_command_file(self, expect, send): | shutit = self.shutit<EOL>random_id = shutit_util.random_id()<EOL>fname = shutit_global.shutit_global_object.shutit_state_dir + '<STR_LIT>' + random_id<EOL>working_str = send<EOL>assert not self.sendline(ShutItSendSpec(self,<EOL>send='<STR_LIT>'+ fname,<EOL>ignore_background=True)), shutit_util.print_debug()<EOL>self.ex... | Internal function. Do not use.
Takes a long command, and puts it in an executable file ready to run. Returns the filename. | f10349:c0:m54 |
def _pause_input_filter(self, input_string): | <EOL>shutit = self.shutit<EOL>if len(input_string) == <NUM_LIT:1>:<EOL><INDENT>if ord(input_string) == <NUM_LIT> and shutit.build['<STR_LIT>'] == '<STR_LIT>':<EOL><INDENT>shutit.log('<STR_LIT>', level=logging.INFO)<EOL>shutit.do_repository_work('<STR_LIT>', password=shutit.host['<STR_LIT:password>'], docker_executable=... | Input filter for pause point to catch special keystrokes | f10349:c0:m56 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.