Exemplo n.º 1
0
 def f(path):
     if os.path.isfile(path):
         path = os.path.dirname(path)
     cli.note("Running a new shell in %s\n"
              "To exit the shell, type 'exit' and press Enter." % path)
     with util.Chdir(path):
         pty.spawn([shell_cmd])
Exemplo n.º 2
0
def _safe_chdir(dir):
    if not os.path.exists(dir):

        class NoOp(object):
            def __enter__(self):
                pass

            def __exit__(self, *_args):
                pass

        return NoOp()

    return util.Chdir(dir)
Exemplo n.º 3
0
def _run(op, flags, opts):
    run = _init_run()
    _init_run_attrs(run, op, flags, opts)
    summary = _init_output_scalars(run, opts)
    try:
        with RunOutput(run, summary):
            with util.Chdir(run.path):
                result = op(**flags)
    except Exception as e:
        exit_status = 1
        raise RunError(run, e)
    else:
        exit_status = 0
        return run, result
    finally:
        _finalize_run_attrs(run, exit_status)
Exemplo n.º 4
0
 def print_runs(self,
                runs=None,
                flags=False,
                labels=False,
                status=False,
                cwd=None,
                limit=None):
     cwd = os.path.join(self.cwd, cwd) if cwd else self.cwd
     if runs is None:
         runs = self.list_runs(limit=limit)
     cols = self._cols_for_print_runs(flags, labels, status)
     rows = []
     with util.Chdir(cwd):
         for run in runs:
             rows.append(self._row_for_print_run(run, flags, labels,
                                                 status))
     cli.table(rows, cols)
Exemplo n.º 5
0
def _run(op, flag_vals, opts, extra_attrs=None):
    run = _init_run()
    _init_run_attrs(run, op, flag_vals, opts, extra_attrs)
    summary = _init_output_scalars(run, opts)
    try:
        with RunOutput(run, summary):
            _write_proc_lock(run)
            with util.Chdir(run.path):
                result = op(**flag_vals)
    except KeyboardInterrupt as e:
        exit_status = exit_code.KEYBOARD_INTERRUPT
        util.raise_from(RunTerminated(run, e), e)
    except Exception as e:
        exit_status = exit_code.DEFAULT_ERROR
        util.raise_from(RunError(run, e), e)
    else:
        exit_status = 0
        return run, result
    finally:
        _finalize_run(run, exit_status)