Mercurial > hg-git
annotate hggit/_ssh.py @ 1115:8ed6c0cae9b8
cleanup: add some blank lines
author | Sean Farley <sean@farley.io> |
---|---|
date | Mon, 27 Nov 2017 18:46:07 -0500 |
parents | a539321562ef |
children | 80664524802b |
rev | line source |
---|---|
889
1b001f9df71b
ssh: move imports to top of file
Sean Farley <sean@farley.io>
parents:
748
diff
changeset
|
1 from dulwich.client import SubprocessWrapper |
1b001f9df71b
ssh: move imports to top of file
Sean Farley <sean@farley.io>
parents:
748
diff
changeset
|
2 import subprocess |
371
240573913439
Create ssh subprocess with a shell command instead of an exec list
Mads Kiilerich <mads@kiilerich.com>
parents:
369
diff
changeset
|
3 |
962
a539321562ef
ssh: regularize mercurial imports
Siddharth Agarwal <sid0@fb.com>
parents:
955
diff
changeset
|
4 from mercurial import ( |
a539321562ef
ssh: regularize mercurial imports
Siddharth Agarwal <sid0@fb.com>
parents:
955
diff
changeset
|
5 util, |
a539321562ef
ssh: regularize mercurial imports
Siddharth Agarwal <sid0@fb.com>
parents:
955
diff
changeset
|
6 ) |
a539321562ef
ssh: regularize mercurial imports
Siddharth Agarwal <sid0@fb.com>
parents:
955
diff
changeset
|
7 |
1115 | 8 |
369
e5c743cd0da1
pass hg's ui.ssh config to dulwich
Tay Ray Chuan <rctay89@gmail.com>
parents:
diff
changeset
|
9 class SSHVendor(object): |
e5c743cd0da1
pass hg's ui.ssh config to dulwich
Tay Ray Chuan <rctay89@gmail.com>
parents:
diff
changeset
|
10 """Parent class for ui-linked Vendor classes.""" |
e5c743cd0da1
pass hg's ui.ssh config to dulwich
Tay Ray Chuan <rctay89@gmail.com>
parents:
diff
changeset
|
11 |
e5c743cd0da1
pass hg's ui.ssh config to dulwich
Tay Ray Chuan <rctay89@gmail.com>
parents:
diff
changeset
|
12 |
e5c743cd0da1
pass hg's ui.ssh config to dulwich
Tay Ray Chuan <rctay89@gmail.com>
parents:
diff
changeset
|
13 def generate_ssh_vendor(ui): |
e5c743cd0da1
pass hg's ui.ssh config to dulwich
Tay Ray Chuan <rctay89@gmail.com>
parents:
diff
changeset
|
14 """ |
e5c743cd0da1
pass hg's ui.ssh config to dulwich
Tay Ray Chuan <rctay89@gmail.com>
parents:
diff
changeset
|
15 Allows dulwich to use hg's ui.ssh config. The dulwich.client.get_ssh_vendor |
e5c743cd0da1
pass hg's ui.ssh config to dulwich
Tay Ray Chuan <rctay89@gmail.com>
parents:
diff
changeset
|
16 property should point to the return value. |
e5c743cd0da1
pass hg's ui.ssh config to dulwich
Tay Ray Chuan <rctay89@gmail.com>
parents:
diff
changeset
|
17 """ |
e5c743cd0da1
pass hg's ui.ssh config to dulwich
Tay Ray Chuan <rctay89@gmail.com>
parents:
diff
changeset
|
18 |
e5c743cd0da1
pass hg's ui.ssh config to dulwich
Tay Ray Chuan <rctay89@gmail.com>
parents:
diff
changeset
|
19 class _Vendor(SSHVendor): |
606
980c37f6a8f9
Upgraded to use latest version of dulwich (0.9.1).
Alex Regueiro <alex@noldorin.com>
parents:
371
diff
changeset
|
20 def run_command(self, host, command, username=None, port=None): |
955
e7316a108780
ssh: fix breakage again with dulwich update
Sean Farley <sean@farley.io>
parents:
941
diff
changeset
|
21 if isinstance(command, basestring): |
e7316a108780
ssh: fix breakage again with dulwich update
Sean Farley <sean@farley.io>
parents:
941
diff
changeset
|
22 # 0.12.x dulwich sends the raw string |
e7316a108780
ssh: fix breakage again with dulwich update
Sean Farley <sean@farley.io>
parents:
941
diff
changeset
|
23 command = [command] |
e7316a108780
ssh: fix breakage again with dulwich update
Sean Farley <sean@farley.io>
parents:
941
diff
changeset
|
24 elif len(command) > 1: |
e7316a108780
ssh: fix breakage again with dulwich update
Sean Farley <sean@farley.io>
parents:
941
diff
changeset
|
25 # 0.11.x dulwich sends an array of [command arg1 arg2 ...], so |
e7316a108780
ssh: fix breakage again with dulwich update
Sean Farley <sean@farley.io>
parents:
941
diff
changeset
|
26 # we detect that here and reformat it back to what hg-git |
e7316a108780
ssh: fix breakage again with dulwich update
Sean Farley <sean@farley.io>
parents:
941
diff
changeset
|
27 # expects (e.g. "command 'arg1 arg2'") |
941
d1546c673c65
ssh: fix breakage with dulwich update
Sean Farley <sean@farley.io>
parents:
889
diff
changeset
|
28 command = ["%s '%s'" % (command[0], ' '.join(command[1:]))] |
369
e5c743cd0da1
pass hg's ui.ssh config to dulwich
Tay Ray Chuan <rctay89@gmail.com>
parents:
diff
changeset
|
29 sshcmd = ui.config("ui", "ssh", "ssh") |
e5c743cd0da1
pass hg's ui.ssh config to dulwich
Tay Ray Chuan <rctay89@gmail.com>
parents:
diff
changeset
|
30 args = util.sshargs(sshcmd, host, username, port) |
747
c1b39434ff56
_ssh: fix trailing whitespace
Augie Fackler <raf@durin42.com>
parents:
606
diff
changeset
|
31 cmd = '%s %s %s' % (sshcmd, args, |
371
240573913439
Create ssh subprocess with a shell command instead of an exec list
Mads Kiilerich <mads@kiilerich.com>
parents:
369
diff
changeset
|
32 util.shellquote(' '.join(command))) |
240573913439
Create ssh subprocess with a shell command instead of an exec list
Mads Kiilerich <mads@kiilerich.com>
parents:
369
diff
changeset
|
33 ui.debug('calling ssh: %s\n' % cmd) |
240573913439
Create ssh subprocess with a shell command instead of an exec list
Mads Kiilerich <mads@kiilerich.com>
parents:
369
diff
changeset
|
34 proc = subprocess.Popen(util.quotecommand(cmd), shell=True, |
369
e5c743cd0da1
pass hg's ui.ssh config to dulwich
Tay Ray Chuan <rctay89@gmail.com>
parents:
diff
changeset
|
35 stdin=subprocess.PIPE, |
e5c743cd0da1
pass hg's ui.ssh config to dulwich
Tay Ray Chuan <rctay89@gmail.com>
parents:
diff
changeset
|
36 stdout=subprocess.PIPE) |
e5c743cd0da1
pass hg's ui.ssh config to dulwich
Tay Ray Chuan <rctay89@gmail.com>
parents:
diff
changeset
|
37 return SubprocessWrapper(proc) |
e5c743cd0da1
pass hg's ui.ssh config to dulwich
Tay Ray Chuan <rctay89@gmail.com>
parents:
diff
changeset
|
38 |
e5c743cd0da1
pass hg's ui.ssh config to dulwich
Tay Ray Chuan <rctay89@gmail.com>
parents:
diff
changeset
|
39 return _Vendor |