wget.py 25 KB

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