summaryrefslogtreecommitdiffstats
path: root/bitbake
diff options
context:
space:
mode:
authorChris Larson <clarson@kergoth.com>2009-07-19 09:51:29 -0700
committerRichard Purdie <rpurdie@linux.intel.com>2010-03-22 14:54:10 +0000
commitac392b66a545ae1c62b61817aa688304c4d56f09 (patch)
treeaadd5452749693ea8f51ca092d2aadb117884f4c /bitbake
parenta3012e1ca98132a4e273d363fe3302cd85c37f48 (diff)
downloadpoky-ac392b66a545ae1c62b61817aa688304c4d56f09.tar.gz
Move encodeurl, decodeurl into bb.fetch.
(Bitbake rev: 867d36f9afce2d298874ac7563e5b3852ef04659) Signed-off-by: Chris Larson <clarson@kergoth.com> Signed-off-by: Richard Purdie <rpurdie@linux.intel.com>
Diffstat (limited to 'bitbake')
-rw-r--r--bitbake/lib/bb/__init__.py109
-rw-r--r--bitbake/lib/bb/fetch/__init__.py94
2 files changed, 95 insertions, 108 deletions
diff --git a/bitbake/lib/bb/__init__.py b/bitbake/lib/bb/__init__.py
index 3195e72a62..de5f0321fa 100644
--- a/bitbake/lib/bb/__init__.py
+++ b/bitbake/lib/bb/__init__.py
@@ -81,7 +81,7 @@ if "BBDEBUG" in os.environ:
81 bb.msg.set_debug_level(level) 81 bb.msg.set_debug_level(level)
82 82
83# For compatibility 83# For compatibility
84from bb.fetch import MalformedUrl 84from bb.fetch import MalformedUrl, encodeurl, decodeurl
85from bb.data import VarExpandError 85from bb.data import VarExpandError
86 86
87 87
@@ -300,113 +300,6 @@ def copyfile(src,dest,newmtime=None,sstat=None):
300 return newmtime 300 return newmtime
301 301
302####################################################################### 302#######################################################################
303#######################################################################
304#
305# SECTION: Download
306#
307# PURPOSE: Download via HTTP, FTP, CVS, BITKEEPER, handling of MD5-signatures
308# and mirrors
309#
310#######################################################################
311#######################################################################
312
313def decodeurl(url):
314 """Decodes an URL into the tokens (scheme, network location, path,
315 user, password, parameters).
316
317 >>> decodeurl("http://www.google.com/index.html")
318 ('http', 'www.google.com', '/index.html', '', '', {})
319
320 CVS url with username, host and cvsroot. The cvs module to check out is in the
321 parameters:
322
323 >>> decodeurl("cvs://anoncvs@cvs.handhelds.org/cvs;module=familiar/dist/ipkg")
324 ('cvs', 'cvs.handhelds.org', '/cvs', 'anoncvs', '', {'module': 'familiar/dist/ipkg'})
325
326 Dito, but this time the username has a password part. And we also request a special tag
327 to check out.
328
329 >>> decodeurl("cvs://anoncvs:anonymous@cvs.handhelds.org/cvs;module=familiar/dist/ipkg;tag=V0-99-81")
330 ('cvs', 'cvs.handhelds.org', '/cvs', 'anoncvs', 'anonymous', {'tag': 'V0-99-81', 'module': 'familiar/dist/ipkg'})
331 """
332
333 m = re.compile('(?P<type>[^:]*)://((?P<user>.+)@)?(?P<location>[^;]+)(;(?P<parm>.*))?').match(url)
334 if not m:
335 raise MalformedUrl(url)
336
337 type = m.group('type')
338 location = m.group('location')
339 if not location:
340 raise MalformedUrl(url)
341 user = m.group('user')
342 parm = m.group('parm')
343
344 locidx = location.find('/')
345 if locidx != -1:
346 host = location[:locidx]
347 path = location[locidx:]
348 else:
349 host = ""
350 path = location
351 if user:
352 m = re.compile('(?P<user>[^:]+)(:?(?P<pswd>.*))').match(user)
353 if m:
354 user = m.group('user')
355 pswd = m.group('pswd')
356 else:
357 user = ''
358 pswd = ''
359
360 p = {}
361 if parm:
362 for s in parm.split(';'):
363 s1,s2 = s.split('=')
364 p[s1] = s2
365
366 return (type, host, path, user, pswd, p)
367
368#######################################################################
369
370def encodeurl(decoded):
371 """Encodes a URL from tokens (scheme, network location, path,
372 user, password, parameters).
373
374 >>> encodeurl(['http', 'www.google.com', '/index.html', '', '', {}])
375 'http://www.google.com/index.html'
376
377 CVS with username, host and cvsroot. The cvs module to check out is in the
378 parameters:
379
380 >>> encodeurl(['cvs', 'cvs.handhelds.org', '/cvs', 'anoncvs', '', {'module': 'familiar/dist/ipkg'}])
381 'cvs://anoncvs@cvs.handhelds.org/cvs;module=familiar/dist/ipkg'
382
383 Dito, but this time the username has a password part. And we also request a special tag
384 to check out.
385
386 >>> encodeurl(['cvs', 'cvs.handhelds.org', '/cvs', 'anoncvs', 'anonymous', {'tag': 'V0-99-81', 'module': 'familiar/dist/ipkg'}])
387 'cvs://anoncvs:anonymous@cvs.handhelds.org/cvs;tag=V0-99-81;module=familiar/dist/ipkg'
388 """
389
390 (type, host, path, user, pswd, p) = decoded
391
392 if not type or not path:
393 fatal("invalid or missing parameters for url encoding")
394 url = '%s://' % type
395 if user:
396 url += "%s" % user
397 if pswd:
398 url += ":%s" % pswd
399 url += "@"
400 if host:
401 url += "%s" % host
402 url += "%s" % path
403 if p:
404 for parm in p.keys():
405 url += ";%s=%s" % (parm, p[parm])
406
407 return url
408
409#######################################################################
410 303
411def which(path, item, direction = 0): 304def which(path, item, direction = 0):
412 """ 305 """
diff --git a/bitbake/lib/bb/fetch/__init__.py b/bitbake/lib/bb/fetch/__init__.py
index 875cda8929..f40d7be334 100644
--- a/bitbake/lib/bb/fetch/__init__.py
+++ b/bitbake/lib/bb/fetch/__init__.py
@@ -50,6 +50,100 @@ class MD5SumError(Exception):
50class InvalidSRCREV(Exception): 50class InvalidSRCREV(Exception):
51 """Exception raised when an invalid SRCREV is encountered""" 51 """Exception raised when an invalid SRCREV is encountered"""
52 52
53def decodeurl(url):
54 """Decodes an URL into the tokens (scheme, network location, path,
55 user, password, parameters).
56
57 >>> decodeurl("http://www.google.com/index.html")
58 ('http', 'www.google.com', '/index.html', '', '', {})
59
60 CVS url with username, host and cvsroot. The cvs module to check out is in the
61 parameters:
62
63 >>> decodeurl("cvs://anoncvs@cvs.handhelds.org/cvs;module=familiar/dist/ipkg")
64 ('cvs', 'cvs.handhelds.org', '/cvs', 'anoncvs', '', {'module': 'familiar/dist/ipkg'})
65
66 Dito, but this time the username has a password part. And we also request a special tag
67 to check out.
68
69 >>> decodeurl("cvs://anoncvs:anonymous@cvs.handhelds.org/cvs;module=familiar/dist/ipkg;tag=V0-99-81")
70 ('cvs', 'cvs.handhelds.org', '/cvs', 'anoncvs', 'anonymous', {'tag': 'V0-99-81', 'module': 'familiar/dist/ipkg'})
71 """
72
73 m = re.compile('(?P<type>[^:]*)://((?P<user>.+)@)?(?P<location>[^;]+)(;(?P<parm>.*))?').match(url)
74 if not m:
75 raise MalformedUrl(url)
76
77 type = m.group('type')
78 location = m.group('location')
79 if not location:
80 raise MalformedUrl(url)
81 user = m.group('user')
82 parm = m.group('parm')
83
84 locidx = location.find('/')
85 if locidx != -1:
86 host = location[:locidx]
87 path = location[locidx:]
88 else:
89 host = ""
90 path = location
91 if user:
92 m = re.compile('(?P<user>[^:]+)(:?(?P<pswd>.*))').match(user)
93 if m:
94 user = m.group('user')
95 pswd = m.group('pswd')
96 else:
97 user = ''
98 pswd = ''
99
100 p = {}
101 if parm:
102 for s in parm.split(';'):
103 s1,s2 = s.split('=')
104 p[s1] = s2
105
106 return (type, host, path, user, pswd, p)
107
108def encodeurl(decoded):
109 """Encodes a URL from tokens (scheme, network location, path,
110 user, password, parameters).
111
112 >>> encodeurl(['http', 'www.google.com', '/index.html', '', '', {}])
113 'http://www.google.com/index.html'
114
115 CVS with username, host and cvsroot. The cvs module to check out is in the
116 parameters:
117
118 >>> encodeurl(['cvs', 'cvs.handhelds.org', '/cvs', 'anoncvs', '', {'module': 'familiar/dist/ipkg'}])
119 'cvs://anoncvs@cvs.handhelds.org/cvs;module=familiar/dist/ipkg'
120
121 Dito, but this time the username has a password part. And we also request a special tag
122 to check out.
123
124 >>> encodeurl(['cvs', 'cvs.handhelds.org', '/cvs', 'anoncvs', 'anonymous', {'tag': 'V0-99-81', 'module': 'familiar/dist/ipkg'}])
125 'cvs://anoncvs:anonymous@cvs.handhelds.org/cvs;tag=V0-99-81;module=familiar/dist/ipkg'
126 """
127
128 (type, host, path, user, pswd, p) = decoded
129
130 if not type or not path:
131 fatal("invalid or missing parameters for url encoding")
132 url = '%s://' % type
133 if user:
134 url += "%s" % user
135 if pswd:
136 url += ":%s" % pswd
137 url += "@"
138 if host:
139 url += "%s" % host
140 url += "%s" % path
141 if p:
142 for parm in p.keys():
143 url += ";%s=%s" % (parm, p[parm])
144
145 return url
146
53def uri_replace(uri, uri_find, uri_replace, d): 147def uri_replace(uri, uri_find, uri_replace, d):
54# bb.msg.note(1, bb.msg.domain.Fetcher, "uri_replace: operating on %s" % uri) 148# bb.msg.note(1, bb.msg.domain.Fetcher, "uri_replace: operating on %s" % uri)
55 if not uri or not uri_find or not uri_replace: 149 if not uri or not uri_find or not uri_replace: