summaryrefslogtreecommitdiffstats
path: root/bitbake-dev/lib/bb/fetch/ssh.py
diff options
context:
space:
mode:
Diffstat (limited to 'bitbake-dev/lib/bb/fetch/ssh.py')
-rw-r--r--bitbake-dev/lib/bb/fetch/ssh.py120
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'''
4BitBake 'Fetch' implementations
5
6This implementation is for Secure Shell (SSH), and attempts to comply with the
7IETF 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
39import re, os
40import bb
41from bb import data
42from bb.fetch import Fetch
43from bb.fetch import FetchError
44from 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
66class 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)