[OE-core] [PATCH 1/3] oe.fetch: add module with uri convenience code
Chris Larson
kergoth at gmail.com
Tue Apr 5 20:39:55 UTC 2011
From: Chris Larson <chris_larson at mentor.com>
Signed-off-by: Chris Larson <chris_larson at mentor.com>
---
meta/conf/bitbake.conf | 1 +
meta/lib/oe/fetch.py | 87 ++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 88 insertions(+), 0 deletions(-)
create mode 100644 meta/lib/oe/fetch.py
diff --git a/meta/conf/bitbake.conf b/meta/conf/bitbake.conf
index 27b8a6b..27b4f74 100644
--- a/meta/conf/bitbake.conf
+++ b/meta/conf/bitbake.conf
@@ -527,6 +527,7 @@ AUTOREV = "${@bb.fetch2.get_autorev(d)}"
SRCPV = "${@bb.fetch2.get_srcrev(d)}"
SRC_URI = "file://${FILE}"
+SRC_URI[type] = "list"
# We can choose which provider of fake root privileges to use
# default is fakeroot but in Poky we use pseudo
diff --git a/meta/lib/oe/fetch.py b/meta/lib/oe/fetch.py
new file mode 100644
index 0000000..c99adcf
--- /dev/null
+++ b/meta/lib/oe/fetch.py
@@ -0,0 +1,87 @@
+import oe.data
+import urlparse
+from collections import namedtuple
+
+class MissingScheme(Exception):
+ def __str__(self):
+ return "Missing scheme in uri '%s'" % self.args[0]
+
+def src_uri(d):
+ return [uri(url) for url in oe.data.typed_value('SRC_URI', d)]
+
+def uri(url):
+ import urlparse
+
+ scheme, netloc, path, params, query, fragment = urlparse.urlparse(url)
+
+ if scheme == 'file':
+ if netloc:
+ path = netloc + path
+ netloc = ''
+ elif not scheme:
+ raise MissingScheme(url)
+
+ if ';' in path:
+ path, params = urlparse._splitparams(path)
+
+ params = parse_params(params)
+ query = urlparse.parse_qs(query)
+
+ return Uri(scheme, netloc, path, params, query, fragment)
+
+def parse_params(params):
+ values = {}
+ if params:
+ for param in params.split(';'):
+ try:
+ key, value = param.split('=', 1)
+ except ValueError:
+ key, value = param, True
+ values[key] = value
+ return values
+
+class Uri(namedtuple('Uri', 'scheme netloc path params query fragment'),
+ urlparse.ResultMixin):
+ """Representation of a Uniform Resource Identifier"""
+
+ __slots__ = ()
+
+ @property
+ def querystring(self):
+ """Reassembled query string"""
+ if self.query:
+ query = ';'.join('%s=%s' % (key, v)
+ for key, value in self.query.iteritems()
+ for v in value)
+ return query
+ else:
+ return self.query
+
+ @property
+ def parameterstring(self):
+ """Reassembled parameter string"""
+ if self.parameters:
+ parameters = ';'.join('%s=%s' % (key, value)
+ for key, value in self.parameters.iteritems())
+ return parameters
+ else:
+ return self.parameters
+
+ def join(self, otherurl):
+ """Join this url to a possibly relative URL to form an absolute
+ interpretation of the latter."""
+ return uri(urlparse.urljoin(str(self), str(otherurl)))
+
+ def unsplit(self):
+ """String version of URL without parameters"""
+ components = (self.scheme, self.netloc, self.path, self.querystring,
+ self.fragment)
+ return urlparse.urlunsplit(components)
+
+ def geturl(self):
+ components = (self.scheme, self.netloc, self.path,
+ self.parameterstring, self.querystring, self.fragment)
+ return urlparse.urlunparse(components)
+
+ def __str__(self):
+ return self.geturl()
--
1.7.4.1
More information about the Openembedded-core
mailing list