bitbake/fetch2: Add explict network access exception and handling to give users usable error messages
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
parent
4a226460d5
commit
029f19bd3d
|
@ -117,6 +117,16 @@ class SHA256SumError(MD5SumError):
|
||||||
BBFetchException.__init__(self, msg)
|
BBFetchException.__init__(self, msg)
|
||||||
self.args = (path, wanted, got, url)
|
self.args = (path, wanted, got, url)
|
||||||
|
|
||||||
|
class NetworkAccess(BBFetchException):
|
||||||
|
"""Exception raised when network access is disabled but it is required."""
|
||||||
|
def __init__(self, url, cmd):
|
||||||
|
msg = "Network access disabled through BB_NO_NETWORK but access rquested with command %s (for url %s)" % (cmd, url)
|
||||||
|
self.url = url
|
||||||
|
self.cmd = cmd
|
||||||
|
BBFetchException.__init__(self, msg)
|
||||||
|
self.args = (url, cmd)
|
||||||
|
|
||||||
|
|
||||||
def decodeurl(url):
|
def decodeurl(url):
|
||||||
"""Decodes an URL into the tokens (scheme, network location, path,
|
"""Decodes an URL into the tokens (scheme, network location, path,
|
||||||
user, password, parameters).
|
user, password, parameters).
|
||||||
|
@ -398,12 +408,12 @@ def runfetchcmd(cmd, d, quiet = False, cleanup = []):
|
||||||
|
|
||||||
return output
|
return output
|
||||||
|
|
||||||
def check_network_access(d, info = ""):
|
def check_network_access(d, info = "", url = None):
|
||||||
"""
|
"""
|
||||||
log remote network access, and error if BB_NO_NETWORK is set
|
log remote network access, and error if BB_NO_NETWORK is set
|
||||||
"""
|
"""
|
||||||
if bb.data.getVar("BB_NO_NETWORK", d, True) == "1":
|
if bb.data.getVar("BB_NO_NETWORK", d, True) == "1":
|
||||||
raise FetchError("BB_NO_NETWORK is set, but the fetcher code attempted network access with the command %s" % info)
|
raise NetworkAccess(url, info)
|
||||||
else:
|
else:
|
||||||
logger.debug(1, "Fetcher accessed the network with the command %s" % info)
|
logger.debug(1, "Fetcher accessed the network with the command %s" % info)
|
||||||
|
|
||||||
|
@ -459,6 +469,9 @@ def try_mirrors(d, origud, mirrors, check = False):
|
||||||
os.symlink(ud.localpath, origud.localpath)
|
os.symlink(ud.localpath, origud.localpath)
|
||||||
return ud.localpath
|
return ud.localpath
|
||||||
|
|
||||||
|
except bb.fetch2.NetworkAccess:
|
||||||
|
raise
|
||||||
|
|
||||||
except bb.fetch2.BBFetchException as e:
|
except bb.fetch2.BBFetchException as e:
|
||||||
logger.debug(1, "Mirror fetch failure for url %s (original url: %s)" % (newuri, origud.url))
|
logger.debug(1, "Mirror fetch failure for url %s (original url: %s)" % (newuri, origud.url))
|
||||||
logger.debug(1, str(e))
|
logger.debug(1, str(e))
|
||||||
|
@ -909,6 +922,9 @@ class Fetch(object):
|
||||||
m.build_mirror_data(u, ud, self.d)
|
m.build_mirror_data(u, ud, self.d)
|
||||||
localpath = ud.localpath
|
localpath = ud.localpath
|
||||||
|
|
||||||
|
except bb.fetch2.NetworkAccess:
|
||||||
|
raise
|
||||||
|
|
||||||
except BBFetchException as e:
|
except BBFetchException as e:
|
||||||
logger.debug(1, str(e))
|
logger.debug(1, str(e))
|
||||||
# Remove any incomplete fetch
|
# Remove any incomplete fetch
|
||||||
|
|
|
@ -85,13 +85,13 @@ class Bzr(FetchMethod):
|
||||||
if os.access(os.path.join(ud.pkgdir, os.path.basename(ud.pkgdir), '.bzr'), os.R_OK):
|
if os.access(os.path.join(ud.pkgdir, os.path.basename(ud.pkgdir), '.bzr'), os.R_OK):
|
||||||
bzrcmd = self._buildbzrcommand(ud, d, "update")
|
bzrcmd = self._buildbzrcommand(ud, d, "update")
|
||||||
logger.debug(1, "BZR Update %s", loc)
|
logger.debug(1, "BZR Update %s", loc)
|
||||||
bb.fetch2.check_network_access(d, bzrcmd)
|
bb.fetch2.check_network_access(d, bzrcmd, ud.url)
|
||||||
os.chdir(os.path.join (ud.pkgdir, os.path.basename(ud.path)))
|
os.chdir(os.path.join (ud.pkgdir, os.path.basename(ud.path)))
|
||||||
runfetchcmd(bzrcmd, d)
|
runfetchcmd(bzrcmd, d)
|
||||||
else:
|
else:
|
||||||
bb.utils.remove(os.path.join(ud.pkgdir, os.path.basename(ud.pkgdir)), True)
|
bb.utils.remove(os.path.join(ud.pkgdir, os.path.basename(ud.pkgdir)), True)
|
||||||
bzrcmd = self._buildbzrcommand(ud, d, "fetch")
|
bzrcmd = self._buildbzrcommand(ud, d, "fetch")
|
||||||
bb.fetch2.check_network_access(d, bzrcmd)
|
bb.fetch2.check_network_access(d, bzrcmd, ud.url)
|
||||||
logger.debug(1, "BZR Checkout %s", loc)
|
logger.debug(1, "BZR Checkout %s", loc)
|
||||||
bb.mkdirhier(ud.pkgdir)
|
bb.mkdirhier(ud.pkgdir)
|
||||||
os.chdir(ud.pkgdir)
|
os.chdir(ud.pkgdir)
|
||||||
|
@ -124,7 +124,7 @@ class Bzr(FetchMethod):
|
||||||
"""
|
"""
|
||||||
logger.debug(2, "BZR fetcher hitting network for %s", url)
|
logger.debug(2, "BZR fetcher hitting network for %s", url)
|
||||||
|
|
||||||
bb.fetch2.check_network_access(d, self._buildbzrcommand(ud, d, "revno"))
|
bb.fetch2.check_network_access(d, self._buildbzrcommand(ud, d, "revno"), ud.url)
|
||||||
|
|
||||||
output = runfetchcmd(self._buildbzrcommand(ud, d, "revno"), d, True)
|
output = runfetchcmd(self._buildbzrcommand(ud, d, "revno"), d, True)
|
||||||
|
|
||||||
|
|
|
@ -132,7 +132,7 @@ class Cvs(FetchMethod):
|
||||||
moddir = os.path.join(pkgdir, localdir)
|
moddir = os.path.join(pkgdir, localdir)
|
||||||
if os.access(os.path.join(moddir, 'CVS'), os.R_OK):
|
if os.access(os.path.join(moddir, 'CVS'), os.R_OK):
|
||||||
logger.info("Update " + loc)
|
logger.info("Update " + loc)
|
||||||
bb.fetch2.check_network_access(d, cvsupdatecmd)
|
bb.fetch2.check_network_access(d, cvsupdatecmd, ud.url)
|
||||||
# update sources there
|
# update sources there
|
||||||
os.chdir(moddir)
|
os.chdir(moddir)
|
||||||
cmd = cvsupdatecmd
|
cmd = cvsupdatecmd
|
||||||
|
@ -142,7 +142,7 @@ class Cvs(FetchMethod):
|
||||||
bb.mkdirhier(pkgdir)
|
bb.mkdirhier(pkgdir)
|
||||||
os.chdir(pkgdir)
|
os.chdir(pkgdir)
|
||||||
logger.debug(1, "Running %s", cvscmd)
|
logger.debug(1, "Running %s", cvscmd)
|
||||||
bb.fetch2.check_network_access(d, cvscmd)
|
bb.fetch2.check_network_access(d, cvscmd, ud.url)
|
||||||
cmd = cvscmd
|
cmd = cvscmd
|
||||||
|
|
||||||
runfetchcmd(cmd, d, cleanup = [moddir])
|
runfetchcmd(cmd, d, cleanup = [moddir])
|
||||||
|
|
|
@ -132,7 +132,7 @@ class Git(FetchMethod):
|
||||||
if not self._contains_ref(ud.revisions[name], d):
|
if not self._contains_ref(ud.revisions[name], d):
|
||||||
needupdate = True
|
needupdate = True
|
||||||
if needupdate:
|
if needupdate:
|
||||||
bb.fetch2.check_network_access(d, "git fetch %s%s" % (ud.host, ud.path))
|
bb.fetch2.check_network_access(d, "git fetch %s%s" % (ud.host, ud.path), ud.url)
|
||||||
try:
|
try:
|
||||||
runfetchcmd("%s remote prune origin" % ud.basecmd, d)
|
runfetchcmd("%s remote prune origin" % ud.basecmd, d)
|
||||||
runfetchcmd("%s remote rm origin" % ud.basecmd, d)
|
runfetchcmd("%s remote rm origin" % ud.basecmd, d)
|
||||||
|
|
|
@ -124,7 +124,7 @@ class Hg(FetchMethod):
|
||||||
# update sources there
|
# update sources there
|
||||||
os.chdir(ud.moddir)
|
os.chdir(ud.moddir)
|
||||||
logger.debug(1, "Running %s", updatecmd)
|
logger.debug(1, "Running %s", updatecmd)
|
||||||
bb.fetch2.check_network_access(d, updatecmd)
|
bb.fetch2.check_network_access(d, updatecmd, ud.url)
|
||||||
runfetchcmd(updatecmd, d)
|
runfetchcmd(updatecmd, d)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
@ -134,7 +134,7 @@ class Hg(FetchMethod):
|
||||||
bb.mkdirhier(ud.pkgdir)
|
bb.mkdirhier(ud.pkgdir)
|
||||||
os.chdir(ud.pkgdir)
|
os.chdir(ud.pkgdir)
|
||||||
logger.debug(1, "Running %s", fetchcmd)
|
logger.debug(1, "Running %s", fetchcmd)
|
||||||
bb.fetch2.check_network_access(d, fetchcmd)
|
bb.fetch2.check_network_access(d, fetchcmd, ud.url)
|
||||||
runfetchcmd(fetchcmd, d)
|
runfetchcmd(fetchcmd, d)
|
||||||
|
|
||||||
# Even when we clone (fetch), we still need to update as hg's clone
|
# Even when we clone (fetch), we still need to update as hg's clone
|
||||||
|
|
|
@ -90,7 +90,7 @@ class Osc(FetchMethod):
|
||||||
# update sources there
|
# update sources there
|
||||||
os.chdir(ud.moddir)
|
os.chdir(ud.moddir)
|
||||||
logger.debug(1, "Running %s", oscupdatecmd)
|
logger.debug(1, "Running %s", oscupdatecmd)
|
||||||
bb.fetch2.check_network_access(d, oscupdatecmd)
|
bb.fetch2.check_network_access(d, oscupdatecmd, ud.url)
|
||||||
runfetchcmd(oscupdatecmd, d)
|
runfetchcmd(oscupdatecmd, d)
|
||||||
else:
|
else:
|
||||||
oscfetchcmd = self._buildosccommand(ud, d, "fetch")
|
oscfetchcmd = self._buildosccommand(ud, d, "fetch")
|
||||||
|
@ -99,7 +99,7 @@ class Osc(FetchMethod):
|
||||||
bb.mkdirhier(ud.pkgdir)
|
bb.mkdirhier(ud.pkgdir)
|
||||||
os.chdir(ud.pkgdir)
|
os.chdir(ud.pkgdir)
|
||||||
logger.debug(1, "Running %s", oscfetchcmd)
|
logger.debug(1, "Running %s", oscfetchcmd)
|
||||||
bb.fetch2.check_network_access(d, oscfetchcmd)
|
bb.fetch2.check_network_access(d, oscfetchcmd, ud.url)
|
||||||
runfetchcmd(oscfetchcmd, d)
|
runfetchcmd(oscfetchcmd, d)
|
||||||
|
|
||||||
os.chdir(os.path.join(ud.pkgdir + ud.path))
|
os.chdir(os.path.join(ud.pkgdir + ud.path))
|
||||||
|
|
|
@ -72,10 +72,10 @@ class Repo(FetchMethod):
|
||||||
bb.mkdirhier(os.path.join(codir, "repo"))
|
bb.mkdirhier(os.path.join(codir, "repo"))
|
||||||
os.chdir(os.path.join(codir, "repo"))
|
os.chdir(os.path.join(codir, "repo"))
|
||||||
if not os.path.exists(os.path.join(codir, "repo", ".repo")):
|
if not os.path.exists(os.path.join(codir, "repo", ".repo")):
|
||||||
bb.fetch2.check_network_access(d, "repo init -m %s -b %s -u %s://%s%s%s" % (ud.manifest, ud.branch, ud.proto, username, ud.host, ud.path))
|
bb.fetch2.check_network_access(d, "repo init -m %s -b %s -u %s://%s%s%s" % (ud.manifest, ud.branch, ud.proto, username, ud.host, ud.path), ud.url)
|
||||||
runfetchcmd("repo init -m %s -b %s -u %s://%s%s%s" % (ud.manifest, ud.branch, ud.proto, username, ud.host, ud.path), d)
|
runfetchcmd("repo init -m %s -b %s -u %s://%s%s%s" % (ud.manifest, ud.branch, ud.proto, username, ud.host, ud.path), d)
|
||||||
|
|
||||||
bb.fetch2.check_network_access(d, "repo sync %s" % ud.url)
|
bb.fetch2.check_network_access(d, "repo sync %s" % ud.url, ud.url)
|
||||||
runfetchcmd("repo sync", d)
|
runfetchcmd("repo sync", d)
|
||||||
os.chdir(codir)
|
os.chdir(codir)
|
||||||
|
|
||||||
|
|
|
@ -114,7 +114,7 @@ class SSH(FetchMethod):
|
||||||
commands.mkarg(ldir)
|
commands.mkarg(ldir)
|
||||||
)
|
)
|
||||||
|
|
||||||
bb.fetch2.check_network_access(d, cmd)
|
bb.fetch2.check_network_access(d, cmd, urldata.url)
|
||||||
|
|
||||||
runfetchcmd(cmd, d)
|
runfetchcmd(cmd, d)
|
||||||
|
|
||||||
|
|
|
@ -116,7 +116,7 @@ class Svn(FetchMethod):
|
||||||
# update sources there
|
# update sources there
|
||||||
os.chdir(ud.moddir)
|
os.chdir(ud.moddir)
|
||||||
logger.debug(1, "Running %s", svnupdatecmd)
|
logger.debug(1, "Running %s", svnupdatecmd)
|
||||||
bb.fetch2.check_network_access(d, svnupdatecmd)
|
bb.fetch2.check_network_access(d, svnupdatecmd, ud.url)
|
||||||
runfetchcmd(svnupdatecmd, d)
|
runfetchcmd(svnupdatecmd, d)
|
||||||
else:
|
else:
|
||||||
svnfetchcmd = self._buildsvncommand(ud, d, "fetch")
|
svnfetchcmd = self._buildsvncommand(ud, d, "fetch")
|
||||||
|
@ -125,7 +125,7 @@ class Svn(FetchMethod):
|
||||||
bb.mkdirhier(ud.pkgdir)
|
bb.mkdirhier(ud.pkgdir)
|
||||||
os.chdir(ud.pkgdir)
|
os.chdir(ud.pkgdir)
|
||||||
logger.debug(1, "Running %s", svnfetchcmd)
|
logger.debug(1, "Running %s", svnfetchcmd)
|
||||||
bb.fetch2.check_network_access(d, svnfetchcmd)
|
bb.fetch2.check_network_access(d, svnfetchcmd, ud.url)
|
||||||
runfetchcmd(svnfetchcmd, d)
|
runfetchcmd(svnfetchcmd, d)
|
||||||
|
|
||||||
scmdata = ud.parm.get("scmdata", "")
|
scmdata = ud.parm.get("scmdata", "")
|
||||||
|
|
Loading…
Reference in New Issue