s3.py: Add support for fetching source mirrors/minor cleanup
PATCH 1/1 s3.py: Add support for fetching source mirrors/minor cleanup
This commits main purpose is to add support for fetching source mirrors. In the current incarnation:
SOURCE_MIRROR_URL ?= "s3://mybucket/downloads"
will fail for two reasons. First, download doesn't support it, but second, without aws included in HOSTTOOLS you'll end up with aws not being found by bitbake (for either source mirrors or sstate mirrors).
Part of this is fixed with this commit. However, this will still fail if HOSTTOOLS doesn't include 'aws' in bitbake.conf. I've another commit or two to fix that as well.
I've also DRYed up some of the error handling, removed the hardcoded aws and added some logging.
--- lib/bb/fetch2/s3.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-)
lib/bb/fetch2/s3.py +14 -6
@@ -34,6 +34,7 @@ import urllib.request, urllib.parse, urllib.error from bb.fetch2 import FetchMethod from bb.fetch2 import FetchError from bb.fetch2 import runfetchcmd +from bb.fetch2 import logger class S3(FetchMethod): """Class to fetch urls via 'aws s3'"""
@@ -60,8 +61,13 @@ class S3(FetchMethod): Fetch urls Assumes localpath was called first """ - - cmd = 'aws s3 cp s3://%s%s %s' % (ud.host, ud.path, ud.localpath) + if 'downloadfilename' in ud.parm: + dldir = d.getVar("DL_DIR", True) + bb.utils.mkdirhier(os.path.dirname(dldir + os.sep + ud.localfile)) + cmd = '%s cp s3://%s%s %s%s%s' % (d.getVar("FETCHCMD_s3"), ud.host, ud.path, dldir, os.sep, ud.localpath) + else: + cmd = '%s cp s3://%s%s %s' % (d.getVar("FETCHCMD_s3"), ud.host, ud.path, ud.localpath) + logger.debug(2, "Fetching %s using command '%s'" % (ud.url, cmd)) bb.fetch2.check_network_access(d, cmd, ud.url) runfetchcmd(cmd, d)
@@ -70,11 +76,11 @@ class S3(FetchMethod): # tool with a little healthy suspicion). if not os.path.exists(ud.localpath): - raise FetchError("The aws cp command returned success for s3://%s%s but %s doesn't exist?!" % (ud.host, ud.path, ud.localpath)) + raise FetchError("The command %s returned success but %s doesn't exist?!" % (cmd, ud.localpath)) if os.path.getsize(ud.localpath) == 0: os.remove(ud.localpath) - raise FetchError("The aws cp command for s3://%s%s resulted in a zero size file?! Deleting and failing since this isn't right." % (ud.host, ud.path)) + raise FetchError("The command %s resulted in a zero size file?! Deleting and failing since this isn't right." % (cmd)) return True
@@ -83,7 +89,9 @@ class S3(FetchMethod): Check the status of a URL """ - cmd = 'aws s3 ls s3://%s%s' % (ud.host, ud.path) + cmd = '%s ls s3://%s%s' % (d.getVar("FETCHCMD_s3"), ud.host, ud.path) + logger.debug(2, "Checking %s using command '%s'" % (ud.url, cmd)) + bb.fetch2.check_network_access(d, cmd, ud.url) output = runfetchcmd(cmd, d)
@@ -91,6 +99,6 @@ class S3(FetchMethod): # is not found, so check output of the command to confirm success. if not output: - raise FetchError("The aws ls command for s3://%s%s gave empty output" % (ud.host, ud.path)) + raise FetchError("The command %s gave empty output" % (cmd)) return True
Signature · 1 line
1.9.1
Quoted 45 lines · Elizabeth 'pidge' Flanagan
This commits main purpose is to add support for fetching source mirrors. In the current incarnation:
SOURCE_MIRROR_URL?= "s3://mybucket/downloads"will fail for two reasons. First, download doesn't support it, but second, without aws included in HOSTTOOLS you'll end up with aws not being found by bitbake (for either source mirrors or sstate mirrors).
Part of this is fixed with this commit. However, this will still fail if HOSTTOOLS doesn't include 'aws' in bitbake.conf. I've another commit or two to fix that as well.
I've also DRYed up some of the error handling, removed the hardcoded aws and added some logging.
Signed-off-by Elizabeth 'pidge' Flanagan <[email protected]>---
lib/bb/fetch2/s3.py | 20 ++++++++++++++------1 file changed, 14 insertions(+), 6 deletions(-)lib/bb/fetch2/s3.py +0
-0@@ -34,6 +34,7 @@ import urllib.request, urllib.parse, urllib.errorfrom bb.fetch2 import FetchMethod
from bb.fetch2 import FetchError
from bb.fetch2 import runfetchcmd
+from bb.fetch2 import logger
class S3(FetchMethod):
"""Class to fetch urls via 'aws s3'"""lib/bb/fetch2/s3.py +0
-0@@ -60,8 +61,13 @@ class S3(FetchMethod):Fetch urls
Assumes localpath was called first
"""
-
- cmd = 'aws s3 cp s3://%s%s %s' % (ud.host, ud.path, ud.localpath)
+ if 'downloadfilename' in ud.parm:
+ dldir =d.getVar("DL_DIR", True)
+ bb.utils.mkdirhier(os.path.dirname(dldir + os.sep + ud.localfile))
Quoted 8 lines
+ cmd = '%s cp s3://%s%s %s%s%s' % (
d.getVar("FETCHCMD_s3"), ud.host, ud.path, dldir, os.sep, ud.localpath)
+ else:
+ cmd = '%s cp s3://%s%s %s' % (d.getVar("FETCHCMD_s3"), ud.host, ud.path, ud.localpath)
+ logger.debug(2, "Fetching %s using command '%s'" % (ud.url, cmd))
Do you actually need/use FETCHCMD_s3 ?
I'd prefer not to add this unless we really do need it.
Cheers,
Richard
Quoted 51 lines · Richard Purdie
Quoted 50 lines · Elizabeth 'pidge' Flanagan
This commits main purpose is to add support for fetching source mirrors. In the current incarnation:
SOURCE_MIRROR_URL?= "s3://mybucket/downloads"will fail for two reasons. First, download doesn't support it, but second, without aws included in HOSTTOOLS you'll end up with aws not being found by bitbake (for either source mirrors or sstate mirrors).
Part of this is fixed with this commit. However, this will still fail if HOSTTOOLS doesn't include 'aws' in bitbake.conf. I've another
commit or two to fix that as well.I've also DRYed up some of the error handling, removed the hardcoded
aws and added some logging.Signed-off-by Elizabeth 'pidge' Flanagan <[email protected]>---
lib/bb/fetch2/s3.py | 20 ++++++++++++++------1 file changed, 14 insertions(+), 6 deletions(-)lib/bb/fetch2/s3.py +0
-0@@ -34,6 +34,7 @@ import urllib.request, urllib.parse, urllib.errorfrom bb.fetch2 import FetchMethod
from bb.fetch2 import FetchError
from bb.fetch2 import runfetchcmd
+from bb.fetch2 import logger
class S3(FetchMethod):
"""Class to fetch urls via 'aws s3'"""lib/bb/fetch2/s3.py +0
-0@@ -60,8 +61,13 @@ class S3(FetchMethod):Fetch urls
Assumes localpath was called first
"""
-
- cmd = 'aws s3 cp s3://%s%s %s' % (ud.host, ud.path, ud.localpath)
+ if 'downloadfilename' in ud.parm:
+ dldir =d.getVar("DL_DIR", True)
+ bb.utils.mkdirhier(os.path.dirname(dldir + os.sep + ud.localfile))
+ cmd = '%s cp s3://%s%s %s%s%s' % (d.getVar("FETCHCMD_s3"), ud.host, ud.path, dldir, os.sep,
Quoted 9 lines
Quoted 7 lines
ud.localpath)
+ else:
+ cmd = '%s cp s3://%s%s %s' % (d.getVar("FETCHCMD_s3"), ud.host, ud.path, ud.localpath)
+ logger.debug(2, "Fetching %s using command '%s'" % (ud.url,
cmd))Do you actually need/use FETCHCMD_s3 ?
I use it so I can rip out aws-cli and use s3cmd.
-b
Quoted 5 lines
I'd prefer not to add this unless we really do need it.
Cheers,
Richard
Quoted 66 lines · Beth 'pidge' Flanagan
Quoted 56 lines · Richard Purdie
Quoted 53 lines · Elizabeth 'pidge' Flanagan
This commits main purpose is to add support for fetching source mirrors. In the current incarnation:
SOURCE_MIRROR_URL?= "s3://mybucket/downloads"will fail for two reasons. First, download doesn't support it, but second, without aws included in HOSTTOOLS you'll end up with aws not being found by bitbake (for either source mirrors or sstate mirrors).
Part of this is fixed with this commit. However, this will still fail if HOSTTOOLS doesn't include 'aws' in bitbake.conf. I've another
commit or two to fix that as well.I've also DRYed up some of the error handling, removed the hardcoded
aws and added some logging.Signed-off-by Elizabeth 'pidge' Flanagan <[email protected]>---
lib/bb/fetch2/s3.py | 20 ++++++++++++++------1 file changed, 14 insertions(+), 6 deletions(-)lib/bb/fetch2/s3.py +0
-0@@ -34,6 +34,7 @@ import urllib.request, urllib.parse,urllib.error
from bb.fetch2 import FetchMethod
from bb.fetch2 import FetchError
from bb.fetch2 import runfetchcmd
+from bb.fetch2 import logger
class S3(FetchMethod):
"""Class to fetch urls via 'aws s3'"""lib/bb/fetch2/s3.py +0
-0@@ -60,8 +61,13 @@ class S3(FetchMethod):Fetch urls
Assumes localpath was called first
"""
-
- cmd = 'aws s3 cp s3://%s%s %s' % (ud.host, ud.path, ud.localpath)
+ if 'downloadfilename' in ud.parm:
+ dldir =d.getVar("DL_DIR", True)
+ bb.utils.mkdirhier(os.path.dirname(dldir + os.sep + ud.localfile))
+ cmd = '%s cp s3://%s%s %s%s%s' % (d.getVar("FETCHCMD_s3"), ud.host, ud.path, dldir, os.sep, ud.localpath)Quoted 9 lines
Quoted 7 lines
+ else:
+ cmd = '%s cp s3://%s%s %s' % (d.getVar("FETCHCMD_s3"),
ud.host, ud.path, ud.localpath)
+ logger.debug(2, "Fetching %s using command '%s'" % (ud.url,
cmd))Do you actually need/use FETCHCMD_s3 ?
Quoted 1 line
I use it so I can rip out aws-cli and use s3cmd.
Ok. The way this needs to work then is that in __init__, you set a default command and then if d.getVar("FETCHCMD_s3") is set, overwrite it. This is so that the fetcher works without having to FETCHCMD_s3 (in common with all the other fetchers. You'd then use ud.cmd instead of all the getVars.
Cheers,
Richard
Quoted 73 lines · Richard Purdie
Quoted 72 lines · Beth 'pidge' Flanagan
Quoted 70 lines · Richard Purdie
Quoted 56 lines · Elizabeth 'pidge' Flanagan
This commits main purpose is to add support for fetching source mirrors. In the current incarnation:
SOURCE_MIRROR_URL?= "s3://mybucket/downloads"will fail for two reasons. First, download doesn't support it, but second, without aws included in HOSTTOOLS you'll end up with aws not being found by bitbake (for either source mirrors or
sstate mirrors).Part of this is fixed with this commit. However, this will still
fail if HOSTTOOLS doesn't include 'aws' in bitbake.conf. I've another
commit or two to fix that as well.I've also DRYed up some of the error handling, removed the hardcoded
aws and added some logging.Signed-off-by Elizabeth 'pidge' Flanagan <[email protected]>---
lib/bb/fetch2/s3.py | 20 ++++++++++++++------1 file changed, 14 insertions(+), 6 deletions(-)lib/bb/fetch2/s3.py +0
-0@@ -34,6 +34,7 @@ import urllib.request, urllib.parse,urllib.error
from bb.fetch2 import FetchMethod
from bb.fetch2 import FetchError
from bb.fetch2 import runfetchcmd
+from bb.fetch2 import logger
class S3(FetchMethod):
"""Class to fetch urls via 'aws s3'"""lib/bb/fetch2/s3.py +0
-0@@ -60,8 +61,13 @@ class S3(FetchMethod):Fetch urls
Assumes localpath was called first
"""
-
- cmd = 'aws s3 cp s3://%s%s %s' % (ud.host, ud.path, ud.localpath)
+ if 'downloadfilename' in ud.parm:
+ dldir =d.getVar("DL_DIR", True)
+ bb.utils.mkdirhier(os.path.dirname(dldir + os.sep +
ud.localfile))
+ cmd = '%s cp s3://%s%s %s%s%s' % (d.getVar("FETCHCMD_s3"), ud.host, ud.path, dldir, os.sep,Quoted 8 lines
ud.localpath)
+ else:
+ cmd = '%s cp s3://%s%s %s' % (d.getVar("FETCHCMD_s3"),
ud.host, ud.path, ud.localpath)
+ logger.debug(2, "Fetching %s using command '%s'" % (ud.url,
cmd))Do you actually need/use FETCHCMD_s3 ?
Quoted 8 lines
Quoted 1 line
I use it so I can rip out aws-cli and use s3cmd.
Ok. The way this needs to work then is that in
__init__, you set a default command and then if d.getVar("FETCHCMD_s3") is set, overwrite it. This is so that the fetcher works without having toFETCHCMD_s3(in
common with all the other fetchers. You'd then use ud.cmd instead of all the getVars.
Ah, ok. v2 incoming in a bit.
Quoted 2 lines
Cheers,
Richard