wget.py 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607
  1. """
  2. BitBake 'Fetch' implementations
  3. Classes for obtaining upstream sources for the
  4. BitBake build tools.
  5. """
  6. # Copyright (C) 2003, 2004 Chris Larson
  7. #
  8. # SPDX-License-Identifier: GPL-2.0-only
  9. #
  10. # Based on functions from the base bb module, Copyright 2003 Holger Schurig
  11. import shlex
  12. import re
  13. import tempfile
  14. import os
  15. import errno
  16. import bb
  17. import bb.progress
  18. import socket
  19. import http.client
  20. import urllib.request, urllib.parse, urllib.error
  21. from bb.fetch2 import FetchMethod
  22. from bb.fetch2 import FetchError
  23. from bb.fetch2 import logger
  24. from bb.fetch2 import runfetchcmd
  25. from bb.utils import export_proxies
  26. from bs4 import BeautifulSoup
  27. from bs4 import SoupStrainer
  28. class WgetProgressHandler(bb.progress.LineFilterProgressHandler):
  29. """
  30. Extract progress information from wget output.
  31. Note: relies on --progress=dot (with -v or without -q/-nv) being
  32. specified on the wget command line.
  33. """
  34. def __init__(self, d):
  35. super(WgetProgressHandler, self).__init__(d)
  36. # Send an initial progress event so the bar gets shown
  37. self._fire_progress(0)
  38. def writeline(self, line):
  39. percs = re.findall(r'(\d+)%\s+([\d.]+[A-Z])', line)
  40. if percs:
  41. progress = int(percs[-1][0])
  42. rate = percs[-1][1] + '/s'
  43. self.update(progress, rate)
  44. return False
  45. return True
  46. class Wget(FetchMethod):
  47. """Class to fetch urls via 'wget'"""
  48. def supports(self, ud, d):
  49. """
  50. Check to see if a given url can be fetched with wget.
  51. """
  52. return ud.type in ['http', 'https', 'ftp']
  53. def recommends_checksum(self, urldata):
  54. return True
  55. def urldata_init(self, ud, d):
  56. if 'protocol' in ud.parm:
  57. if ud.parm['protocol'] == 'git':
  58. raise bb.fetch2.ParameterError("Invalid protocol - if you wish to fetch from a git repository using http, you need to instead use the git:// prefix with protocol=http", ud.url)
  59. if 'downloadfilename' in ud.parm:
  60. ud.basename = ud.parm['downloadfilename']
  61. else:
  62. ud.basename = os.path.basename(ud.path)
  63. ud.localfile = d.expand(urllib.parse.unquote(ud.basename))
  64. if not ud.localfile:
  65. ud.localfile = d.expand(urllib.parse.unquote(ud.host + ud.path).replace("/", "."))
  66. self.basecmd = d.getVar("FETCHCMD_wget") or "/usr/bin/env wget -t 2 -T 30 --passive-ftp --no-check-certificate"
  67. def _runwget(self, ud, d, command, quiet, workdir=None):
  68. progresshandler = WgetProgressHandler(d)
  69. logger.debug(2, "Fetching %s using command '%s'" % (ud.url, command))
  70. bb.fetch2.check_network_access(d, command, ud.url)
  71. runfetchcmd(command + ' --progress=dot -v', d, quiet, log=progresshandler, workdir=workdir)
  72. def download(self, ud, d):
  73. """Fetch urls"""
  74. fetchcmd = self.basecmd
  75. if 'downloadfilename' in ud.parm:
  76. localpath = os.path.join(d.getVar("DL_DIR"), ud.localfile)
  77. bb.utils.mkdirhier(os.path.dirname(localpath))
  78. fetchcmd += " -O %s" % shlex.quote(localpath)
  79. if ud.user and ud.pswd:
  80. fetchcmd += " --user=%s --password=%s --auth-no-challenge" % (ud.user, ud.pswd)
  81. uri = ud.url.split(";")[0]
  82. if os.path.exists(ud.localpath):
  83. # file exists, but we didnt complete it.. trying again..
  84. fetchcmd += d.expand(" -c -P ${DL_DIR} '%s'" % uri)
  85. else:
  86. fetchcmd += d.expand(" -P ${DL_DIR} '%s'" % uri)
  87. self._runwget(ud, d, fetchcmd, False)
  88. # Sanity check since wget can pretend it succeed when it didn't
  89. # Also, this used to happen if sourceforge sent us to the mirror page
  90. if not os.path.exists(ud.localpath):
  91. raise FetchError("The fetch command returned success for url %s but %s doesn't exist?!" % (uri, ud.localpath), uri)
  92. if os.path.getsize(ud.localpath) == 0:
  93. os.remove(ud.localpath)
  94. raise FetchError("The fetch of %s resulted in a zero size file?! Deleting and failing since this isn't right." % (uri), uri)
  95. return True
  96. def checkstatus(self, fetch, ud, d, try_again=True):
  97. class HTTPConnectionCache(http.client.HTTPConnection):
  98. if fetch.connection_cache:
  99. def connect(self):
  100. """Connect to the host and port specified in __init__."""
  101. sock = fetch.connection_cache.get_connection(self.host, self.port)
  102. if sock:
  103. self.sock = sock
  104. else:
  105. self.sock = socket.create_connection((self.host, self.port),
  106. self.timeout, self.source_address)
  107. fetch.connection_cache.add_connection(self.host, self.port, self.sock)
  108. if self._tunnel_host:
  109. self._tunnel()
  110. class CacheHTTPHandler(urllib.request.HTTPHandler):
  111. def http_open(self, req):
  112. return self.do_open(HTTPConnectionCache, req)
  113. def do_open(self, http_class, req):
  114. """Return an addinfourl object for the request, using http_class.
  115. http_class must implement the HTTPConnection API from httplib.
  116. The addinfourl return value is a file-like object. It also
  117. has methods and attributes including:
  118. - info(): return a mimetools.Message object for the headers
  119. - geturl(): return the original request URL
  120. - code: HTTP status code
  121. """
  122. host = req.host
  123. if not host:
  124. raise urllib.error.URLError('no host given')
  125. h = http_class(host, timeout=req.timeout) # will parse host:port
  126. h.set_debuglevel(self._debuglevel)
  127. headers = dict(req.unredirected_hdrs)
  128. headers.update(dict((k, v) for k, v in list(req.headers.items())
  129. if k not in headers))
  130. # We want to make an HTTP/1.1 request, but the addinfourl
  131. # class isn't prepared to deal with a persistent connection.
  132. # It will try to read all remaining data from the socket,
  133. # which will block while the server waits for the next request.
  134. # So make sure the connection gets closed after the (only)
  135. # request.
  136. # Don't close connection when connection_cache is enabled,
  137. if fetch.connection_cache is None:
  138. headers["Connection"] = "close"
  139. else:
  140. headers["Connection"] = "Keep-Alive" # Works for HTTP/1.0
  141. headers = dict(
  142. (name.title(), val) for name, val in list(headers.items()))
  143. if req._tunnel_host:
  144. tunnel_headers = {}
  145. proxy_auth_hdr = "Proxy-Authorization"
  146. if proxy_auth_hdr in headers:
  147. tunnel_headers[proxy_auth_hdr] = headers[proxy_auth_hdr]
  148. # Proxy-Authorization should not be sent to origin
  149. # server.
  150. del headers[proxy_auth_hdr]
  151. h.set_tunnel(req._tunnel_host, headers=tunnel_headers)
  152. try:
  153. h.request(req.get_method(), req.selector, req.data, headers)
  154. except socket.error as err: # XXX what error?
  155. # Don't close connection when cache is enabled.
  156. # Instead, try to detect connections that are no longer
  157. # usable (for example, closed unexpectedly) and remove
  158. # them from the cache.
  159. if fetch.connection_cache is None:
  160. h.close()
  161. elif isinstance(err, OSError) and err.errno == errno.EBADF:
  162. # This happens when the server closes the connection despite the Keep-Alive.
  163. # Apparently urllib then uses the file descriptor, expecting it to be
  164. # connected, when in reality the connection is already gone.
  165. # We let the request fail and expect it to be
  166. # tried once more ("try_again" in check_status()),
  167. # with the dead connection removed from the cache.
  168. # If it still fails, we give up, which can happend for bad
  169. # HTTP proxy settings.
  170. fetch.connection_cache.remove_connection(h.host, h.port)
  171. raise urllib.error.URLError(err)
  172. else:
  173. try:
  174. r = h.getresponse(buffering=True)
  175. except TypeError: # buffering kw not supported
  176. r = h.getresponse()
  177. # Pick apart the HTTPResponse object to get the addinfourl
  178. # object initialized properly.
  179. # Wrap the HTTPResponse object in socket's file object adapter
  180. # for Windows. That adapter calls recv(), so delegate recv()
  181. # to read(). This weird wrapping allows the returned object to
  182. # have readline() and readlines() methods.
  183. # XXX It might be better to extract the read buffering code
  184. # out of socket._fileobject() and into a base class.
  185. r.recv = r.read
  186. # no data, just have to read
  187. r.read()
  188. class fp_dummy(object):
  189. def read(self):
  190. return ""
  191. def readline(self):
  192. return ""
  193. def close(self):
  194. pass
  195. closed = False
  196. resp = urllib.response.addinfourl(fp_dummy(), r.msg, req.get_full_url())
  197. resp.code = r.status
  198. resp.msg = r.reason
  199. # Close connection when server request it.
  200. if fetch.connection_cache is not None:
  201. if 'Connection' in r.msg and r.msg['Connection'] == 'close':
  202. fetch.connection_cache.remove_connection(h.host, h.port)
  203. return resp
  204. class HTTPMethodFallback(urllib.request.BaseHandler):
  205. """
  206. Fallback to GET if HEAD is not allowed (405 HTTP error)
  207. """
  208. def http_error_405(self, req, fp, code, msg, headers):
  209. fp.read()
  210. fp.close()
  211. if req.get_method() != 'GET':
  212. newheaders = dict((k, v) for k, v in list(req.headers.items())
  213. if k.lower() not in ("content-length", "content-type"))
  214. return self.parent.open(urllib.request.Request(req.get_full_url(),
  215. headers=newheaders,
  216. origin_req_host=req.origin_req_host,
  217. unverifiable=True))
  218. raise urllib.request.HTTPError(req, code, msg, headers, None)
  219. # Some servers (e.g. GitHub archives, hosted on Amazon S3) return 403
  220. # Forbidden when they actually mean 405 Method Not Allowed.
  221. http_error_403 = http_error_405
  222. class FixedHTTPRedirectHandler(urllib.request.HTTPRedirectHandler):
  223. """
  224. urllib2.HTTPRedirectHandler resets the method to GET on redirect,
  225. when we want to follow redirects using the original method.
  226. """
  227. def redirect_request(self, req, fp, code, msg, headers, newurl):
  228. newreq = urllib.request.HTTPRedirectHandler.redirect_request(self, req, fp, code, msg, headers, newurl)
  229. newreq.get_method = req.get_method
  230. return newreq
  231. exported_proxies = export_proxies(d)
  232. handlers = [FixedHTTPRedirectHandler, HTTPMethodFallback]
  233. if exported_proxies:
  234. handlers.append(urllib.request.ProxyHandler())
  235. handlers.append(CacheHTTPHandler())
  236. # Since Python 2.7.9 ssl cert validation is enabled by default
  237. # see PEP-0476, this causes verification errors on some https servers
  238. # so disable by default.
  239. import ssl
  240. if hasattr(ssl, '_create_unverified_context'):
  241. handlers.append(urllib.request.HTTPSHandler(context=ssl._create_unverified_context()))
  242. opener = urllib.request.build_opener(*handlers)
  243. try:
  244. uri = ud.url.split(";")[0]
  245. r = urllib.request.Request(uri)
  246. r.get_method = lambda: "HEAD"
  247. # Some servers (FusionForge, as used on Alioth) require that the
  248. # optional Accept header is set.
  249. r.add_header("Accept", "*/*")
  250. r.add_header("User-Agent", "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.12) Gecko/20101027 Ubuntu/9.10 (karmic) Firefox/3.6.12")
  251. def add_basic_auth(login_str, request):
  252. '''Adds Basic auth to http request, pass in login:password as string'''
  253. import base64
  254. encodeuser = base64.b64encode(login_str.encode('utf-8')).decode("utf-8")
  255. authheader = "Basic %s" % encodeuser
  256. r.add_header("Authorization", authheader)
  257. if ud.user and ud.pswd:
  258. add_basic_auth(ud.user + ':' + ud.pswd, r)
  259. try:
  260. import netrc
  261. n = netrc.netrc()
  262. login, unused, password = n.authenticators(urllib.parse.urlparse(uri).hostname)
  263. add_basic_auth("%s:%s" % (login, password), r)
  264. except (TypeError, ImportError, IOError, netrc.NetrcParseError):
  265. pass
  266. with opener.open(r) as response:
  267. pass
  268. except urllib.error.URLError as e:
  269. if try_again:
  270. logger.debug(2, "checkstatus: trying again")
  271. return self.checkstatus(fetch, ud, d, False)
  272. else:
  273. # debug for now to avoid spamming the logs in e.g. remote sstate searches
  274. logger.debug(2, "checkstatus() urlopen failed: %s" % e)
  275. return False
  276. return True
  277. def _parse_path(self, regex, s):
  278. """
  279. Find and group name, version and archive type in the given string s
  280. """
  281. m = regex.search(s)
  282. if m:
  283. pname = ''
  284. pver = ''
  285. ptype = ''
  286. mdict = m.groupdict()
  287. if 'name' in mdict.keys():
  288. pname = mdict['name']
  289. if 'pver' in mdict.keys():
  290. pver = mdict['pver']
  291. if 'type' in mdict.keys():
  292. ptype = mdict['type']
  293. bb.debug(3, "_parse_path: %s, %s, %s" % (pname, pver, ptype))
  294. return (pname, pver, ptype)
  295. return None
  296. def _modelate_version(self, version):
  297. if version[0] in ['.', '-']:
  298. if version[1].isdigit():
  299. version = version[1] + version[0] + version[2:len(version)]
  300. else:
  301. version = version[1:len(version)]
  302. version = re.sub('-', '.', version)
  303. version = re.sub('_', '.', version)
  304. version = re.sub('(rc)+', '.1000.', version)
  305. version = re.sub('(beta)+', '.100.', version)
  306. version = re.sub('(alpha)+', '.10.', version)
  307. if version[0] == 'v':
  308. version = version[1:len(version)]
  309. return version
  310. def _vercmp(self, old, new):
  311. """
  312. Check whether 'new' is newer than 'old' version. We use existing vercmp() for the
  313. purpose. PE is cleared in comparison as it's not for build, and PR is cleared too
  314. for simplicity as it's somehow difficult to get from various upstream format
  315. """
  316. (oldpn, oldpv, oldsuffix) = old
  317. (newpn, newpv, newsuffix) = new
  318. # Check for a new suffix type that we have never heard of before
  319. if newsuffix:
  320. m = self.suffix_regex_comp.search(newsuffix)
  321. if not m:
  322. bb.warn("%s has a possible unknown suffix: %s" % (newpn, newsuffix))
  323. return False
  324. # Not our package so ignore it
  325. if oldpn != newpn:
  326. return False
  327. oldpv = self._modelate_version(oldpv)
  328. newpv = self._modelate_version(newpv)
  329. return bb.utils.vercmp(("0", oldpv, ""), ("0", newpv, ""))
  330. def _fetch_index(self, uri, ud, d):
  331. """
  332. Run fetch checkstatus to get directory information
  333. """
  334. f = tempfile.NamedTemporaryFile()
  335. with tempfile.TemporaryDirectory(prefix="wget-index-") as workdir, tempfile.NamedTemporaryFile(dir=workdir, prefix="wget-listing-") as f:
  336. agent = "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.12) Gecko/20101027 Ubuntu/9.10 (karmic) Firefox/3.6.12"
  337. fetchcmd = self.basecmd
  338. fetchcmd += " -O " + f.name + " --user-agent='" + agent + "' '" + uri + "'"
  339. try:
  340. self._runwget(ud, d, fetchcmd, True, workdir=workdir)
  341. fetchresult = f.read()
  342. except bb.fetch2.BBFetchException:
  343. fetchresult = ""
  344. return fetchresult
  345. def _check_latest_version(self, url, package, package_regex, current_version, ud, d):
  346. """
  347. Return the latest version of a package inside a given directory path
  348. If error or no version, return ""
  349. """
  350. valid = 0
  351. version = ['', '', '']
  352. bb.debug(3, "VersionURL: %s" % (url))
  353. soup = BeautifulSoup(self._fetch_index(url, ud, d), "html.parser", parse_only=SoupStrainer("a"))
  354. if not soup:
  355. bb.debug(3, "*** %s NO SOUP" % (url))
  356. return ""
  357. for line in soup.find_all('a', href=True):
  358. bb.debug(3, "line['href'] = '%s'" % (line['href']))
  359. bb.debug(3, "line = '%s'" % (str(line)))
  360. newver = self._parse_path(package_regex, line['href'])
  361. if not newver:
  362. newver = self._parse_path(package_regex, str(line))
  363. if newver:
  364. bb.debug(3, "Upstream version found: %s" % newver[1])
  365. if valid == 0:
  366. version = newver
  367. valid = 1
  368. elif self._vercmp(version, newver) < 0:
  369. version = newver
  370. pupver = re.sub('_', '.', version[1])
  371. bb.debug(3, "*** %s -> UpstreamVersion = %s (CurrentVersion = %s)" %
  372. (package, pupver or "N/A", current_version[1]))
  373. if valid:
  374. return pupver
  375. return ""
  376. def _check_latest_version_by_dir(self, dirver, package, package_regex, current_version, ud, d):
  377. """
  378. Scan every directory in order to get upstream version.
  379. """
  380. version_dir = ['', '', '']
  381. version = ['', '', '']
  382. dirver_regex = re.compile(r"(?P<pfx>\D*)(?P<ver>(\d+[\.\-_])+(\d+))")
  383. s = dirver_regex.search(dirver)
  384. if s:
  385. version_dir[1] = s.group('ver')
  386. else:
  387. version_dir[1] = dirver
  388. dirs_uri = bb.fetch.encodeurl([ud.type, ud.host,
  389. ud.path.split(dirver)[0], ud.user, ud.pswd, {}])
  390. bb.debug(3, "DirURL: %s, %s" % (dirs_uri, package))
  391. soup = BeautifulSoup(self._fetch_index(dirs_uri, ud, d), "html.parser", parse_only=SoupStrainer("a"))
  392. if not soup:
  393. return version[1]
  394. for line in soup.find_all('a', href=True):
  395. s = dirver_regex.search(line['href'].strip("/"))
  396. if s:
  397. sver = s.group('ver')
  398. # When prefix is part of the version directory it need to
  399. # ensure that only version directory is used so remove previous
  400. # directories if exists.
  401. #
  402. # Example: pfx = '/dir1/dir2/v' and version = '2.5' the expected
  403. # result is v2.5.
  404. spfx = s.group('pfx').split('/')[-1]
  405. version_dir_new = ['', sver, '']
  406. if self._vercmp(version_dir, version_dir_new) <= 0:
  407. dirver_new = spfx + sver
  408. path = ud.path.replace(dirver, dirver_new, True) \
  409. .split(package)[0]
  410. uri = bb.fetch.encodeurl([ud.type, ud.host, path,
  411. ud.user, ud.pswd, {}])
  412. pupver = self._check_latest_version(uri,
  413. package, package_regex, current_version, ud, d)
  414. if pupver:
  415. version[1] = pupver
  416. version_dir = version_dir_new
  417. return version[1]
  418. def _init_regexes(self, package, ud, d):
  419. """
  420. Match as many patterns as possible such as:
  421. gnome-common-2.20.0.tar.gz (most common format)
  422. gtk+-2.90.1.tar.gz
  423. xf86-input-synaptics-12.6.9.tar.gz
  424. dri2proto-2.3.tar.gz
  425. blktool_4.orig.tar.gz
  426. libid3tag-0.15.1b.tar.gz
  427. unzip552.tar.gz
  428. icu4c-3_6-src.tgz
  429. genext2fs_1.3.orig.tar.gz
  430. gst-fluendo-mp3
  431. """
  432. # match most patterns which uses "-" as separator to version digits
  433. pn_prefix1 = r"[a-zA-Z][a-zA-Z0-9]*([-_][a-zA-Z]\w+)*\+?[-_]"
  434. # a loose pattern such as for unzip552.tar.gz
  435. pn_prefix2 = r"[a-zA-Z]+"
  436. # a loose pattern such as for 80325-quicky-0.4.tar.gz
  437. pn_prefix3 = r"[0-9]+[-]?[a-zA-Z]+"
  438. # Save the Package Name (pn) Regex for use later
  439. pn_regex = r"(%s|%s|%s)" % (pn_prefix1, pn_prefix2, pn_prefix3)
  440. # match version
  441. pver_regex = r"(([A-Z]*\d+[a-zA-Z]*[\.\-_]*)+)"
  442. # match arch
  443. parch_regex = "-source|_all_"
  444. # src.rpm extension was added only for rpm package. Can be removed if the rpm
  445. # packaged will always be considered as having to be manually upgraded
  446. psuffix_regex = r"(tar\.gz|tgz|tar\.bz2|zip|xz|tar\.lz|rpm|bz2|orig\.tar\.gz|tar\.xz|src\.tar\.gz|src\.tgz|svnr\d+\.tar\.bz2|stable\.tar\.gz|src\.rpm)"
  447. # match name, version and archive type of a package
  448. package_regex_comp = re.compile(r"(?P<name>%s?\.?v?)(?P<pver>%s)(?P<arch>%s)?[\.-](?P<type>%s$)"
  449. % (pn_regex, pver_regex, parch_regex, psuffix_regex))
  450. self.suffix_regex_comp = re.compile(psuffix_regex)
  451. # compile regex, can be specific by package or generic regex
  452. pn_regex = d.getVar('UPSTREAM_CHECK_REGEX')
  453. if pn_regex:
  454. package_custom_regex_comp = re.compile(pn_regex)
  455. else:
  456. version = self._parse_path(package_regex_comp, package)
  457. if version:
  458. package_custom_regex_comp = re.compile(
  459. r"(?P<name>%s)(?P<pver>%s)(?P<arch>%s)?[\.-](?P<type>%s)" %
  460. (re.escape(version[0]), pver_regex, parch_regex, psuffix_regex))
  461. else:
  462. package_custom_regex_comp = None
  463. return package_custom_regex_comp
  464. def latest_versionstring(self, ud, d):
  465. """
  466. Manipulate the URL and try to obtain the latest package version
  467. sanity check to ensure same name and type.
  468. """
  469. package = ud.path.split("/")[-1]
  470. current_version = ['', d.getVar('PV'), '']
  471. """possible to have no version in pkg name, such as spectrum-fw"""
  472. if not re.search(r"\d+", package):
  473. current_version[1] = re.sub('_', '.', current_version[1])
  474. current_version[1] = re.sub('-', '.', current_version[1])
  475. return (current_version[1], '')
  476. package_regex = self._init_regexes(package, ud, d)
  477. if package_regex is None:
  478. bb.warn("latest_versionstring: package %s don't match pattern" % (package))
  479. return ('', '')
  480. bb.debug(3, "latest_versionstring, regex: %s" % (package_regex.pattern))
  481. uri = ""
  482. regex_uri = d.getVar("UPSTREAM_CHECK_URI")
  483. if not regex_uri:
  484. path = ud.path.split(package)[0]
  485. # search for version matches on folders inside the path, like:
  486. # "5.7" in http://download.gnome.org/sources/${PN}/5.7/${PN}-${PV}.tar.gz
  487. dirver_regex = re.compile(r"(?P<dirver>[^/]*(\d+\.)*\d+([-_]r\d+)*)/")
  488. m = dirver_regex.search(path)
  489. if m:
  490. pn = d.getVar('PN')
  491. dirver = m.group('dirver')
  492. dirver_pn_regex = re.compile(r"%s\d?" % (re.escape(pn)))
  493. if not dirver_pn_regex.search(dirver):
  494. return (self._check_latest_version_by_dir(dirver,
  495. package, package_regex, current_version, ud, d), '')
  496. uri = bb.fetch.encodeurl([ud.type, ud.host, path, ud.user, ud.pswd, {}])
  497. else:
  498. uri = regex_uri
  499. return (self._check_latest_version(uri, package, package_regex,
  500. current_version, ud, d), '')