Esempio n. 1
0
 def _connect(self, cmd, path):
     """
     Override connection establishment in SSHGitClient class so that pubkey
     is used.
     """
     # FIXME: This has no way to deal with passphrases..
     # FIXME: can we rely on ssh being in PATH here ?
     args = ['ssh', '-x', '-oStrictHostKeyChecking=no']
     if not (os.path.exists(self.pubkey)
             and os.access(self.pubkey, os.R_OK)):
         raise GitProtocolError(
             "Public key file is missing or incaccesible")
     args.extend(['-i', self.pubkey])
     if self.port is not None:
         args.extend(['-p', str(self.port)])
     if self.username is not None:
         host = '{0}@{1}'.format(self.username, self.host)
     else:
         host = self.host
     args.append(host)
     args.extend(["{0} '{1}'".format(self._get_cmd_path(cmd), path)])
     proc = subprocess.Popen(args,
                             stdin=subprocess.PIPE,
                             stdout=subprocess.PIPE)
     con = SubprocessWrapper(proc)
     logging.info("Connected to repo {0}:{1} via ssh, cmd: {2}".format(
         self.host, self.port if self.port else 22, cmd))
     return (Protocol(con.read,
                      con.write,
                      report_activity=self._report_activity), con.can_read)
Esempio n. 2
0
 def run_command(self, host, command, username=None, port=None):
     sshcmd = ui.config("ui", "ssh", "ssh")
     args = util.sshargs(sshcmd, host, username, port)
     cmd = '%s %s %s' % (sshcmd, args, util.shellquote(
         ' '.join(command)))
     ui.debug('calling ssh: %s\n' % cmd)
     proc = subprocess.Popen(util.quotecommand(cmd),
                             shell=True,
                             stdin=subprocess.PIPE,
                             stdout=subprocess.PIPE)
     return SubprocessWrapper(proc)
Esempio n. 3
0
        def connect_ssh(self, host, command, username=None, port=None):
            from dulwich.client import SubprocessWrapper
            from mercurial import util
            import subprocess

            sshcmd = ui.config("ui", "ssh", "ssh")
            args = util.sshargs(sshcmd, host, username, port)
            cmd = '%s %s %s' % (sshcmd, args, util.shellquote(
                ' '.join(command)))
            ui.debug('calling ssh: %s\n' % cmd)
            print command
            proc = subprocess.Popen(util.quotecommand(cmd),
                                    shell=True,
                                    stdin=subprocess.PIPE,
                                    stdout=subprocess.PIPE)
            return SubprocessWrapper(proc)
Esempio n. 4
0
 def run_command(self, host, command, username=None, port=None):
     if isinstance(command, basestring):
         # 0.12.x dulwich sends the raw string
         command = [command]
     elif len(command) > 1:
         # 0.11.x dulwich sends an array of [command arg1 arg2 ...], so
         # we detect that here and reformat it back to what hg-git
         # expects (e.g. "command 'arg1 arg2'")
         command = ["%s '%s'" % (command[0], ' '.join(command[1:]))]
     sshcmd = ui.config("ui", "ssh", "ssh")
     args = util.sshargs(sshcmd, host, username, port)
     cmd = '%s %s %s' % (sshcmd, args, util.shellquote(
         ' '.join(command)))
     ui.debug('calling ssh: %s\n' % cmd)
     proc = subprocess.Popen(util.quotecommand(cmd),
                             shell=True,
                             stdin=subprocess.PIPE,
                             stdout=subprocess.PIPE)
     return SubprocessWrapper(proc)
Esempio n. 5
0
 def run_command(self, host, command, username=None, port=None):
     assert isinstance(command, str)
     command = command.encode(SSHGitClient.DEFAULT_ENCODING)
     sshcmd = ui.config(b"ui", b"ssh", b"ssh")
     args = procutil.sshargs(
         sshcmd, pycompat.bytesurl(host), username, port
     )
     cmd = b'%s %s %s' % (sshcmd, args, procutil.shellquote(command))
     # consistent with mercurial
     ui.debug(b'running %s\n' % cmd)
     # we cannot use Mercurial's procutil.popen4() since it
     # always redirects stderr into a pipe
     proc = subprocess.Popen(
         procutil.tonativestr(cmd),
         shell=True,
         bufsize=0,
         stdin=subprocess.PIPE,
         stdout=subprocess.PIPE,
     )
     return SubprocessWrapper(proc)