diff options
Diffstat (limited to 'bitbake/lib/bb/fetch2/ssh.py')
-rw-r--r-- | bitbake/lib/bb/fetch2/ssh.py | 127 |
1 files changed, 127 insertions, 0 deletions
diff --git a/bitbake/lib/bb/fetch2/ssh.py b/bitbake/lib/bb/fetch2/ssh.py new file mode 100644 index 0000000000..4ae979472c --- /dev/null +++ b/bitbake/lib/bb/fetch2/ssh.py | |||
@@ -0,0 +1,127 @@ | |||
1 | # ex:ts=4:sw=4:sts=4:et | ||
2 | # -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- | ||
3 | ''' | ||
4 | BitBake 'Fetch' implementations | ||
5 | |||
6 | This implementation is for Secure Shell (SSH), and attempts to comply with the | ||
7 | IETF secsh internet draft: | ||
8 | http://tools.ietf.org/wg/secsh/draft-ietf-secsh-scp-sftp-ssh-uri/ | ||
9 | |||
10 | Currently does not support the sftp parameters, as this uses scp | ||
11 | Also does not support the 'fingerprint' connection parameter. | ||
12 | |||
13 | Please note that '/' is used as host, path separator not ':' as you may | ||
14 | be used to, also '~' can be used to specify user HOME, but again after '/' | ||
15 | |||
16 | Example SRC_URI: | ||
17 | SRC_URI = "ssh://user@host.example.com/dir/path/file.txt" | ||
18 | SRC_URI = "ssh://user@host.example.com/~/file.txt" | ||
19 | ''' | ||
20 | |||
21 | # Copyright (C) 2006 OpenedHand Ltd. | ||
22 | # | ||
23 | # | ||
24 | # Based in part on svk.py: | ||
25 | # Copyright (C) 2006 Holger Hans Peter Freyther | ||
26 | # Based on svn.py: | ||
27 | # Copyright (C) 2003, 2004 Chris Larson | ||
28 | # Based on functions from the base bb module: | ||
29 | # Copyright 2003 Holger Schurig | ||
30 | # | ||
31 | # | ||
32 | # This program is free software; you can redistribute it and/or modify | ||
33 | # it under the terms of the GNU General Public License version 2 as | ||
34 | # published by the Free Software Foundation. | ||
35 | # | ||
36 | # This program is distributed in the hope that it will be useful, | ||
37 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
38 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
39 | # GNU General Public License for more details. | ||
40 | # | ||
41 | # You should have received a copy of the GNU General Public License along | ||
42 | # with this program; if not, write to the Free Software Foundation, Inc., | ||
43 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
44 | |||
45 | import re, os | ||
46 | from bb import data | ||
47 | from bb.fetch2 import FetchMethod | ||
48 | from bb.fetch2 import FetchError | ||
49 | from bb.fetch2 import logger | ||
50 | from bb.fetch2 import runfetchcmd | ||
51 | |||
52 | |||
53 | __pattern__ = re.compile(r''' | ||
54 | \s* # Skip leading whitespace | ||
55 | ssh:// # scheme | ||
56 | ( # Optional username/password block | ||
57 | (?P<user>\S+) # username | ||
58 | (:(?P<pass>\S+))? # colon followed by the password (optional) | ||
59 | )? | ||
60 | (?P<cparam>(;[^;]+)*)? # connection parameters block (optional) | ||
61 | @ | ||
62 | (?P<host>\S+?) # non-greedy match of the host | ||
63 | (:(?P<port>[0-9]+))? # colon followed by the port (optional) | ||
64 | / | ||
65 | (?P<path>[^;]+) # path on the remote system, may be absolute or relative, | ||
66 | # and may include the use of '~' to reference the remote home | ||
67 | # directory | ||
68 | (?P<sparam>(;[^;]+)*)? # parameters block (optional) | ||
69 | $ | ||
70 | ''', re.VERBOSE) | ||
71 | |||
72 | class SSH(FetchMethod): | ||
73 | '''Class to fetch a module or modules via Secure Shell''' | ||
74 | |||
75 | def supports(self, urldata, d): | ||
76 | return __pattern__.match(urldata.url) != None | ||
77 | |||
78 | def supports_checksum(self, urldata): | ||
79 | return False | ||
80 | |||
81 | def urldata_init(self, urldata, d): | ||
82 | if 'protocol' in urldata.parm and urldata.parm['protocol'] == 'git': | ||
83 | raise bb.fetch2.ParameterError( | ||
84 | "Invalid protocol - if you wish to fetch from a git " + | ||
85 | "repository using ssh, you need to use " + | ||
86 | "git:// prefix with protocol=ssh", urldata.url) | ||
87 | m = __pattern__.match(urldata.url) | ||
88 | path = m.group('path') | ||
89 | host = m.group('host') | ||
90 | urldata.localpath = os.path.join(d.getVar('DL_DIR', True), os.path.basename(path)) | ||
91 | |||
92 | def download(self, urldata, d): | ||
93 | dldir = d.getVar('DL_DIR', True) | ||
94 | |||
95 | m = __pattern__.match(urldata.url) | ||
96 | path = m.group('path') | ||
97 | host = m.group('host') | ||
98 | port = m.group('port') | ||
99 | user = m.group('user') | ||
100 | password = m.group('pass') | ||
101 | |||
102 | if port: | ||
103 | portarg = '-P %s' % port | ||
104 | else: | ||
105 | portarg = '' | ||
106 | |||
107 | if user: | ||
108 | fr = user | ||
109 | if password: | ||
110 | fr += ':%s' % password | ||
111 | fr += '@%s' % host | ||
112 | else: | ||
113 | fr = host | ||
114 | fr += ':%s' % path | ||
115 | |||
116 | |||
117 | import commands | ||
118 | cmd = 'scp -B -r %s %s %s/' % ( | ||
119 | portarg, | ||
120 | commands.mkarg(fr), | ||
121 | commands.mkarg(dldir) | ||
122 | ) | ||
123 | |||
124 | bb.fetch2.check_network_access(d, cmd, urldata.url) | ||
125 | |||
126 | runfetchcmd(cmd, d) | ||
127 | |||