2 # ex:ts=4:sw=4:sts=4:et
3 # -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
5 BitBake 'Fetch' implementations
7 This implementation is for Secure Shell (SSH), and attempts to comply with the
8 IETF secsh internet draft:
9 http://tools.ietf.org/wg/secsh/draft-ietf-secsh-scp-sftp-ssh-uri/
11 Currently does not support the sftp parameters, as this uses scp
12 Also does not support the 'fingerprint' connection parameter.
14 Copyright (C) 2006 OpenedHand Ltd.
16 Based in part on svk.py:
17 Copyright (C) 2006 Holger Hans Peter Freyther
19 Copyright (C) 2003, 2004 Chris Larson
20 Based on functions from the base bb module:
21 Copyright 2003 Holger Schurig
24 This program is free software; you can redistribute it and/or modify it under
25 the terms of the GNU General Public License as published by the Free Software
26 Foundation; either version 2 of the License, or (at your option) any later
29 This program is distributed in the hope that it will be useful, but WITHOUT
30 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
31 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
33 You should have received a copy of the GNU General Public License along with
34 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
35 Place, Suite 330, Boston, MA 02111-1307 USA.
40 from bb.fetch import Fetch
41 from bb.fetch import FetchError
42 from bb.fetch import MissingParameterError
45 __pattern__ = re.compile(r'''
46 \s* # Skip leading whitespace
48 ( # Optional username/password block
49 (?P<user>\S+) # username
50 (:(?P<pass>\S+))? # colon followed by the password (optional)
52 (?P<cparam>(;[^;]+)*)? # connection parameters block (optional)
54 (?P<host>\S+?) # non-greedy match of the host
55 (:(?P<port>[0-9]+))? # colon followed by the port (optional)
57 (?P<path>[^;]+) # path on the remote system, may be absolute or relative,
58 # and may include the use of '~' to reference the remote home
60 (?P<sparam>(;[^;]+)*)? # parameters block (optional)
65 '''Class to fetch a module or modules via Secure Shell'''
67 def supports(self, url, urldata, d):
68 return __pattern__.match(url) != None
70 def localpath(self, url, urldata, d):
71 m = __pattern__.match(url)
72 path = m.group('path')
73 host = m.group('host')
74 lpath = os.path.join(data.getVar('DL_DIR', d, 1), host, os.path.basename(path))
77 def go(self, url, urldata, d):
78 dldir = data.getVar('DL_DIR', d, 1)
80 m = __pattern__.match(url)
81 path = m.group('path')
82 host = m.group('host')
83 port = m.group('port')
84 user = m.group('user')
85 password = m.group('pass')
87 ldir = os.path.join(dldir, host)
88 lpath = os.path.join(ldir, os.path.basename(path))
90 if not os.path.exists(ldir):
101 fr += ':%s' % password
109 cmd = 'scp -B -r %s %s %s/' % (
115 (exitstatus, output) = commands.getstatusoutput(cmd)
118 raise FetchError('Unable to fetch %s' % url)