Esempio n. 1
0
def run_git(args,
            git_path=_DEFAULT_GIT,
            input=None,
            capture_stdout=False,
            **popen_kwargs):
    """Run a git command.

    Input is piped from the input parameter and output is sent to the standard
    streams, unless capture_stdout is set.

    :param args: A list of args to the git command.
    :param git_path: Path to to the git executable.
    :param input: Input data to be sent to stdin.
    :param capture_stdout: Whether to capture and return stdout.
    :param popen_kwargs: Additional kwargs for subprocess.Popen;
        stdin/stdout args are ignored.
    :return: A tuple of (returncode, stdout contents). If capture_stdout is
        False, None will be returned as stdout contents.
    :raise OSError: if the git executable was not found.
    """

    env = get_safe_env(popen_kwargs.pop('env', None))

    args = [git_path] + args
    popen_kwargs['stdin'] = subprocess.PIPE
    if capture_stdout:
        popen_kwargs['stdout'] = subprocess.PIPE
    else:
        popen_kwargs.pop('stdout', None)
    p = subprocess.Popen(args, env=env, **popen_kwargs)
    stdout, stderr = p.communicate(input=input)
    return (p.returncode, stdout)
Esempio n. 2
0
def run_git(args, git_path=_DEFAULT_GIT, input=None, capture_stdout=False,
            **popen_kwargs):
    """Run a git command.

    Input is piped from the input parameter and output is sent to the standard
    streams, unless capture_stdout is set.

    :param args: A list of args to the git command.
    :param git_path: Path to to the git executable.
    :param input: Input data to be sent to stdin.
    :param capture_stdout: Whether to capture and return stdout.
    :param popen_kwargs: Additional kwargs for subprocess.Popen;
        stdin/stdout args are ignored.
    :return: A tuple of (returncode, stdout contents). If capture_stdout is
        False, None will be returned as stdout contents.
    :raise OSError: if the git executable was not found.
    """

    env = get_safe_env(popen_kwargs.pop('env', None))

    args = [git_path] + args
    popen_kwargs['stdin'] = subprocess.PIPE
    if capture_stdout:
        popen_kwargs['stdout'] = subprocess.PIPE
    else:
        popen_kwargs.pop('stdout', None)
    p = subprocess.Popen(args, env=env, **popen_kwargs)
    stdout, stderr = p.communicate(input=input)
    return (p.returncode, stdout)
Esempio n. 3
0
 def run_command(host, command, username=None, port=None):
     cmd, path = command
     cmd = cmd.split(b'-', 1)
     path = path.replace(b"'", b"")
     p = subprocess.Popen(cmd + [path], bufsize=0, env=get_safe_env(), stdin=subprocess.PIPE,
                          stdout=subprocess.PIPE, stderr=subprocess.PIPE)
     return client.SubprocessWrapper(p)
Esempio n. 4
0
 def run_command(host, command, username=None, port=None):
     cmd, path = command[0].replace("'", "").split(" ")
     cmd = cmd.split("-", 1)
     p = subprocess.Popen(
         cmd + [path], env=get_safe_env(), stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE
     )
     return client.SubprocessWrapper(p)
Esempio n. 5
0
 def run_command(host, command, username=None, port=None):
     cmd, path = command[0].replace("'", '').split(' ')
     cmd = cmd.split('-', 1)
     p = subprocess.Popen(cmd + [path],
                          env=get_safe_env(),
                          stdin=subprocess.PIPE,
                          stdout=subprocess.PIPE,
                          stderr=subprocess.PIPE)
     return client.SubprocessWrapper(p)
Esempio n. 6
0
 def run_command(host, command, username=None, port=None):
     cmd, path = command.split(b' ')
     cmd = cmd.split(b'-', 1)
     path = path.replace(b"'", b"")
     p = subprocess.Popen(cmd + [path],
                          bufsize=0,
                          env=get_safe_env(),
                          stdin=subprocess.PIPE,
                          stdout=subprocess.PIPE,
                          stderr=subprocess.PIPE)
     return client.SubprocessWrapper(p)
Esempio n. 7
0
 def setUp(self):
     CompatTestCase.setUp(self)
     DulwichClientTestBase.setUp(self)
     if check_for_daemon(limit=1):
         raise SkipTest('git-daemon was already running on port %s' %
                           protocol.TCP_GIT_PORT)
     env = get_safe_env()
     fd, self.pidfile = tempfile.mkstemp(prefix='dulwich-test-git-client',
                                         suffix=".pid")
     os.fdopen(fd).close()
     args = [_DEFAULT_GIT, 'daemon', '--verbose', '--export-all',
             '--pid-file=%s' % self.pidfile,
             '--base-path=%s' % self.gitroot,
             '--enable=receive-pack', '--enable=upload-archive',
             '--listen=localhost', '--reuseaddr',
             self.gitroot]
     self.process = subprocess.Popen(
         args, env=env, cwd=self.gitroot,
         stdout=subprocess.PIPE, stderr=subprocess.PIPE)
     if not check_for_daemon():
         raise SkipTest('git-daemon failed to start')
Esempio n. 8
0
 def setUp(self):
     CompatTestCase.setUp(self)
     DulwichClientTestBase.setUp(self)
     if check_for_daemon(limit=1):
         raise SkipTest('git-daemon was already running on port %s' %
                        protocol.TCP_GIT_PORT)
     env = get_safe_env()
     fd, self.pidfile = tempfile.mkstemp(prefix='dulwich-test-git-client',
                                         suffix=".pid")
     os.fdopen(fd).close()
     args = [
         _DEFAULT_GIT, 'daemon', '--verbose', '--export-all',
         '--pid-file=%s' % self.pidfile,
         '--base-path=%s' % self.gitroot, '--enable=receive-pack',
         '--enable=upload-archive', '--listen=localhost', '--reuseaddr',
         self.gitroot
     ]
     self.process = subprocess.Popen(args,
                                     env=env,
                                     cwd=self.gitroot,
                                     stdout=subprocess.PIPE,
                                     stderr=subprocess.PIPE)
     if not check_for_daemon():
         raise SkipTest('git-daemon failed to start')