diff options
| author | Richard Purdie <richard@openedhand.com> | 2008-09-30 15:08:33 +0000 |
|---|---|---|
| committer | Richard Purdie <richard@openedhand.com> | 2008-09-30 15:08:33 +0000 |
| commit | c30eddb243e7e65f67f656e62848a033cf6f2e5c (patch) | |
| tree | 110dd95788b76f55d31cb8d30aac2de8400b6f4a /bitbake-dev/lib/bb/fetch/ssh.py | |
| parent | 5ef0510474004eeb2ae8a99b64e2febb1920e077 (diff) | |
| download | poky-c30eddb243e7e65f67f656e62848a033cf6f2e5c.tar.gz | |
Add bitbake-dev to allow ease of testing and development of bitbake trunk
git-svn-id: https://svn.o-hand.com/repos/poky/trunk@5337 311d38ba-8fff-0310-9ca6-ca027cbcb966
Diffstat (limited to 'bitbake-dev/lib/bb/fetch/ssh.py')
| -rw-r--r-- | bitbake-dev/lib/bb/fetch/ssh.py | 120 |
1 files changed, 120 insertions, 0 deletions
diff --git a/bitbake-dev/lib/bb/fetch/ssh.py b/bitbake-dev/lib/bb/fetch/ssh.py new file mode 100644 index 0000000000..81a9892dcc --- /dev/null +++ b/bitbake-dev/lib/bb/fetch/ssh.py | |||
| @@ -0,0 +1,120 @@ | |||
| 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 | ''' | ||
| 14 | |||
| 15 | # Copyright (C) 2006 OpenedHand Ltd. | ||
| 16 | # | ||
| 17 | # | ||
| 18 | # Based in part on svk.py: | ||
| 19 | # Copyright (C) 2006 Holger Hans Peter Freyther | ||
| 20 | # Based on svn.py: | ||
| 21 | # Copyright (C) 2003, 2004 Chris Larson | ||
| 22 | # Based on functions from the base bb module: | ||
| 23 | # Copyright 2003 Holger Schurig | ||
| 24 | # | ||
| 25 | # | ||
| 26 | # This program is free software; you can redistribute it and/or modify | ||
| 27 | # it under the terms of the GNU General Public License version 2 as | ||
| 28 | # published by the Free Software Foundation. | ||
| 29 | # | ||
| 30 | # This program is distributed in the hope that it will be useful, | ||
| 31 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 32 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 33 | # GNU General Public License for more details. | ||
| 34 | # | ||
| 35 | # You should have received a copy of the GNU General Public License along | ||
| 36 | # with this program; if not, write to the Free Software Foundation, Inc., | ||
| 37 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
| 38 | |||
| 39 | import re, os | ||
| 40 | import bb | ||
| 41 | from bb import data | ||
| 42 | from bb.fetch import Fetch | ||
| 43 | from bb.fetch import FetchError | ||
| 44 | from bb.fetch import MissingParameterError | ||
| 45 | |||
| 46 | |||
| 47 | __pattern__ = re.compile(r''' | ||
| 48 | \s* # Skip leading whitespace | ||
| 49 | ssh:// # scheme | ||
| 50 | ( # Optional username/password block | ||
| 51 | (?P<user>\S+) # username | ||
| 52 | (:(?P<pass>\S+))? # colon followed by the password (optional) | ||
| 53 | )? | ||
| 54 | (?P<cparam>(;[^;]+)*)? # connection parameters block (optional) | ||
| 55 | @ | ||
| 56 | (?P<host>\S+?) # non-greedy match of the host | ||
| 57 | (:(?P<port>[0-9]+))? # colon followed by the port (optional) | ||
| 58 | / | ||
| 59 | (?P<path>[^;]+) # path on the remote system, may be absolute or relative, | ||
| 60 | # and may include the use of '~' to reference the remote home | ||
| 61 | # directory | ||
| 62 | (?P<sparam>(;[^;]+)*)? # parameters block (optional) | ||
| 63 | $ | ||
| 64 | ''', re.VERBOSE) | ||
| 65 | |||
| 66 | class SSH(Fetch): | ||
| 67 | '''Class to fetch a module or modules via Secure Shell''' | ||
| 68 | |||
| 69 | def supports(self, url, urldata, d): | ||
| 70 | return __pattern__.match(url) != None | ||
| 71 | |||
| 72 | def localpath(self, url, urldata, d): | ||
| 73 | m = __pattern__.match(url) | ||
| 74 | path = m.group('path') | ||
| 75 | host = m.group('host') | ||
| 76 | lpath = os.path.join(data.getVar('DL_DIR', d, True), host, os.path.basename(path)) | ||
| 77 | return lpath | ||
| 78 | |||
| 79 | def go(self, url, urldata, d): | ||
| 80 | dldir = data.getVar('DL_DIR', d, 1) | ||
| 81 | |||
| 82 | m = __pattern__.match(url) | ||
| 83 | path = m.group('path') | ||
| 84 | host = m.group('host') | ||
| 85 | port = m.group('port') | ||
| 86 | user = m.group('user') | ||
| 87 | password = m.group('pass') | ||
| 88 | |||
| 89 | ldir = os.path.join(dldir, host) | ||
| 90 | lpath = os.path.join(ldir, os.path.basename(path)) | ||
| 91 | |||
| 92 | if not os.path.exists(ldir): | ||
| 93 | os.makedirs(ldir) | ||
| 94 | |||
| 95 | if port: | ||
| 96 | port = '-P %s' % port | ||
| 97 | else: | ||
| 98 | port = '' | ||
| 99 | |||
| 100 | if user: | ||
| 101 | fr = user | ||
| 102 | if password: | ||
| 103 | fr += ':%s' % password | ||
| 104 | fr += '@%s' % host | ||
| 105 | else: | ||
| 106 | fr = host | ||
| 107 | fr += ':%s' % path | ||
| 108 | |||
| 109 | |||
| 110 | import commands | ||
| 111 | cmd = 'scp -B -r %s %s %s/' % ( | ||
| 112 | port, | ||
| 113 | commands.mkarg(fr), | ||
| 114 | commands.mkarg(ldir) | ||
| 115 | ) | ||
| 116 | |||
| 117 | (exitstatus, output) = commands.getstatusoutput(cmd) | ||
| 118 | if exitstatus != 0: | ||
| 119 | print output | ||
| 120 | raise FetchError('Unable to fetch %s' % url) | ||
