Add ssh fetcher written by kergoth (from poky)
authorRichard Purdie <rpurdie@linux.intel.com>
Sat, 11 Nov 2006 19:10:44 +0000 (19:10 +0000)
committerRichard Purdie <rpurdie@linux.intel.com>
Sat, 11 Nov 2006 19:10:44 +0000 (19:10 +0000)
MANIFEST
lib/bb/fetch/__init__.py
lib/bb/fetch/ssh.py [new file with mode: 0644]

index 82f1a21..4a38019 100644 (file)
--- a/MANIFEST
+++ b/MANIFEST
@@ -24,6 +24,7 @@ lib/bb/fetch/cvs.py
 lib/bb/fetch/git.py
 lib/bb/fetch/__init__.py
 lib/bb/fetch/local.py
+lib/bb/fetch/ssh.py
 lib/bb/fetch/svk.py
 lib/bb/fetch/svn.py
 lib/bb/fetch/wget.py
index cc246fa..9460116 100644 (file)
@@ -221,6 +221,7 @@ import local
 import svn
 import wget
 import svk
+import ssh
 
 methods.append(cvs.Cvs())
 methods.append(git.Git())
@@ -228,3 +229,4 @@ methods.append(local.Local())
 methods.append(svn.Svn())
 methods.append(wget.Wget())
 methods.append(svk.Svk())
+methods.append(ssh.SSH())
diff --git a/lib/bb/fetch/ssh.py b/lib/bb/fetch/ssh.py
new file mode 100644 (file)
index 0000000..57874d5
--- /dev/null
@@ -0,0 +1,122 @@
+#!/usr/bin/env python
+# ex:ts=4:sw=4:sts=4:et
+# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
+'''
+BitBake 'Fetch' implementations
+
+This implementation is for Secure Shell (SSH), and attempts to comply with the
+IETF secsh internet draft:
+    http://tools.ietf.org/wg/secsh/draft-ietf-secsh-scp-sftp-ssh-uri/
+
+    Currently does not support the sftp parameters, as this uses scp
+    Also does not support the 'fingerprint' connection parameter.
+
+Copyright (C) 2006  OpenedHand Ltd.
+
+Based in part on svk.py:
+    Copyright (C) 2006 Holger Hans Peter Freyther
+    Based on svn.py:
+        Copyright (C) 2003, 2004  Chris Larson
+        Based on functions from the base bb module:
+            Copyright 2003 Holger Schurig
+
+
+This program is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free Software
+Foundation; either version 2 of the License, or (at your option) any later
+version.
+
+This program is distributed in the hope that it will be useful, but WITHOUT
+ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License along with
+this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+Place, Suite 330, Boston, MA 02111-1307 USA.
+'''
+import re, os
+import bb
+from   bb import data
+from   bb.fetch import Fetch
+from   bb.fetch import FetchError
+from   bb.fetch import MissingParameterError
+
+
+__pattern__ = re.compile(r'''
+ \s*                 # Skip leading whitespace
+ ssh://              # scheme
+ (                   # Optional username/password block
+  (?P<user>\S+)      # username
+  (:(?P<pass>\S+))?  # colon followed by the password (optional)
+ )?
+ (?P<cparam>(;[^;]+)*)?  # connection parameters block (optional)
+ @
+ (?P<host>\S+?)          # non-greedy match of the host
+ (:(?P<port>[0-9]+))?    # colon followed by the port (optional)
+ /
+ (?P<path>[^;]+)         # path on the remote system, may be absolute or relative,
+                         # and may include the use of '~' to reference the remote home
+                         # directory
+ (?P<sparam>(;[^;]+)*)?  # parameters block (optional)
+ $
+''', re.VERBOSE)
+
+class SSH(Fetch):
+    '''Class to fetch a module or modules via Secure Shell'''
+
+    def supports(self, url, d):
+        return __pattern__.match(url) != None
+
+    def localpath(self, url, d):
+        m = __pattern__.match(url)
+        path = m.group('path')
+        host = m.group('host')
+        lpath = os.path.join(data.getVar('DL_DIR', d, 1), host, os.path.basename(path))
+        return lpath
+
+    def go(self, d, urls = []):
+        if not urls:
+            urls = self.urls
+
+        for url in urls:
+            dldir = data.getVar('DL_DIR', d, 1)
+
+            m = __pattern__.match(url)
+            path = m.group('path')
+            host = m.group('host')
+            port = m.group('port')
+            user = m.group('user')
+            password = m.group('pass')
+
+            ldir = os.path.join(dldir, host)
+            lpath = os.path.join(ldir, os.path.basename(path))
+
+            if not os.path.exists(ldir):
+                os.makedirs(ldir)
+
+            if port:
+                port = '-P %s' % port
+            else:
+                port = ''
+
+            if user:
+                fr = user
+                if password:
+                    fr += ':%s' % password
+                fr += '@%s' % host
+            else:
+                fr = host
+            fr += ':%s' % path
+
+
+            import commands
+            cmd = 'scp -B -r %s %s %s/' % (
+                port,
+                commands.mkarg(fr),
+                commands.mkarg(ldir)
+            )
+
+            (exitstatus, output) = commands.getstatusoutput(cmd)
+            if exitstatus != 0:
+                print output
+                raise FetchError('Unable to fetch %s' % url)