diff options
author | Olof Johansson <olof.johansson@axis.com> | 2013-01-29 08:50:11 +0100 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2013-02-17 22:32:05 +0000 |
commit | 7b59a343600f295506ffcaf635d4cf90d43384d3 (patch) | |
tree | 3b5fba7c64d8c4a343e78d6b619c4e1fc4a47808 /bitbake/lib/bb/fetch2 | |
parent | 96f0a39e7c7dd849ea8279112e4cb66a7182afec (diff) | |
download | poky-7b59a343600f295506ffcaf635d4cf90d43384d3.tar.gz |
bitbake: fetch2: Add SFTP fetcher
This fetcher differs from the SSH fetcher in that it adheres more
strictly to the SECSH URI internet draft --- it uses the sftp://
instead of the ssh:// scheme, and it uses sftp instead of scp.
(Bitbake rev: d240baeb7a4107d2eba3f08c411c0f086674d8e2)
Signed-off-by: Olof Johansson <olof.johansson@axis.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/bb/fetch2')
-rw-r--r-- | bitbake/lib/bb/fetch2/__init__.py | 2 | ||||
-rw-r--r-- | bitbake/lib/bb/fetch2/sftp.py | 129 |
2 files changed, 131 insertions, 0 deletions
diff --git a/bitbake/lib/bb/fetch2/__init__.py b/bitbake/lib/bb/fetch2/__init__.py index 427c47673b..f5b363d231 100644 --- a/bitbake/lib/bb/fetch2/__init__.py +++ b/bitbake/lib/bb/fetch2/__init__.py | |||
@@ -1467,6 +1467,7 @@ from . import svn | |||
1467 | from . import wget | 1467 | from . import wget |
1468 | from . import svk | 1468 | from . import svk |
1469 | from . import ssh | 1469 | from . import ssh |
1470 | from . import sftp | ||
1470 | from . import perforce | 1471 | from . import perforce |
1471 | from . import bzr | 1472 | from . import bzr |
1472 | from . import hg | 1473 | from . import hg |
@@ -1480,6 +1481,7 @@ methods.append(git.Git()) | |||
1480 | methods.append(cvs.Cvs()) | 1481 | methods.append(cvs.Cvs()) |
1481 | methods.append(svk.Svk()) | 1482 | methods.append(svk.Svk()) |
1482 | methods.append(ssh.SSH()) | 1483 | methods.append(ssh.SSH()) |
1484 | methods.append(sftp.SFTP()) | ||
1483 | methods.append(perforce.Perforce()) | 1485 | methods.append(perforce.Perforce()) |
1484 | methods.append(bzr.Bzr()) | 1486 | methods.append(bzr.Bzr()) |
1485 | methods.append(hg.Hg()) | 1487 | methods.append(hg.Hg()) |
diff --git a/bitbake/lib/bb/fetch2/sftp.py b/bitbake/lib/bb/fetch2/sftp.py new file mode 100644 index 0000000000..5fbbcfdd90 --- /dev/null +++ b/bitbake/lib/bb/fetch2/sftp.py | |||
@@ -0,0 +1,129 @@ | |||
1 | # ex:ts=4:sw=4:sts=4:et | ||
2 | # -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- | ||
3 | """ | ||
4 | BitBake SFTP Fetch implementation | ||
5 | |||
6 | Class for fetching files via SFTP. It tries to adhere to the (now | ||
7 | expired) IETF Internet Draft for "Uniform Resource Identifier (URI) | ||
8 | Scheme for Secure File Transfer Protocol (SFTP) and Secure Shell | ||
9 | (SSH)" (SECSH URI). | ||
10 | |||
11 | It uses SFTP (as to adhere to the SECSH URI specification). It only | ||
12 | supports key based authentication, not password. This class, unlike | ||
13 | the SSH fetcher, does not support fetching a directory tree from the | ||
14 | remote. | ||
15 | |||
16 | http://tools.ietf.org/html/draft-ietf-secsh-scp-sftp-ssh-uri-04 | ||
17 | https://www.iana.org/assignments/uri-schemes/prov/sftp | ||
18 | https://tools.ietf.org/html/draft-ietf-secsh-filexfer-13 | ||
19 | |||
20 | Please note that '/' is used as host path seperator, and not ":" | ||
21 | as you may be used to from the scp/sftp commands. You can use a | ||
22 | ~ (tilde) to specify a path relative to your home directory. | ||
23 | (The /~user/ syntax, for specyfing a path relative to another | ||
24 | user's home directory is not supported.) Note that the tilde must | ||
25 | still follow the host path seperator ("/"). See exampels below. | ||
26 | |||
27 | Example SRC_URIs: | ||
28 | |||
29 | SRC_URI = "sftp://host.example.com/dir/path.file.txt" | ||
30 | |||
31 | A path relative to your home directory. | ||
32 | |||
33 | SRC_URI = "sftp://host.example.com/~/dir/path.file.txt" | ||
34 | |||
35 | You can also specify a username (specyfing password in the | ||
36 | URI is not supported, use SSH keys to authenticate): | ||
37 | |||
38 | SRC_URI = "sftp://user@host.example.com/dir/path.file.txt" | ||
39 | |||
40 | """ | ||
41 | |||
42 | # Copyright (C) 2013, Olof Johansson <olof.johansson@axis.com> | ||
43 | # | ||
44 | # Based in part on bb.fetch2.wget: | ||
45 | # Copyright (C) 2003, 2004 Chris Larson | ||
46 | # | ||
47 | # This program is free software; you can redistribute it and/or modify | ||
48 | # it under the terms of the GNU General Public License version 2 as | ||
49 | # published by the Free Software Foundation. | ||
50 | # | ||
51 | # This program is distributed in the hope that it will be useful, | ||
52 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
53 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
54 | # GNU General Public License for more details. | ||
55 | # | ||
56 | # You should have received a copy of the GNU General Public License along | ||
57 | # with this program; if not, write to the Free Software Foundation, Inc., | ||
58 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
59 | # | ||
60 | # Based on functions from the base bb module, Copyright 2003 Holger Schurig | ||
61 | |||
62 | import os | ||
63 | import bb | ||
64 | import urllib | ||
65 | import commands | ||
66 | from bb import data | ||
67 | from bb.fetch2 import URI | ||
68 | from bb.fetch2 import FetchMethod | ||
69 | from bb.fetch2 import runfetchcmd | ||
70 | |||
71 | |||
72 | class SFTP(FetchMethod): | ||
73 | """Class to fetch urls via 'sftp'""" | ||
74 | |||
75 | def supports(self, url, ud, d): | ||
76 | """ | ||
77 | Check to see if a given url can be fetched with sftp. | ||
78 | """ | ||
79 | return ud.type in ['sftp'] | ||
80 | |||
81 | def recommends_checksum(self, urldata): | ||
82 | return True | ||
83 | |||
84 | def urldata_init(self, ud, d): | ||
85 | if 'protocol' in ud.parm and ud.parm['protocol'] == 'git': | ||
86 | raise bb.fetch2.ParameterError( | ||
87 | "Invalid protocol - if you wish to fetch from a " + | ||
88 | "git repository using ssh, you need to use the " + | ||
89 | "git:// prefix with protocol=ssh", ud.url) | ||
90 | |||
91 | if 'downloadfilename' in ud.parm: | ||
92 | ud.basename = ud.parm['downloadfilename'] | ||
93 | else: | ||
94 | ud.basename = os.path.basename(ud.path) | ||
95 | |||
96 | ud.localfile = data.expand(urllib.unquote(ud.basename), d) | ||
97 | |||
98 | def download(self, uri, ud, d): | ||
99 | """Fetch urls""" | ||
100 | |||
101 | urlo = URI(uri) | ||
102 | basecmd = 'sftp -oPasswordAuthentication=no' | ||
103 | port = '' | ||
104 | if urlo.port: | ||
105 | port = '-P %d' % urlo.port | ||
106 | urlo.port = None | ||
107 | |||
108 | dldir = data.getVar('DL_DIR', d, True) | ||
109 | lpath = os.path.join(dldir, ud.localfile) | ||
110 | |||
111 | user = '' | ||
112 | if urlo.userinfo: | ||
113 | user = urlo.userinfo + '@' | ||
114 | |||
115 | path = urlo.path | ||
116 | |||
117 | # Supoprt URIs relative to the user's home directory, with | ||
118 | # the tilde syntax. (E.g. <sftp://example.com/~/foo.diff>). | ||
119 | if path[:3] == '/~/': | ||
120 | path = path[3:] | ||
121 | |||
122 | remote = '%s%s:%s' % (user, urlo.hostname, path) | ||
123 | |||
124 | cmd = '%s %s %s %s' % (basecmd, port, commands.mkarg(remote), | ||
125 | commands.mkarg(lpath)) | ||
126 | |||
127 | bb.fetch2.check_network_access(d, cmd, uri) | ||
128 | runfetchcmd(cmd, d) | ||
129 | return True | ||