Skip to contentSkip to conversation

fetch2: SFTP fetcher and restructure of decodeurl

PATCH Superseded Olof Johansson 4 participants 23 messages Jan 21, 2013 – Feb 20, 2013

lore
Share & tools
lore
#0 lore raw

cover fetch2: SFTP fetcher and restructure of decodeurl

Hi,

In our early work in migrating to poky we realized that bitbake's current SSH fetcher doesn't really suite our needs. It suffers from some specification conformance bugs --- some which may be easily worked around. However, this patch series instead introduces a new "SFTP" fetcher, meant to in a way, replace the SSH fetcher, with stricter conformance to the SECSH URI spec [1].

The SSH fetcher has its own URI parsing, and can not rely on bb.fetch2.decodeurl. I found that decodeurl was hard to extend, with it returning a tuple. This prompted me to write a generic URI class, with attributes for the various URI components (and some general bitbake kludges, like support relative file:// uris).

I realize that these changes are a bit bold and non-trivial, but I hope you'll find time to review them and point out problems to fix. If my reasoning is completely wrong, please let me know and I can try to solve our direct problems with the SSH fetcher with minimal changes instead.

The changes come with unittests for the URI class; it passes all the tests in bb.tests.fetch and all other tests under bb.tests, except bb.tests.data.DataExpansions, but the same errors are present on master as well. I've also tested running bitbake core-image-minimal in a new tree without any issues.

Olof Johansson (6):
fetch2: Remove unused code in wget fetcher
fetch2: Add a class representing a generic URI
fetch2: unittests for bb.fetch2.URI class
fetch2: Adapt encode/decode url to use URI class
fetch2: Add editor modelines for bb.tests.*
fetch2: Add SFTP fetcher

 lib/bb/fetch2/__init__.py  |  262 +++++++++++++++++++++++++++++++++++---------
 lib/bb/fetch2/sftp.py      |  104 ++++++++++++++++++
 lib/bb/fetch2/wget.py      |    5 -
 lib/bb/tests/codeparser.py |    2 +
 lib/bb/tests/cow.py        |    2 +
 lib/bb/tests/data.py       |    2 +
 lib/bb/tests/fetch.py      |  228 ++++++++++++++++++++++++++++++++++++++
 lib/bb/tests/utils.py      |    2 +
 8 files changed, 553 insertions(+), 54 deletions(-)
 create mode 100644 lib/bb/fetch2/sftp.py

References:
1: http://tools.ietf.org/html/draft-ietf-secsh-scp-sftp-ssh-uri-04

Signature · 3 lines
Olof Johansson
Tools engineer
(IRC: zibri on Freenode)
#1 lore raw

PATCH 1/6 fetch2: Remove unused code in wget fetcher

---
 lib/bb/fetch2/wget.py |    5 -----
 1 file changed, 5 deletions(-)
bb/fetch2/wget.py +0 -5
index 2808df6..1fafc4a 100644
@@ -32,8 +32,6 @@ import urllib
 from   bb import data
 from   bb.fetch2 import FetchMethod
 from   bb.fetch2 import FetchError
-from   bb.fetch2 import encodeurl
-from   bb.fetch2 import decodeurl
 from   bb.fetch2 import logger
 from   bb.fetch2 import runfetchcmd
 
@@ -77,9 +75,6 @@ class Wget(FetchMethod):
             fetchcmd = d.getVar("FETCHCOMMAND_wget", True) or d.expand(basecmd + " -P ${DL_DIR} '${URI}'")
 
         uri = uri.split(";")[0]
-        uri_decoded = list(decodeurl(uri))
-        uri_type = uri_decoded[0]
-        uri_host = uri_decoded[1]
 
         fetchcmd = fetchcmd.replace("${URI}", uri.split(";")[0])
         fetchcmd = fetchcmd.replace("${FILE}", ud.basename)
Signature · 1 line
1.7.10.4
#2 lore raw

PATCH 2/6 fetch2: Add a class representing a generic URI

In reply to Olof Johansson

A class representing a generic URI, with methods for accessing the URI components, and stringifies to the URI. This class should be a bit more flexible than the existing {encode,decode}_url functions in that it supports more components (e.g. port) and that it does not rely on a specific order on the return values. This makes it easy to add new properties without affecting the API.

---
 lib/bb/fetch2/__init__.py |  194 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 194 insertions(+)
bb/fetch2/__init__.py +194 -0
index 150dc3c..3b83c0c 100644
@@ -30,6 +30,7 @@ from __future__ import print_function
 import os, re
 import logging
 import urllib
+from urlparse import urlparse
 import bb.persist_data, bb.utils
 import bb.checksum
 from bb import data
@@ -119,6 +120,199 @@ class NonLocalMethod(Exception):
     def __init__(self):
         Exception.__init__(self)
 
+
+class URI(object):
+    """
+    A class representing a generic URI, with methods for
+    accessing the URI components, and stringifies to the
+    URI.
+
+    It is constructed by calling it with a URI, or setting
+    the attributes manually:
+
+     uri = URI("http://example.com/")
+
+     uri = URI()
+     uri.scheme = 'http'
+     uri.hostname = 'example.com'
+     uri.path = '/'
+
+    It has the following attributes:
+
+      * scheme (read/write)
+      * userinfo (authentication information) (read/write)
+        * username (read/write)
+        * password (read/write)
+
+        Note, password is deprecated as of RFC 3986.
+
+      * hostname (read/write)
+      * port (read/write)
+      * hostport (read only)
+        "hostname:port", if both are set, otherwise just "hostname"
+      * path (read/write)
+      * path_quoted (read/write)
+        A URI quoted version of path
+      * params (dict) (read/write)
+      * relative (bool) (read only)
+        True if this is a "relative URI", (e.g. file:foo.diff)
+
+    It stringifies to the URI itself.
+
+    Some notes about relative URIs: while it's specified that
+    a URI beginning with <scheme>:// should either be directly
+    followed by a hostname or a /, the old URI handling of the
+    fetch2 library did not comform to this. Therefore, this URI
+    class has some kludges to make sure that URIs are parsed in
+    a way comforming to bitbake's current usage. This URI class
+    supports the following:
+
+     file:relative/path.diff (IETF compliant)
+     git:relative/path.git (IETF compliant)
+     git:///absolute/path.git (IETF compliant)
+     file:///absolute/path.diff (IETF compliant)
+
+     file://relative/path.diff (not IETF compliant)
+
+    But it does not support the following:
+
+     file://hostname/absolute/path.diff (would be IETF compliant)
+
+    Note that the last case only applies to a list of
+    "whitelisted" schemes (currently only file://), that requires
+    its URIs to not have a network location.
+    """
+
+    _relative_schemes = ['file', 'git']
+    _netloc_forbidden = ['file']
+
+    def __init__(self, uri=None):
+        self.scheme = ''
+        self.userinfo = ''
+        self.hostname = ''
+        self.port = None
+        self._path = ''
+        self.params = {}
+        self.relative = False
+
+        if not uri:
+            return
+
+        urlp = urlparse(uri)
+        self.scheme = urlp.scheme
+
+        # Convert URI to be relative
+        if urlp.scheme in self._netloc_forbidden:
+            uri = re.sub("(?<=:)//(?!/)", "", uri, 1)
+            urlp = urlparse(uri)
+
+        # Identify if the URI is relative or not
+        if urlp.scheme in self._relative_schemes and \
+           re.compile("^\w+:(?!//)").match(uri):
+            self.relative = True
+
+        if not self.relative:
+            self.hostname = urlp.hostname or ''
+            self.port = urlp.port
+
+            self.userinfo += urlp.username or ''
+
+            if urlp.password:
+                self.userinfo += ':%s' % urlp.password
+
+        # Do support params even for URI schemes that Python's
+        # urlparse doesn't support params for.
+        path = ''
+        param_str = ''
+        if not urlp.params:
+            path, param_str = (list(urlp.path.split(";", 1)) + [None])[:2]
+        else:
+            path = urlp.path
+            param_str = urlp.params
+
+        self.path = urllib.unquote(path)
+
+        if param_str:
+            self.params = self._param_dict(param_str)
+
+    def __str__(self):
+        userinfo = self.userinfo
+        if userinfo:
+            userinfo += '@'
+
+        return "%s:%s%s%s%s%s" % (
+            self.scheme,
+            '' if self.relative else '//',
+            userinfo,
+            self.hostport,
+            self.path_quoted,
+            self._param_str)
+
+    @property
+    def _param_str(self):
+        ret = ''
+        for key, val in self.params.items():
+            ret += ";%s=%s" % (key, val)
+        return ret
+
+    def _param_dict(self, param_str):
+        parm = {}
+
+        for keyval in param_str.split(";"):
+            key, val = keyval.split("=", 1)
+            parm[key] = val
+
+        return parm
+
+    @property
+    def hostport(self):
+        if not self.port:
+            return self.hostname
+        return "%s:%d" % (self.hostname, self.port)
+
+    @property
+    def path_quoted(self):
+        return urllib.quote(self.path)
+
+    @path_quoted.setter
+    def path_quoted(self, path):
+        self.path = urllib.unquote(path)
+
+    @property
+    def path(self):
+        return self._path
+
+    @path.setter
+    def path(self, path):
+        self._path = path
+
+        if re.compile("^/").match(path):
+            self.relative = False
+        else:
+            self.relative = True
+
+    @property
+    def username(self):
+        if self.userinfo:
+            return (self.userinfo.split(":", 1))[0]
+        return ''
+
+    @username.setter
+    def username(self, username):
+        self.userinfo = username
+        if self.password:
+            self.userinfo += ":%s" % self.password
+
+    @property
+    def password(self):
+        if self.userinfo and ":" in self.userinfo:
+            return (self.userinfo.split(":", 1))[1]
+        return ''
+
+    @password.setter
+    def password(self, password):
+        self.userinfo = "%s:%s" % (self.username, password)
+
 def decodeurl(url):
     """Decodes an URL into the tokens (scheme, network location, path,
     user, password, parameters).
Signature · 1 line
1.7.10.4
#3 lore raw

PATCH 3/6 fetch2: unittests for bb.fetch2.URI class

In reply to Olof Johansson
---
 lib/bb/tests/fetch.py |  226 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 226 insertions(+)
bb/tests/fetch.py +226 -0
index 67eda59..e765ca7 100644
@@ -21,8 +21,234 @@ import unittest
 import tempfile
 import subprocess
 import os
+from bb.fetch2 import URI
 import bb
 
+class URITest(unittest.TestCase):
+    test_uris = {
+        "http://www.google.com/index.html" : {
+            'uri': 'http://www.google.com/index.html',
+            'scheme': 'http',
+            'hostname': 'www.google.com',
+            'port': None,
+            'hostport': 'www.google.com',
+            'path': '/index.html',
+            'userinfo': '',
+            'username': '',
+            'password': '',
+            'params': {},
+            'relative': False
+        },
+        "http://www.google.com/index.html;param1=value1" : {
+            'uri': 'http://www.google.com/index.html;param1=value1',
+            'scheme': 'http',
+            'hostname': 'www.google.com',
+            'port': None,
+            'hostport': 'www.google.com',
+            'path': '/index.html',
+            'userinfo': '',
+            'username': '',
+            'password': '',
+            'params': {
+                'param1': 'value1'
+            },
+            'relative': False
+        },
+        "http://www.example.com:8080/index.html" : {
+            'uri': 'http://www.example.com:8080/index.html',
+            'scheme': 'http',
+            'hostname': 'www.example.com',
+            'port': 8080,
+            'hostport': 'www.example.com:8080',
+            'path': '/index.html',
+            'userinfo': '',
+            'username': '',
+            'password': '',
+            'params': {},
+            'relative': False
+        },
+        "cvs://[email protected]/cvs;module=familiar/dist/ipkg" : {
+            'uri': 'cvs://[email protected]/cvs;module=familiar/dist/ipkg',
+            'scheme': 'cvs',
+            'hostname': 'cvs.handhelds.org',
+            'port': None,
+            'hostport': 'cvs.handhelds.org',
+            'path': '/cvs',
+            'userinfo': 'anoncvs',
+            'username': 'anoncvs',
+            'password': '',
+            'params': {
+                'module': 'familiar/dist/ipkg'
+            },
+            'relative': False
+        },
+        "cvs://anoncvs:[email protected]/cvs;tag=V0-99-81;module=familiar/dist/ipkg": {
+            'uri': 'cvs://anoncvs:[email protected]/cvs;tag=V0-99-81;module=familiar/dist/ipkg',
+            'scheme': 'cvs',
+            'hostname': 'cvs.handhelds.org',
+            'port': None,
+            'hostport': 'cvs.handhelds.org',
+            'path': '/cvs',
+            'userinfo': 'anoncvs:anonymous',
+            'username': 'anoncvs',
+            'password': 'anonymous',
+            'params': {
+                'tag': 'V0-99-81',
+                'module': 'familiar/dist/ipkg'
+            },
+            'relative': False
+        },
+        "file://example.diff": { # NOTE: Not RFC compliant!
+            'uri': 'file:example.diff',
+            'scheme': 'file',
+            'hostname': '',
+            'port': None,
+            'hostport': '',
+            'path': 'example.diff',
+            'userinfo': '',
+            'username': '',
+            'password': '',
+            'params': {},
+            'relative': True
+        },
+        "file:example.diff": { # NOTE: RFC compliant version of the former
+            'uri': 'file:example.diff',
+            'scheme': 'file',
+            'hostname': '',
+            'port': None,
+            'hostport': '',
+            'path': 'example.diff',
+            'userinfo': '',
+            'userinfo': '',
+            'username': '',
+            'password': '',
+            'params': {},
+            'relative': True
+        },
+        "file:///tmp/example.diff": {
+            'uri': 'file:///tmp/example.diff',
+            'scheme': 'file',
+            'hostname': '',
+            'port': None,
+            'hostport': '',
+            'path': '/tmp/example.diff',
+            'userinfo': '',
+            'userinfo': '',
+            'username': '',
+            'password': '',
+            'params': {},
+            'relative': False
+        },
+        "git:///path/example.git": {
+            'uri': 'git:///path/example.git',
+            'scheme': 'git',
+            'hostname': '',
+            'port': None,
+            'hostport': '',
+            'path': '/path/example.git',
+            'userinfo': '',
+            'userinfo': '',
+            'username': '',
+            'password': '',
+            'params': {},
+            'relative': False
+        },
+        "git:path/example.git": {
+            'uri': 'git:path/example.git',
+            'scheme': 'git',
+            'hostname': '',
+            'port': None,
+            'hostport': '',
+            'path': 'path/example.git',
+            'userinfo': '',
+            'userinfo': '',
+            'username': '',
+            'password': '',
+            'params': {},
+            'relative': True
+        },
+        "git://example.net/path/example.git": {
+            'uri': 'git://example.net/path/example.git',
+            'scheme': 'git',
+            'hostname': 'example.net',
+            'port': None,
+            'hostport': 'example.net',
+            'path': '/path/example.git',
+            'userinfo': '',
+            'userinfo': '',
+            'username': '',
+            'password': '',
+            'params': {},
+            'relative': False
+        }
+    }
+
+    def test_uri(self):
+        for test_uri, ref in self.test_uris.items():
+            uri = URI(test_uri)
+
+            self.assertEqual(str(uri), ref['uri'])
+
+            # expected attributes
+            self.assertEqual(uri.scheme, ref['scheme'])
+
+            self.assertEqual(uri.userinfo, ref['userinfo'])
+            self.assertEqual(uri.username, ref['username'])
+            self.assertEqual(uri.password, ref['password'])
+
+            self.assertEqual(uri.hostname, ref['hostname'])
+            self.assertEqual(uri.port, ref['port'])
+            self.assertEqual(uri.hostport, ref['hostport'])
+
+            self.assertEqual(uri.path, ref['path'])
+            self.assertEqual(uri.params, ref['params'])
+
+            self.assertEqual(uri.relative, ref['relative'])
+
+    def test_dict(self):
+        for test in self.test_uris.values():
+            uri = URI()
+
+            self.assertEqual(uri.scheme, '')
+            self.assertEqual(uri.userinfo, '')
+            self.assertEqual(uri.username, '')
+            self.assertEqual(uri.password, '')
+            self.assertEqual(uri.hostname, '')
+            self.assertEqual(uri.port, None)
+            self.assertEqual(uri.path, '')
+            self.assertEqual(uri.params, {})
+
+
+            uri.scheme = test['scheme']
+            self.assertEqual(uri.scheme, test['scheme'])
+
+            uri.userinfo = test['userinfo']
+            self.assertEqual(uri.userinfo, test['userinfo'])
+            self.assertEqual(uri.username, test['username'])
+            self.assertEqual(uri.password, test['password'])
+
+            uri.hostname = test['hostname']
+            self.assertEqual(uri.hostname, test['hostname'])
+            self.assertEqual(uri.hostport, test['hostname'])
+
+            uri.port = test['port']
+            self.assertEqual(uri.port, test['port'])
+            self.assertEqual(uri.hostport, test['hostport'])
+
+            uri.path = test['path']
+            self.assertEqual(uri.path, test['path'])
+
+            uri.params = test['params']
+            self.assertEqual(uri.params, test['params'])
+
+            self.assertEqual(str(uri)+str(uri.relative), str(test['uri'])+str(test['relative']))
+
+            self.assertEqual(str(uri), test['uri'])
+
+            uri.params = {}
+            self.assertEqual(uri.params, {})
+            self.assertEqual(str(uri), (str(uri).split(";"))[0])
+
 
 class FetcherTest(unittest.TestCase):
 
Signature · 1 line
1.7.10.4
#4 lore raw

PATCH 4/6 fetch2: Adapt encode/decode url to use URI class

In reply to Olof Johansson
---
 lib/bb/fetch2/__init__.py |   66 ++++++++++++---------------------------------
 1 file changed, 17 insertions(+), 49 deletions(-)
bb/fetch2/__init__.py +17 -49
index 3b83c0c..549e261 100644
@@ -318,40 +318,9 @@ def decodeurl(url):
     user, password, parameters).
     """
 
-    m = re.compile('(?P<type>[^:]*)://((?P<user>.+)@)?(?P<location>[^;]+)(;(?P<parm>.*))?').match(url)
-    if not m:
-        raise MalformedUrl(url)
-
-    type = m.group('type')
-    location = m.group('location')
-    if not location:
-        raise MalformedUrl(url)
-    user = m.group('user')
-    parm = m.group('parm')
-
-    locidx = location.find('/')
-    if locidx != -1 and type.lower() != 'file':
-        host = location[:locidx]
-        path = location[locidx:]
-    else:
-        host = ""
-        path = location
-    if user:
-        m = re.compile('(?P<user>[^:]+)(:?(?P<pswd>.*))').match(user)
-        if m:
-            user = m.group('user')
-            pswd = m.group('pswd')
-    else:
-        user = ''
-        pswd = ''
-
-    p = {}
-    if parm:
-        for s in parm.split(';'):
-            s1, s2 = s.split('=')
-            p[s1] = s2
-
-    return type, host, urllib.unquote(path), user, pswd, p
+    urlo = URI(url)
+    return (urlo.scheme, urlo.hostport, urlo.path,
+            urlo.username, urlo.password, urlo.params)
 
 def encodeurl(decoded):
     """Encodes a URL from tokens (scheme, network location, path,
@@ -360,27 +329,26 @@ def encodeurl(decoded):
 
     type, host, path, user, pswd, p = decoded
 
+    urlo = URI()
+
     if not path:
         raise MissingParameterError('path', "encoded from the data %s" % str(decoded))
     if not type:
         raise MissingParameterError('type', "encoded from the data %s" % str(decoded))
-    url = '%s://' % type
-    if user and type != "file":
-        url += "%s" % user
-        if pswd:
-            url += ":%s" % pswd
-        url += "@"
-    if host and type != "file":
-        url += "%s" % host
-    # Standardise path to ensure comparisons work
-    while '//' in path:
-        path = path.replace("//", "/")
-    url += "%s" % urllib.quote(path)
+
+    urlo.scheme = type
+    urlo.path = path
+
+    if host:
+        urlo.hostname = host
+    if user:
+        urlo.username = user
+    if pswd:
+        urlo.password = pswd
     if p:
-        for parm in p:
-            url += ";%s=%s" % (parm, p[parm])
+        urlo.params = p
 
-    return url
+    return str(urlo)
 
 def uri_replace(ud, uri_find, uri_replace, replacements, d):
     if not ud.url or not uri_find or not uri_replace:
Signature · 1 line
1.7.10.4
#5 lore raw

PATCH 5/6 fetch2: Add editor modelines for bb.tests.*

In reply to Olof Johansson
---
 lib/bb/tests/codeparser.py |    2 ++
 lib/bb/tests/cow.py        |    2 ++
 lib/bb/tests/data.py       |    2 ++
 lib/bb/tests/fetch.py      |    2 ++
 lib/bb/tests/utils.py      |    2 ++
 5 files changed, 10 insertions(+)
bb/tests/codeparser.py +2 -0
index 9b2d588..d2bd4a2 100644
@@ -1,3 +1,5 @@
+# ex:ts=4:sw=4:sts=4:et
+# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
 #
 # BitBake Test for codeparser.py
 #
bb/tests/cow.py +2 -0
index 599b2aa..35c5841 100644
@@ -1,3 +1,5 @@
+# ex:ts=4:sw=4:sts=4:et
+# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
 #
 # BitBake Tests for Copy-on-Write (cow.py)
 #
bb/tests/data.py +2 -0
index b2ab8ee..5161586 100644
@@ -1,3 +1,5 @@
+# ex:ts=4:sw=4:sts=4:et
+# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
 #
 # BitBake Tests for the Data Store (data.py/data_smart.py)
 #
bb/tests/fetch.py +2 -0
index e765ca7..778d94f 100644
@@ -1,3 +1,5 @@
+# ex:ts=4:sw=4:sts=4:et
+# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
 #
 # BitBake Tests for the Fetcher (fetch2/)
 #
bb/tests/utils.py +2 -0
index 9f60491..7c50b1d 100644
@@ -1,3 +1,5 @@
+# ex:ts=4:sw=4:sts=4:et
+# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
 #
 # BitBake Tests for utils.py
 #
Signature · 1 line
1.7.10.4
#6 lore raw

PATCH 6/6 fetch2: Add SFTP fetcher

In reply to Olof Johansson

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.

---
 lib/bb/fetch2/__init__.py |    2 +
 lib/bb/fetch2/sftp.py     |  104 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 106 insertions(+)
 create mode 100644 lib/bb/fetch2/sftp.py
bb/fetch2/__init__.py +2 -0
index 549e261..86302f7 100644
@@ -1448,6 +1448,7 @@ from . import svn
 from . import wget
 from . import svk
 from . import ssh
+from . import sftp
 from . import perforce
 from . import bzr
 from . import hg
@@ -1461,6 +1462,7 @@ methods.append(git.Git())
 methods.append(cvs.Cvs())
 methods.append(svk.Svk())
 methods.append(ssh.SSH())
+methods.append(sftp.SFTP())
 methods.append(perforce.Perforce())
 methods.append(bzr.Bzr())
 methods.append(hg.Hg())
bb/fetch2/sftp.py new file +104 -0

104 lines not on this page · raw message

Signature · 1 line
1.7.10.4
#7 lore raw

Re: [PATCH 6/6] fetch2: Add SFTP fetcher

Quoted 94 lines · Olof Johansson

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.

---
 lib/bb/fetch2/__init__.py |    2 +
 lib/bb/fetch2/sftp.py     |  104 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 106 insertions(+)
 create mode 100644 lib/bb/fetch2/sftp.py
bb/fetch2/__init__.py +2 -0
index 549e261..86302f7 100644
@@ -1448,6 +1448,7 @@ from . import svn
 from . import wget
 from . import svk
 from . import ssh
+from . import sftp
 from . import perforce
 from . import bzr
 from . import hg
@@ -1461,6 +1462,7 @@ methods.append(git.Git())
 methods.append(cvs.Cvs())
 methods.append(svk.Svk())
 methods.append(ssh.SSH())
+methods.append(sftp.SFTP())
 methods.append(perforce.Perforce())
 methods.append(bzr.Bzr())
 methods.append(hg.Hg())
bb/fetch2/sftp.py new file +57 -0
new file mode 100644
index 0000000..0902ce7
@@ -0,0 +1,104 @@
+# ex:ts=4:sw=4:sts=4:et
+# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
+"""
+BitBake SFTP Fetch implementation
+
+Class for fetching files via SFTP. It tries to adhere to the (now
+expired) IETF Internet Draft for "Uniform Resource Identifier (URI)
+Scheme for Secure File Transfer Protocol (SFTP) and Secure Shell
+(SSH)" (SECSH URI).
+
+It uses SFTP (as to adhere to the SECSH URI specification). It only
+supports key based authentication, not password. This class, unlike
+the SSH fetcher, does not support fetching a directory tree from the
+remote.
+
+  http://tools.ietf.org/html/draft-ietf-secsh-scp-sftp-ssh-uri-04
+  https://www.iana.org/assignments/uri-schemes/prov/sftp
+  https://tools.ietf.org/html/draft-ietf-secsh-filexfer-13
+
+"""
+
+# Copyright (C) 2013, Olof Johansson <[email protected]>
+#
+# Based in part on bb.fetch2.wget:
+#    Copyright (C) 2003, 2004  Chris Larson
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 2 as
+# published by the Free Software Foundation.
+#
+# 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.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Based on functions from the base bb module, Copyright 2003 Holger Schurig
+
+import os
+import bb
+import urllib
+import commands
+from bb import data
+from bb.fetch2 import URI
+from bb.fetch2 import FetchMethod
+from bb.fetch2 import runfetchcmd
+
+
+class SFTP(FetchMethod):
+    """Class to fetch urls via 'sftp'"""
+    def supports(self, url, ud, d):
+        """
+        Check to see if a given url can be fetched with sftp.
+        """

bb/fetch2/sftp.py line 67

Quoted 10 lines
bb/fetch2/sftp.py new file +10 -0
+        return ud.type in ['sftp']
+
+    def recommends_checksum(self, urldata):
+        return True
+
+    def urldata_init(self, ud, d):
+        if 'protocol' in ud.parm and ud.parm['protocol'] == 'git':
+            raise bb.fetch2.ParameterError(
+                "Invalid protocol - if you wish to fetch from a git " +
+                "repository using ssh, you need to instead use the " +

extra 'instead' ^ ?

But I like this error, will add the same to ssh.py fetcher (which I'm now trying to fix).

Quoted 45 lines
bb/fetch2/sftp.py new file +37 -0
+                "git:// prefix with protocol=ssh", ud.url)
+
+        if 'downloadfilename' in ud.parm:
+            ud.basename = ud.parm['downloadfilename']
+        else:
+            ud.basename = os.path.basename(ud.path)
+
+        ud.localfile = data.expand(urllib.unquote(ud.basename), d)
+
+    def download(self, uri, ud, d):
+        """Fetch urls"""
+
+        urlo = URI(uri)
+        basecmd = 'sftp -oPasswordAuthentication=no'
+        port = ''
+        if urlo.port:
+            port = '-P %d' % urlo.port
+            urlo.port = None
+
+        dldir = data.getVar('DL_DIR', d, True)
+        lpath = os.path.join(dldir, ud.localfile)
+
+        user = ''
+        if urlo.userinfo:
+            user = urlo.userinfo + '@'
+
+        remote = '%s%s:%s' % (user, urlo.hostname, urlo.path)
+
+        cmd = '%s %s %s %s' % (basecmd, port, commands.mkarg(remote),
+                               commands.mkarg(lpath))
+
+        bb.fetch2.check_network_access(d, cmd, uri)
+        runfetchcmd(cmd, d)
+        return True
+
+    def checkstatus(self, uri, ud, d):
+        return self.download(uri, ud, d, True)
Signature · 7 lines
1.7.10.4


_______________________________________________
bitbake-devel mailing list
[email protected]
http://lists.linuxtogo.org/cgi-bin/mailman/listinfo/bitbake-devel
Signature · 1 line
Martin 'JaMa' Jansa     jabber: [email protected]
#8 lore raw

Re: [PATCH 6/6] fetch2: Add SFTP fetcher

Quoted 9 lines · Martin Jansa

bb/fetch2/sftp.py line 67

Quoted 3 lines · Olof Johansson
bb/fetch2/sftp.py new file +3 -0
+            raise bb.fetch2.ParameterError(
+                "Invalid protocol - if you wish to fetch from a git " +
+                "repository using ssh, you need to instead use the " +

extra 'instead' ^ ?

But I like this error, will add the same to ssh.py fetcher (which I'm now trying to fix).

That is shamelessly stolen from the wget fetcher :-). The "instead" may be redundant, can remove it.

Signature · 1 line
Olof Johansson
#9 lore raw

Re: [PATCH 6/6] fetch2: Add SFTP fetcher

In reply to Olof Johansson
Quoted 121 lines · Olof Johansson

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.

---
 lib/bb/fetch2/__init__.py |    2 +
 lib/bb/fetch2/sftp.py     |  104 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 106 insertions(+)
 create mode 100644 lib/bb/fetch2/sftp.py
bb/fetch2/__init__.py +2 -0
index 549e261..86302f7 100644
@@ -1448,6 +1448,7 @@ from . import svn
 from . import wget
 from . import svk
 from . import ssh
+from . import sftp
 from . import perforce
 from . import bzr
 from . import hg
@@ -1461,6 +1462,7 @@ methods.append(git.Git())
 methods.append(cvs.Cvs())
 methods.append(svk.Svk())
 methods.append(ssh.SSH())
+methods.append(sftp.SFTP())
 methods.append(perforce.Perforce())
 methods.append(bzr.Bzr())
 methods.append(hg.Hg())
bb/fetch2/sftp.py new file +84 -0
new file mode 100644
index 0000000..0902ce7
@@ -0,0 +1,104 @@
+# ex:ts=4:sw=4:sts=4:et
+# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
+"""
+BitBake SFTP Fetch implementation
+
+Class for fetching files via SFTP. It tries to adhere to the (now
+expired) IETF Internet Draft for "Uniform Resource Identifier (URI)
+Scheme for Secure File Transfer Protocol (SFTP) and Secure Shell
+(SSH)" (SECSH URI).
+
+It uses SFTP (as to adhere to the SECSH URI specification). It only
+supports key based authentication, not password. This class, unlike
+the SSH fetcher, does not support fetching a directory tree from the
+remote.
+
+  http://tools.ietf.org/html/draft-ietf-secsh-scp-sftp-ssh-uri-04
+  https://www.iana.org/assignments/uri-schemes/prov/sftp
+  https://tools.ietf.org/html/draft-ietf-secsh-filexfer-13
+
+"""
+
+# Copyright (C) 2013, Olof Johansson <[email protected]>
+#
+# Based in part on bb.fetch2.wget:
+#    Copyright (C) 2003, 2004  Chris Larson
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 2 as
+# published by the Free Software Foundation.
+#
+# 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.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Based on functions from the base bb module, Copyright 2003 Holger Schurig
+
+import os
+import bb
+import urllib
+import commands
+from bb import data
+from bb.fetch2 import URI
+from bb.fetch2 import FetchMethod
+from bb.fetch2 import runfetchcmd
+
+
+class SFTP(FetchMethod):
+    """Class to fetch urls via 'sftp'"""
+    def supports(self, url, ud, d):
+        """
+        Check to see if a given url can be fetched with sftp.
+        """
+        return ud.type in ['sftp']
+
+    def recommends_checksum(self, urldata):
+        return True
+
+    def urldata_init(self, ud, d):
+        if 'protocol' in ud.parm and ud.parm['protocol'] == 'git':
+            raise bb.fetch2.ParameterError(
+                "Invalid protocol - if you wish to fetch from a git " +
+                "repository using ssh, you need to instead use the " +
+                "git:// prefix with protocol=ssh", ud.url)
+
+        if 'downloadfilename' in ud.parm:
+            ud.basename = ud.parm['downloadfilename']
+        else:
+            ud.basename = os.path.basename(ud.path)
+
+        ud.localfile = data.expand(urllib.unquote(ud.basename), d)
+
+    def download(self, uri, ud, d):
+        """Fetch urls"""
+
+        urlo = URI(uri)
+        basecmd = 'sftp -oPasswordAuthentication=no'
+        port = ''
+        if urlo.port:
+            port = '-P %d' % urlo.port

bb/fetch2/sftp.py line 94

Quoted 10 lines
bb/fetch2/sftp.py new file +10 -0
+            urlo.port = None
+
+        dldir = data.getVar('DL_DIR', d, True)
+        lpath = os.path.join(dldir, ud.localfile)
+
+        user = ''
+        if urlo.userinfo:
+            user = urlo.userinfo + '@'
+
+        remote = '%s%s:%s' % (user, urlo.hostname, urlo.path)

Please add some SRC_URI examples, it always surprise me that there isn't ':' as host-path separator, but '/' and error as returned from bitbake ia not so easy to read.

Also it looks like optional ~ syntax is not supported sftp://[email protected]/~/file.txt

But it should be easy to implement if you remove '^/~/' from urlo.path.

Cheers,

Quoted 18 lines
bb/fetch2/sftp.py new file +10 -0
+
+        cmd = '%s %s %s %s' % (basecmd, port, commands.mkarg(remote),
+                               commands.mkarg(lpath))
+
+        bb.fetch2.check_network_access(d, cmd, uri)
+        runfetchcmd(cmd, d)
+        return True
+
+    def checkstatus(self, uri, ud, d):
+        return self.download(uri, ud, d, True)
Signature · 7 lines
1.7.10.4


_______________________________________________
bitbake-devel mailing list
[email protected]
http://lists.linuxtogo.org/cgi-bin/mailman/listinfo/bitbake-devel
Signature · 1 line
Martin 'JaMa' Jansa     jabber: [email protected]
#10 lore raw
In reply to Olof Johansson
Quoted 19 lines · Olof Johansson

Hi,

In our early work in migrating to poky we realized that bitbake's current SSH fetcher doesn't really suite our needs. It suffers from some specification conformance bugs --- some which may be easily worked around. However, this patch series instead introduces a new "SFTP" fetcher, meant to in a way, replace the SSH fetcher, with stricter conformance to the SECSH URI spec [1].

The SSH fetcher has its own URI parsing, and can not rely on bb.fetch2.decodeurl. I found that decodeurl was hard to extend, with it returning a tuple. This prompted me to write a generic URI class, with attributes for the various URI components (and some general bitbake kludges, like support relative file:// uris).

I realize that these changes are a bit bold and non-trivial, but I hope you'll find time to review them and point out problems to fix. If my reasoning is completely wrong, please let me know and I can try to solve our direct problems with the SSH fetcher with minimal changes instead.

Quoted 6 lines

The changes come with unittests for the URI class; it passes all the tests in bb.tests.fetch and all other tests under bb.tests, except bb.tests.data.DataExpansions, but the same errors are present on master as well. I've also tested running bitbake core-image-minimal in a new tree without any issues.

Can you please rebase your patchset on latest master?

2nd patch conflicts with
commit 22bd19d208f0251f5a1f9b98f3cac66181f3fc07

Author: Tyler Hall <[email protected]>
Date:   Wed Dec 19 18:26:50 2012 -0500
fetch2: Sort file checksums by value, not path

Are those patches generated from bitbake repo?
They start with 'lib/' so patch -p0 is needed instead of default -p1 and cannot be applied directly from pw-am.sh :/.

Or please provide URL to your bitbake branch.

Cheers,

Quoted 32 lines

Olof Johansson (6):
fetch2: Remove unused code in wget fetcher
fetch2: Add a class representing a generic URI
fetch2: unittests for bb.fetch2.URI class
fetch2: Adapt encode/decode url to use URI class
fetch2: Add editor modelines for bb.tests.*
fetch2: Add SFTP fetcher

 lib/bb/fetch2/__init__.py  |  262 +++++++++++++++++++++++++++++++++++---------
 lib/bb/fetch2/sftp.py      |  104 ++++++++++++++++++
 lib/bb/fetch2/wget.py      |    5 -
 lib/bb/tests/codeparser.py |    2 +
 lib/bb/tests/cow.py        |    2 +
 lib/bb/tests/data.py       |    2 +
 lib/bb/tests/fetch.py      |  228 ++++++++++++++++++++++++++++++++++++++
 lib/bb/tests/utils.py      |    2 +
 8 files changed, 553 insertions(+), 54 deletions(-)
 create mode 100644 lib/bb/fetch2/sftp.py

References:
1: http://tools.ietf.org/html/draft-ietf-secsh-scp-sftp-ssh-uri-04

Signature · 8 lines
Olof Johansson
Tools engineer
(IRC: zibri on Freenode)

_______________________________________________
bitbake-devel mailing list
[email protected]
http://lists.linuxtogo.org/cgi-bin/mailman/listinfo/bitbake-devel
Signature · 1 line
Martin 'JaMa' Jansa     jabber: [email protected]
#11 lore raw
Quoted 11 lines · Martin Jansa

Can you please rebase your patchset on latest master?

2nd patch conflicts with
commit 22bd19d208f0251f5a1f9b98f3cac66181f3fc07

Author: Tyler Hall <[email protected]>
Date:   Wed Dec 19 18:26:50 2012 -0500
fetch2: Sort file checksums by value, not path

Are those patches generated from bitbake repo?
They start with 'lib/' so patch -p0 is needed instead of default -p1 and cannot be applied directly from pw-am.sh :/.

Sorry, will fix, but not until later this evening unfortunately.

(I've set git config diff.noprefix=true without realizing the implications in cases like this. Will remove it.)

Signature · 1 line
Olof Johansson
#12 lore raw

PATCH v2 1/6 fetch2: Remove unused code in wget fetcher

In reply to Olof Johansson
---
 lib/bb/fetch2/wget.py |    5 -----
 1 file changed, 5 deletions(-)
lib/bb/fetch2/wget.py +0 -5
index 2808df6..1fafc4a 100644
@@ -32,8 +32,6 @@ import urllib
 from   bb import data
 from   bb.fetch2 import FetchMethod
 from   bb.fetch2 import FetchError
-from   bb.fetch2 import encodeurl
-from   bb.fetch2 import decodeurl
 from   bb.fetch2 import logger
 from   bb.fetch2 import runfetchcmd
 
@@ -77,9 +75,6 @@ class Wget(FetchMethod):
             fetchcmd = d.getVar("FETCHCOMMAND_wget", True) or d.expand(basecmd + " -P ${DL_DIR} '${URI}'")
 
         uri = uri.split(";")[0]
-        uri_decoded = list(decodeurl(uri))
-        uri_type = uri_decoded[0]
-        uri_host = uri_decoded[1]
 
         fetchcmd = fetchcmd.replace("${URI}", uri.split(";")[0])
         fetchcmd = fetchcmd.replace("${FILE}", ud.basename)
Signature · 1 line
1.7.10.4
#13 lore raw

PATCH v2 2/6 fetch2: Add a class representing a generic URI

In reply to Olof Johansson

A class representing a generic URI, with methods for accessing the URI components, and stringifies to the URI. This class should be a bit more flexible than the existing {encode,decode}_url functions in that it supports more components (e.g. port) and that it does not rely on a specific order on the return values. This makes it easy to add new properties without affecting the API.

---
 lib/bb/fetch2/__init__.py |  194 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 194 insertions(+)
lib/bb/fetch2/__init__.py +194 -0
index 4746356..7f44976 100644
@@ -30,6 +30,7 @@ from __future__ import print_function
 import os, re
 import logging
 import urllib
+from urlparse import urlparse
 import operator
 import bb.persist_data, bb.utils
 import bb.checksum
@@ -120,6 +121,199 @@ class NonLocalMethod(Exception):
     def __init__(self):
         Exception.__init__(self)
 
+
+class URI(object):
+    """
+    A class representing a generic URI, with methods for
+    accessing the URI components, and stringifies to the
+    URI.
+
+    It is constructed by calling it with a URI, or setting
+    the attributes manually:
+
+     uri = URI("http://example.com/")
+
+     uri = URI()
+     uri.scheme = 'http'
+     uri.hostname = 'example.com'
+     uri.path = '/'
+
+    It has the following attributes:
+
+      * scheme (read/write)
+      * userinfo (authentication information) (read/write)
+        * username (read/write)
+        * password (read/write)
+
+        Note, password is deprecated as of RFC 3986.
+
+      * hostname (read/write)
+      * port (read/write)
+      * hostport (read only)
+        "hostname:port", if both are set, otherwise just "hostname"
+      * path (read/write)
+      * path_quoted (read/write)
+        A URI quoted version of path
+      * params (dict) (read/write)
+      * relative (bool) (read only)
+        True if this is a "relative URI", (e.g. file:foo.diff)
+
+    It stringifies to the URI itself.
+
+    Some notes about relative URIs: while it's specified that
+    a URI beginning with <scheme>:// should either be directly
+    followed by a hostname or a /, the old URI handling of the
+    fetch2 library did not comform to this. Therefore, this URI
+    class has some kludges to make sure that URIs are parsed in
+    a way comforming to bitbake's current usage. This URI class
+    supports the following:
+
+     file:relative/path.diff (IETF compliant)
+     git:relative/path.git (IETF compliant)
+     git:///absolute/path.git (IETF compliant)
+     file:///absolute/path.diff (IETF compliant)
+
+     file://relative/path.diff (not IETF compliant)
+
+    But it does not support the following:
+
+     file://hostname/absolute/path.diff (would be IETF compliant)
+
+    Note that the last case only applies to a list of
+    "whitelisted" schemes (currently only file://), that requires
+    its URIs to not have a network location.
+    """
+
+    _relative_schemes = ['file', 'git']
+    _netloc_forbidden = ['file']
+
+    def __init__(self, uri=None):
+        self.scheme = ''
+        self.userinfo = ''
+        self.hostname = ''
+        self.port = None
+        self._path = ''
+        self.params = {}
+        self.relative = False
+
+        if not uri:
+            return
+
+        urlp = urlparse(uri)
+        self.scheme = urlp.scheme
+
+        # Convert URI to be relative
+        if urlp.scheme in self._netloc_forbidden:
+            uri = re.sub("(?<=:)//(?!/)", "", uri, 1)
+            urlp = urlparse(uri)
+
+        # Identify if the URI is relative or not
+        if urlp.scheme in self._relative_schemes and \
+           re.compile("^\w+:(?!//)").match(uri):
+            self.relative = True
+
+        if not self.relative:
+            self.hostname = urlp.hostname or ''
+            self.port = urlp.port
+
+            self.userinfo += urlp.username or ''
+
+            if urlp.password:
+                self.userinfo += ':%s' % urlp.password
+
+        # Do support params even for URI schemes that Python's
+        # urlparse doesn't support params for.
+        path = ''
+        param_str = ''
+        if not urlp.params:
+            path, param_str = (list(urlp.path.split(";", 1)) + [None])[:2]
+        else:
+            path = urlp.path
+            param_str = urlp.params
+
+        self.path = urllib.unquote(path)
+
+        if param_str:
+            self.params = self._param_dict(param_str)
+
+    def __str__(self):
+        userinfo = self.userinfo
+        if userinfo:
+            userinfo += '@'
+
+        return "%s:%s%s%s%s%s" % (
+            self.scheme,
+            '' if self.relative else '//',
+            userinfo,
+            self.hostport,
+            self.path_quoted,
+            self._param_str)
+
+    @property
+    def _param_str(self):
+        ret = ''
+        for key, val in self.params.items():
+            ret += ";%s=%s" % (key, val)
+        return ret
+
+    def _param_dict(self, param_str):
+        parm = {}
+
+        for keyval in param_str.split(";"):
+            key, val = keyval.split("=", 1)
+            parm[key] = val
+
+        return parm
+
+    @property
+    def hostport(self):
+        if not self.port:
+            return self.hostname
+        return "%s:%d" % (self.hostname, self.port)
+
+    @property
+    def path_quoted(self):
+        return urllib.quote(self.path)
+
+    @path_quoted.setter
+    def path_quoted(self, path):
+        self.path = urllib.unquote(path)
+
+    @property
+    def path(self):
+        return self._path
+
+    @path.setter
+    def path(self, path):
+        self._path = path
+
+        if re.compile("^/").match(path):
+            self.relative = False
+        else:
+            self.relative = True
+
+    @property
+    def username(self):
+        if self.userinfo:
+            return (self.userinfo.split(":", 1))[0]
+        return ''
+
+    @username.setter
+    def username(self, username):
+        self.userinfo = username
+        if self.password:
+            self.userinfo += ":%s" % self.password
+
+    @property
+    def password(self):
+        if self.userinfo and ":" in self.userinfo:
+            return (self.userinfo.split(":", 1))[1]
+        return ''
+
+    @password.setter
+    def password(self, password):
+        self.userinfo = "%s:%s" % (self.username, password)
+
 def decodeurl(url):
     """Decodes an URL into the tokens (scheme, network location, path,
     user, password, parameters).
Signature · 1 line
1.7.10.4
#14 lore raw

PATCH v2 3/6 fetch2: unittests for bb.fetch2.URI class

In reply to Olof Johansson
---
 lib/bb/tests/fetch.py |  226 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 226 insertions(+)
lib/bb/tests/fetch.py +226 -0
index 67eda59..e765ca7 100644
@@ -21,8 +21,234 @@ import unittest
 import tempfile
 import subprocess
 import os
+from bb.fetch2 import URI
 import bb
 
+class URITest(unittest.TestCase):
+    test_uris = {
+        "http://www.google.com/index.html" : {
+            'uri': 'http://www.google.com/index.html',
+            'scheme': 'http',
+            'hostname': 'www.google.com',
+            'port': None,
+            'hostport': 'www.google.com',
+            'path': '/index.html',
+            'userinfo': '',
+            'username': '',
+            'password': '',
+            'params': {},
+            'relative': False
+        },
+        "http://www.google.com/index.html;param1=value1" : {
+            'uri': 'http://www.google.com/index.html;param1=value1',
+            'scheme': 'http',
+            'hostname': 'www.google.com',
+            'port': None,
+            'hostport': 'www.google.com',
+            'path': '/index.html',
+            'userinfo': '',
+            'username': '',
+            'password': '',
+            'params': {
+                'param1': 'value1'
+            },
+            'relative': False
+        },
+        "http://www.example.com:8080/index.html" : {
+            'uri': 'http://www.example.com:8080/index.html',
+            'scheme': 'http',
+            'hostname': 'www.example.com',
+            'port': 8080,
+            'hostport': 'www.example.com:8080',
+            'path': '/index.html',
+            'userinfo': '',
+            'username': '',
+            'password': '',
+            'params': {},
+            'relative': False
+        },
+        "cvs://[email protected]/cvs;module=familiar/dist/ipkg" : {
+            'uri': 'cvs://[email protected]/cvs;module=familiar/dist/ipkg',
+            'scheme': 'cvs',
+            'hostname': 'cvs.handhelds.org',
+            'port': None,
+            'hostport': 'cvs.handhelds.org',
+            'path': '/cvs',
+            'userinfo': 'anoncvs',
+            'username': 'anoncvs',
+            'password': '',
+            'params': {
+                'module': 'familiar/dist/ipkg'
+            },
+            'relative': False
+        },
+        "cvs://anoncvs:[email protected]/cvs;tag=V0-99-81;module=familiar/dist/ipkg": {
+            'uri': 'cvs://anoncvs:[email protected]/cvs;tag=V0-99-81;module=familiar/dist/ipkg',
+            'scheme': 'cvs',
+            'hostname': 'cvs.handhelds.org',
+            'port': None,
+            'hostport': 'cvs.handhelds.org',
+            'path': '/cvs',
+            'userinfo': 'anoncvs:anonymous',
+            'username': 'anoncvs',
+            'password': 'anonymous',
+            'params': {
+                'tag': 'V0-99-81',
+                'module': 'familiar/dist/ipkg'
+            },
+            'relative': False
+        },
+        "file://example.diff": { # NOTE: Not RFC compliant!
+            'uri': 'file:example.diff',
+            'scheme': 'file',
+            'hostname': '',
+            'port': None,
+            'hostport': '',
+            'path': 'example.diff',
+            'userinfo': '',
+            'username': '',
+            'password': '',
+            'params': {},
+            'relative': True
+        },
+        "file:example.diff": { # NOTE: RFC compliant version of the former
+            'uri': 'file:example.diff',
+            'scheme': 'file',
+            'hostname': '',
+            'port': None,
+            'hostport': '',
+            'path': 'example.diff',
+            'userinfo': '',
+            'userinfo': '',
+            'username': '',
+            'password': '',
+            'params': {},
+            'relative': True
+        },
+        "file:///tmp/example.diff": {
+            'uri': 'file:///tmp/example.diff',
+            'scheme': 'file',
+            'hostname': '',
+            'port': None,
+            'hostport': '',
+            'path': '/tmp/example.diff',
+            'userinfo': '',
+            'userinfo': '',
+            'username': '',
+            'password': '',
+            'params': {},
+            'relative': False
+        },
+        "git:///path/example.git": {
+            'uri': 'git:///path/example.git',
+            'scheme': 'git',
+            'hostname': '',
+            'port': None,
+            'hostport': '',
+            'path': '/path/example.git',
+            'userinfo': '',
+            'userinfo': '',
+            'username': '',
+            'password': '',
+            'params': {},
+            'relative': False
+        },
+        "git:path/example.git": {
+            'uri': 'git:path/example.git',
+            'scheme': 'git',
+            'hostname': '',
+            'port': None,
+            'hostport': '',
+            'path': 'path/example.git',
+            'userinfo': '',
+            'userinfo': '',
+            'username': '',
+            'password': '',
+            'params': {},
+            'relative': True
+        },
+        "git://example.net/path/example.git": {
+            'uri': 'git://example.net/path/example.git',
+            'scheme': 'git',
+            'hostname': 'example.net',
+            'port': None,
+            'hostport': 'example.net',
+            'path': '/path/example.git',
+            'userinfo': '',
+            'userinfo': '',
+            'username': '',
+            'password': '',
+            'params': {},
+            'relative': False
+        }
+    }
+
+    def test_uri(self):
+        for test_uri, ref in self.test_uris.items():
+            uri = URI(test_uri)
+
+            self.assertEqual(str(uri), ref['uri'])
+
+            # expected attributes
+            self.assertEqual(uri.scheme, ref['scheme'])
+
+            self.assertEqual(uri.userinfo, ref['userinfo'])
+            self.assertEqual(uri.username, ref['username'])
+            self.assertEqual(uri.password, ref['password'])
+
+            self.assertEqual(uri.hostname, ref['hostname'])
+            self.assertEqual(uri.port, ref['port'])
+            self.assertEqual(uri.hostport, ref['hostport'])
+
+            self.assertEqual(uri.path, ref['path'])
+            self.assertEqual(uri.params, ref['params'])
+
+            self.assertEqual(uri.relative, ref['relative'])
+
+    def test_dict(self):
+        for test in self.test_uris.values():
+            uri = URI()
+
+            self.assertEqual(uri.scheme, '')
+            self.assertEqual(uri.userinfo, '')
+            self.assertEqual(uri.username, '')
+            self.assertEqual(uri.password, '')
+            self.assertEqual(uri.hostname, '')
+            self.assertEqual(uri.port, None)
+            self.assertEqual(uri.path, '')
+            self.assertEqual(uri.params, {})
+
+
+            uri.scheme = test['scheme']
+            self.assertEqual(uri.scheme, test['scheme'])
+
+            uri.userinfo = test['userinfo']
+            self.assertEqual(uri.userinfo, test['userinfo'])
+            self.assertEqual(uri.username, test['username'])
+            self.assertEqual(uri.password, test['password'])
+
+            uri.hostname = test['hostname']
+            self.assertEqual(uri.hostname, test['hostname'])
+            self.assertEqual(uri.hostport, test['hostname'])
+
+            uri.port = test['port']
+            self.assertEqual(uri.port, test['port'])
+            self.assertEqual(uri.hostport, test['hostport'])
+
+            uri.path = test['path']
+            self.assertEqual(uri.path, test['path'])
+
+            uri.params = test['params']
+            self.assertEqual(uri.params, test['params'])
+
+            self.assertEqual(str(uri)+str(uri.relative), str(test['uri'])+str(test['relative']))
+
+            self.assertEqual(str(uri), test['uri'])
+
+            uri.params = {}
+            self.assertEqual(uri.params, {})
+            self.assertEqual(str(uri), (str(uri).split(";"))[0])
+
 
 class FetcherTest(unittest.TestCase):
 
Signature · 1 line
1.7.10.4
#15 lore raw

v2 cover fetch2: Updated SFTP fetcher

In reply to Olof Johansson

Changes since the first draft (thanks Martin Jansa for the feedback):

* Rebase against current master
* Regenerate diffs without git config diff.noprefix
* Support /~/ (home relative URIs) in SFTP fetcher
* Add an example section in the SFTP fetcher documentation
* Remove "checkstatus" method from SFTP fetcher (wasn't meant to be there)

Olof Johansson (6):
fetch2: Remove unused code in wget fetcher
fetch2: Add a class representing a generic URI
fetch2: unittests for bb.fetch2.URI class
fetch2: Adapt encode/decode url to use URI class
fetch2: Add editor modelines for bb.tests.*
fetch2: Add SFTP fetcher

 lib/bb/fetch2/__init__.py  |  262 +++++++++++++++++++++++++++++++++++---------
 lib/bb/fetch2/sftp.py      |  129 ++++++++++++++++++++++
 lib/bb/fetch2/wget.py      |    5 -
 lib/bb/tests/codeparser.py |    2 +
 lib/bb/tests/cow.py        |    2 +
 lib/bb/tests/data.py       |    2 +
 lib/bb/tests/fetch.py      |  228 ++++++++++++++++++++++++++++++++++++++
 lib/bb/tests/utils.py      |    2 +
 8 files changed, 578 insertions(+), 54 deletions(-)
 create mode 100644 lib/bb/fetch2/sftp.py
Signature · 1 line
1.7.10.4
#16 lore raw

Re: [PATCH v2 0/6] fetch2: Updated SFTP fetcher

Hi,

Quoted 7 lines · Olof Johansson

Olof Johansson (6):
fetch2: Remove unused code in wget fetcher
fetch2: Add a class representing a generic URI
fetch2: unittests for bb.fetch2.URI class
fetch2: Adapt encode/decode url to use URI class
fetch2: Add editor modelines for bb.tests.*
fetch2: Add SFTP fetcher

One thing I forgot to mention; after speaking with kergoth on IRC last Friday, we found that there are some performance penelties in using the URI class instead of encode/decodeurl. I tried to profile and see if there were any obvious ways to get it down to the level of the old encode/decodeurl, but nothing obvious.

I did the performance evaluation by running the unittests.

Forking and running the unittests in seperate processes shows no change:

http://codepad.org/SYsVsckY

However, running them in a single process with the timeit module shows a pretty big (proportional) regression:

http://codepad.org/Vzu7Pqqw

Is this significant? Running the tests 10000, each run creating three URI objects, takes ~2 seconds.

Signature · 1 line
Olof Johasnson
#17 lore raw

Re: [PATCH v2 0/6] fetch2: Updated SFTP fetcher

Quoted 24 lines · Olof Johansson

Hi,

Quoted 7 lines · Olof Johansson

Olof Johansson (6):
fetch2: Remove unused code in wget fetcher
fetch2: Add a class representing a generic URI
fetch2: unittests for bb.fetch2.URI class
fetch2: Adapt encode/decode url to use URI class
fetch2: Add editor modelines for bb.tests.*
fetch2: Add SFTP fetcher

One thing I forgot to mention; after speaking with kergoth on IRC last Friday, we found that there are some performance penelties in using the URI class instead of encode/decodeurl. I tried to profile and see if there were any obvious ways to get it down to the level of the old encode/decodeurl, but nothing obvious.

I did the performance evaluation by running the unittests.

Forking and running the unittests in seperate processes shows no change:

http://codepad.org/SYsVsckY

Quoted 7 lines

However, running them in a single process with the timeit module shows a pretty big (proportional) regression:

http://codepad.org/Vzu7Pqqw

Is this significant? Running the tests 10000, each run creating three URI objects, takes ~2 seconds.

In the scheme of things and other bitbake overheads, I'd suspect its not significant although it is a good thing to check...

What were the other changes between v1 and v2? In cases like this a 0/6 summary email is helpful.

Cheers,

Richard

#18 lore raw

Re: [PATCH v2 0/6] fetch2: Updated SFTP fetcher

Quoted 45 lines

-----Original Message-----
From: [email protected] [mailto:bitbake- [email protected]] On Behalf Of Richard Purdie
Sent: den 31 januari 2013 13:43
To: Olof Johansson
Cc: [email protected]
Subject: Re: [bitbake-devel] [PATCH v2 0/6] fetch2: Updated SFTP fetcher

Quoted 24 lines · Olof Johansson

Hi,

Quoted 7 lines · Olof Johansson

Olof Johansson (6):
fetch2: Remove unused code in wget fetcher
fetch2: Add a class representing a generic URI
fetch2: unittests for bb.fetch2.URI class
fetch2: Adapt encode/decode url to use URI class
fetch2: Add editor modelines for bb.tests.*
fetch2: Add SFTP fetcher

One thing I forgot to mention; after speaking with kergoth on IRC last Friday, we found that there are some performance penelties in using the URI class instead of encode/decodeurl. I tried to profile and see if there were any obvious ways to get it down to the level of the old encode/decodeurl, but nothing obvious.

I did the performance evaluation by running the unittests.

Forking and running the unittests in seperate processes shows no change:

http://codepad.org/SYsVsckY

Quoted 7 lines

However, running them in a single process with the timeit module shows a pretty big (proportional) regression:

http://codepad.org/Vzu7Pqqw

Is this significant? Running the tests 10000, each run creating three URI objects, takes ~2 seconds.

In the scheme of things and other bitbake overheads, I'd suspect its not significant although it is a good thing to check...

Quoted 6 lines

What were the other changes between v1 and v2? In cases like this a 0/6 summary email is helpful.

Cheers,

Richard

The list of changes between v1 and v2 were in the 0/6 mail that Olof did send (the one he replied to above). I have included them below:

Quoted 15 lines

-----Original Message-----
From: [email protected] [mailto:bitbake- [email protected]] On Behalf Of Olof Johansson
Sent: den 29 januari 2013 08:50
To: [email protected]
Subject: [bitbake-devel] [PATCH v2 0/6] fetch2: Updated SFTP fetcher

Changes since the first draft (thanks Martin Jansa for the feedback):

* Rebase against current master
* Regenerate diffs without git config diff.noprefix
* Support /~/ (home relative URIs) in SFTP fetcher
* Add an example section in the SFTP fetcher documentation
* Remove "checkstatus" method from SFTP fetcher (wasn't meant to be there)

Quoted 3 lines

Olof Johansson (6):
fetch2: Remove unused code in wget fetcher
...

//Peter

#19 lore raw

PATCH v2 4/6 fetch2: Adapt encode/decode url to use URI class

In reply to Olof Johansson
---
 lib/bb/fetch2/__init__.py |   66 ++++++++++++---------------------------------
 1 file changed, 17 insertions(+), 49 deletions(-)
lib/bb/fetch2/__init__.py +17 -49
index 7f44976..b6fc8f8 100644
@@ -319,40 +319,9 @@ def decodeurl(url):
     user, password, parameters).
     """
 
-    m = re.compile('(?P<type>[^:]*)://((?P<user>.+)@)?(?P<location>[^;]+)(;(?P<parm>.*))?').match(url)
-    if not m:
-        raise MalformedUrl(url)
-
-    type = m.group('type')
-    location = m.group('location')
-    if not location:
-        raise MalformedUrl(url)
-    user = m.group('user')
-    parm = m.group('parm')
-
-    locidx = location.find('/')
-    if locidx != -1 and type.lower() != 'file':
-        host = location[:locidx]
-        path = location[locidx:]
-    else:
-        host = ""
-        path = location
-    if user:
-        m = re.compile('(?P<user>[^:]+)(:?(?P<pswd>.*))').match(user)
-        if m:
-            user = m.group('user')
-            pswd = m.group('pswd')
-    else:
-        user = ''
-        pswd = ''
-
-    p = {}
-    if parm:
-        for s in parm.split(';'):
-            s1, s2 = s.split('=')
-            p[s1] = s2
-
-    return type, host, urllib.unquote(path), user, pswd, p
+    urlo = URI(url)
+    return (urlo.scheme, urlo.hostport, urlo.path,
+            urlo.username, urlo.password, urlo.params)
 
 def encodeurl(decoded):
     """Encodes a URL from tokens (scheme, network location, path,
@@ -361,27 +330,26 @@ def encodeurl(decoded):
 
     type, host, path, user, pswd, p = decoded
 
+    urlo = URI()
+
     if not path:
         raise MissingParameterError('path', "encoded from the data %s" % str(decoded))
     if not type:
         raise MissingParameterError('type', "encoded from the data %s" % str(decoded))
-    url = '%s://' % type
-    if user and type != "file":
-        url += "%s" % user
-        if pswd:
-            url += ":%s" % pswd
-        url += "@"
-    if host and type != "file":
-        url += "%s" % host
-    # Standardise path to ensure comparisons work
-    while '//' in path:
-        path = path.replace("//", "/")
-    url += "%s" % urllib.quote(path)
+
+    urlo.scheme = type
+    urlo.path = path
+
+    if host:
+        urlo.hostname = host
+    if user:
+        urlo.username = user
+    if pswd:
+        urlo.password = pswd
     if p:
-        for parm in p:
-            url += ";%s=%s" % (parm, p[parm])
+        urlo.params = p
 
-    return url
+    return str(urlo)
 
 def uri_replace(ud, uri_find, uri_replace, replacements, d):
     if not ud.url or not uri_find or not uri_replace:
Signature · 1 line
1.7.10.4
#20 lore raw

Re: [PATCH v2 4/6] fetch2: Adapt encode/decode url to use URI class

Quoted 4 lines · Olof Johansson
---
 lib/bb/fetch2/__init__.py |   66 ++++++++++++---------------------------------
 1 file changed, 17 insertions(+), 49 deletions(-)

I've had to revert this since it simply doesn't work. bitbake-selftest fails all the tests with this applied, we also saw multiple failures in other places where things should work :(

Cheers,

Richard

#21 lore raw

PATCH v2 5/6 fetch2: Add editor modelines for bb.tests.*

In reply to Olof Johansson
---
 lib/bb/tests/codeparser.py |    2 ++
 lib/bb/tests/cow.py        |    2 ++
 lib/bb/tests/data.py       |    2 ++
 lib/bb/tests/fetch.py      |    2 ++
 lib/bb/tests/utils.py      |    2 ++
 5 files changed, 10 insertions(+)
lib/bb/tests/codeparser.py +2 -0
index 9b2d588..d2bd4a2 100644
@@ -1,3 +1,5 @@
+# ex:ts=4:sw=4:sts=4:et
+# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
 #
 # BitBake Test for codeparser.py
 #
lib/bb/tests/cow.py +2 -0
index 599b2aa..35c5841 100644
@@ -1,3 +1,5 @@
+# ex:ts=4:sw=4:sts=4:et
+# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
 #
 # BitBake Tests for Copy-on-Write (cow.py)
 #
lib/bb/tests/data.py +2 -0
index b2ab8ee..5161586 100644
@@ -1,3 +1,5 @@
+# ex:ts=4:sw=4:sts=4:et
+# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
 #
 # BitBake Tests for the Data Store (data.py/data_smart.py)
 #
lib/bb/tests/fetch.py +2 -0
index e765ca7..778d94f 100644
@@ -1,3 +1,5 @@
+# ex:ts=4:sw=4:sts=4:et
+# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
 #
 # BitBake Tests for the Fetcher (fetch2/)
 #
lib/bb/tests/utils.py +2 -0
index 9f60491..7c50b1d 100644
@@ -1,3 +1,5 @@
+# ex:ts=4:sw=4:sts=4:et
+# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
 #
 # BitBake Tests for utils.py
 #
Signature · 1 line
1.7.10.4
#22 lore raw

PATCH v2 6/6 fetch2: Add SFTP fetcher

In reply to Olof Johansson

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.

---
 lib/bb/fetch2/__init__.py |    2 +
 lib/bb/fetch2/sftp.py     |  129 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 131 insertions(+)
 create mode 100644 lib/bb/fetch2/sftp.py
lib/bb/fetch2/__init__.py +2 -0
index b6fc8f8..cc524c5 100644
@@ -1449,6 +1449,7 @@ from . import svn
 from . import wget
 from . import svk
 from . import ssh
+from . import sftp
 from . import perforce
 from . import bzr
 from . import hg
@@ -1462,6 +1463,7 @@ methods.append(git.Git())
 methods.append(cvs.Cvs())
 methods.append(svk.Svk())
 methods.append(ssh.SSH())
+methods.append(sftp.SFTP())
 methods.append(perforce.Perforce())
 methods.append(bzr.Bzr())
 methods.append(hg.Hg())
lib/bb/fetch2/sftp.py new file +129 -0

129 lines not on this page · raw message

Signature · 1 line
1.7.10.4