diff options
author | Chris Larson <clarson@kergoth.com> | 2009-07-19 09:51:29 -0700 |
---|---|---|
committer | Richard Purdie <rpurdie@linux.intel.com> | 2010-03-22 14:54:10 +0000 |
commit | ac392b66a545ae1c62b61817aa688304c4d56f09 (patch) | |
tree | aadd5452749693ea8f51ca092d2aadb117884f4c /bitbake/lib/bb/fetch | |
parent | a3012e1ca98132a4e273d363fe3302cd85c37f48 (diff) | |
download | poky-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/lib/bb/fetch')
-rw-r--r-- | bitbake/lib/bb/fetch/__init__.py | 94 |
1 files changed, 94 insertions, 0 deletions
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): | |||
50 | class InvalidSRCREV(Exception): | 50 | class InvalidSRCREV(Exception): |
51 | """Exception raised when an invalid SRCREV is encountered""" | 51 | """Exception raised when an invalid SRCREV is encountered""" |
52 | 52 | ||
53 | def 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 | |||
108 | def 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 | |||
53 | def uri_replace(uri, uri_find, uri_replace, d): | 147 | def 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: |