Processing a shell entry.
355961
def process_shell(self, creator, entry, config):
        """"""
        self.logger.info("Processing Bash code: start")

        output = []
        shell = creator(entry, config)
        for line in shell.process():
            output.append(line)
            self.logger.info(" | %s", line)

        if shell.success:
            self.logger.info("Processing Bash code: finished")
            return {'success': True, 'output': output}

        for line in self.run_cleanup(config.env, shell.exit_code):
            output.append(line)

        self.logger.error("Pipeline has failed: leaving as soon as possible!")
        self.event.failed()
        return {'success': False, 'output': output}
1048485
def run(self):
    """"""
    cmd = ['gsutil', 'ls', os.path.join(self.source_dir, '**')]
    try:
      files_list = subprocess.check_output(cmd).split('\n')
    except subprocess.CalledProcessError:
      logging.error('Can''t read source directory')
    all_submissions = [
        s for s in files_list
        if s.endswith('.zip') or s.endswith('.tar') or s.endswith('.tar.gz')
    ]
    for submission_path in all_submissions:
      self.validate_and_copy_one_submission(submission_path)
    self.stats.log_stats()
    self.save_id_to_path_mapping()
    if self.containers_file:
      with open(self.containers_file, 'w') as f:
        f.write('\n'.join(sorted(self.list_of_containers)))
1296051
def prepare_shell_data(self, shells, key, entry):
        """"""
        if self.can_process_shell(entry):
            if key in ['python']:
                entry['type'] = key

            if 'with' in entry and isinstance(entry['with'], str):
                rendered_with = ast.literal_eval(render(entry['with'],
                                                        variables=self.pipeline.variables,
                                                        model=self.pipeline.model,
                                                        env=self.get_merged_env(include_os=True)))
            elif 'with' in entry:
                rendered_with = entry['with']
            else:
                rendered_with = ['']

            for item in rendered_with:
                shells.append({
                    'id': self.next_task_id,
                    'creator': key,
                    'entry': entry,
                    'model': self.pipeline.model,
                    'env': self.get_merged_env(),
                    'item': item,
                    'dry_run': self.pipeline.options.dry_run,
                    'debug': self.pipeline.options.debug,
                    'strict': self.pipeline.options.strict,
                    'variables': self.pipeline.variables,
                    'temporary_scripts_path': self.pipeline.options.temporary_scripts_path})
                self.next_task_id += 1
1133296
def bash(filename):
    """"""
    sys.stdout.flush()
    subprocess.call("bash {}".format(filename), shell=True)
644278
def execute(self):
        """"""
        if self._decode_output:
            # Capture and decode system output
            with Popen(self.command, shell=True, stdout=PIPE) as process:
                self._output = [i.decode("utf-8").strip() for i in process.stdout]
                self._success = True
        else:
            # Execute without capturing output
            os.system(self.command)
            self._success = True
        return self
230752
def preprocess(cls, cat):
        """"""
        if isinstance(cat, str):
            cat = intake.open_catalog(cat)
        return cat
324867
function handleDir(fs, path, res) {
  var sh = new fs.Shell();

  sh.ls(path, {recursive: true}, function(err, listing) {
    if(err) {
      log.error(err, 'Unable to get listing for path `%s`', path);
      handle404(path, res);
      return;
    }
    write(listing, res);
  });
}
1199202
def shell(self):
        
        from rez.shells import get_shell_types
        shells = set(get_shell_types())
        if not shells:
            raise RezSystemError("no shells available")

        if self.platform == "windows":
            return "cmd"
        else:
            import subprocess as sp
            shell = None

            # check parent process via ps
            try:
                args = ['ps', '-o', 'args=', '-p', str(os.getppid())]
                proc = sp.Popen(args, stdout=sp.PIPE)
                output = proc.communicate()[0]
                shell = os.path.basename(output.strip().split()[0]).replace('-', '')
            except Exception:
                pass

            # check $SHELL
            if shell not in shells:
                shell = os.path.basename(os.getenv("SHELL", ''))

            # traverse parent procs via /proc/(pid)/status
            if shell not in shells:
                pid = str(os.getppid())
                found = False

                while not found:
                    try:
                        file = os.path.join(os.sep, "proc", pid, "status")
                        with open(file) as f:
                            loc = f.read().split('\n')

                        for line in loc:
                            line = line.strip()
                            toks = line.split()
                            if len(toks) == 2:
                                if toks[0] == "Name:":
                                    name = toks[1]
                                    if name in shells:
                                        shell = name
                                        found = True
                                        break
                                elif toks[0] == "PPid:":
                                    pid = toks[1]
                    except Exception:
                        break

            if (shell not in shells) and ("sh" in shells):
                shell = "sh"  # failed detection, fall back on 'sh'
            elif (shell not in shells) and ("bash" in shells):
                shell = "bash"  # failed detection, fall back on 'bash'
            elif shell not in shells:
                shell = iter(shells).next()  # give up - just choose a shell

            # sh has to be handled as a special case
            if shell == "sh":
                if os.path.islink("/bin/sh"):
                    path = os.readlink("/bin/sh")
                    shell2 = os.path.split(path)[-1]

                    if shell2 == "bash":
                        # bash switches to sh-like shell when invoked as sh,
                        # so we want to use the sh shell plugin
                        pass
                    elif shell2 == "dash":
                        # dash doesn't have an sh emulation mode, so we have
                        # to use the dash shell plugin
                        if "dash" in shells:
                            shell = "dash"
                        else:
                            # this isn't good!
                            if "bash" in shells:
                                shell = "bash"  # fall back on bash
                            else:
                                shell = iter(shells).next()  # give up - just choose a shell

            # TODO: remove this when/if dash support added
            if shell == "dash":
                shell = "bash"

            return shell
1153351
def process(self):
    """"""
    for _, path in self.state.input:
      self._copy_file_or_directory(path, self._target_directory)
      print('{0:s} -> {1:s}'.format(path, self._target_directory))
828498
def out(self, output, newline=True):
        """"""
        click.echo(output, nl=newline)
65128
def shell(ctx, package, working_dir, sudo):
    """"""
    ctx.mode = CanariMode.LocalShellDebug
    from canari.commands.shell import shell
    shell(package, working_dir, sudo)
369524
def _batch_entry(self):
        """"""
        try:
            while True:
                self._batch_entry_run()
        except:
            self.exc_info = sys.exc_info()
            os.kill(self.pid, signal.SIGUSR1)
170138
def __handle_variable(self, shell_entry, output):
        
        if 'variable' in shell_entry:
            variable_name = shell_entry['variable']
            self.pipeline.variables[variable_name] = "\n".join(output)
1199108
def _stage_input_files(self, file_mapping, dry_run=True):
        """"""
        # print ("Staging input ", file_mapping)
        if self._file_stage is None:
            return
        self._file_stage.copy_to_scratch(file_mapping, dry_run)
1012692
def _ProcessEntries(self, fd):
    """"""
    p = config_file.KeyValueParser(kv_sep="{", term="}", sep=None)
    data = utils.ReadFileBytesAsUnicode(fd)
    entries = p.ParseEntries(data)
    for entry in entries:
      for section, cfg in iteritems(entry):
        # The parser returns a list of configs. There will only be one.
        if cfg:
          cfg = cfg[0].strip()
        else:
          cfg = ""
        self._ParseSection(section, cfg)
520286
protected function processInputFiles()
    {
        $passwords = array();
        foreach ($this->_files as $handle => $file) {
            $this->addArg($handle.'=',$file['name']);
            if ($file['password']!==null) {
                $passwords[$handle] = $file['password'];
            }
        }
        if ($passwords!==array()) {
            $this->addArg('input_pw');
            foreach ($passwords as $handle => $password) {
                $this->addArg($handle.'=', $password);
            }
        }
    }
1024533
def Main():
  """"""
  multiprocessing.freeze_support()

  input_reader = cli_tools.StdinInputReader()
  tool = psort_tool.PsortTool(input_reader=input_reader)

  if not tool.ParseArguments():
    return False

  have_list_option = False
  if tool.list_analysis_plugins:
    tool.ListAnalysisPlugins()
    have_list_option = True

  if tool.list_output_modules:
    tool.ListOutputModules()
    have_list_option = True

  if tool.list_language_identifiers:
    tool.ListLanguageIdentifiers()
    have_list_option = True

  if tool.list_timezones:
    tool.ListTimeZones()
    have_list_option = True

  if have_list_option:
    return True

  try:
    tool.ProcessStorage()

  except (KeyboardInterrupt, errors.UserAbort):
    logging.warning('Aborted by user.')
    return False

  except errors.BadConfigOption as exception:
    logging.warning(exception)
    return False

  return True