def uri_replace(uri, uri_find, uri_replace, d): # bb.msg.note(1, bb.msg.domain.Fetcher, "uri_replace: operating on %s" % uri) if not uri or not uri_find or not uri_replace: bb.msg.debug(1, bb.msg.domain.Fetcher, "uri_replace: passed an undefined value, not replacing") uri_decoded = list(bb.decodeurl(uri)) uri_find_decoded = list(bb.decodeurl(uri_find)) uri_replace_decoded = list(bb.decodeurl(uri_replace)) result_decoded = ['', '', '', '', '', {}] for i in uri_find_decoded: loc = uri_find_decoded.index(i) result_decoded[loc] = uri_decoded[loc] import types if type(i) == types.StringType: if (re.match(i, uri_decoded[loc])): result_decoded[loc] = re.sub(i, uri_replace_decoded[loc], uri_decoded[loc]) if uri_find_decoded.index(i) == 2: if d: localfn = bb.fetch.localpath(uri, d) if localfn: result_decoded[loc] = os.path.dirname( result_decoded[loc]) + "/" + os.path.basename( bb.fetch.localpath(uri, d)) # bb.msg.note(1, bb.msg.domain.Fetcher, "uri_replace: matching %s against %s and replacing with %s" % (i, uri_decoded[loc], uri_replace_decoded[loc])) else: # bb.msg.note(1, bb.msg.domain.Fetcher, "uri_replace: no match") return uri # else: # for j in i: # FIXME: apply replacements against options return bb.encodeurl(result_decoded)
def uri_replace(uri, uri_find, uri_replace, d): # bb.msg.note(1, bb.msg.domain.Fetcher, "uri_replace: operating on %s" % uri) if not uri or not uri_find or not uri_replace: bb.msg.debug(1, bb.msg.domain.Fetcher, "uri_replace: passed an undefined value, not replacing") uri_decoded = list(bb.decodeurl(uri)) uri_find_decoded = list(bb.decodeurl(uri_find)) uri_replace_decoded = list(bb.decodeurl(uri_replace)) result_decoded = ['','','','','',{}] for i in uri_find_decoded: loc = uri_find_decoded.index(i) result_decoded[loc] = uri_decoded[loc] import types if type(i) == types.StringType: import re if (re.match(i, uri_decoded[loc])): result_decoded[loc] = re.sub(i, uri_replace_decoded[loc], uri_decoded[loc]) if uri_find_decoded.index(i) == 2: if d: localfn = bb.fetch.localpath(uri, d) if localfn: result_decoded[loc] = os.path.dirname(result_decoded[loc]) + "/" + os.path.basename(bb.fetch.localpath(uri, d)) # bb.msg.note(1, bb.msg.domain.Fetcher, "uri_replace: matching %s against %s and replacing with %s" % (i, uri_decoded[loc], uri_replace_decoded[loc])) else: # bb.msg.note(1, bb.msg.domain.Fetcher, "uri_replace: no match") return uri # else: # for j in i.keys(): # FIXME: apply replacements against options return bb.encodeurl(result_decoded)
def localpath(self, url, ud, d): url = bb.encodeurl([ud.type, ud.host, ud.path, ud.user, ud.pswd, {}]) ud.basename = os.path.basename(ud.path) ud.localfile = data.expand(os.path.basename(url), d) return os.path.join(data.getVar("DL_DIR", d, True), ud.localfile)
def localpath(url, d): # strip off parameters (type, host, path, user, pswd, parm) = bb.decodeurl(bb.data.expand(url, d)) if "localpath" in parm: # if user overrides local path, use it. return parm["localpath"] url = bb.encodeurl([type, host, path, user, pswd, {}]) return os.path.join(bb.data.getVar("DL_DIR", d), os.path.basename(url))