mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-24 13:50:22 -07:00
Port modules away from __file__
* __file__ won't work if we want to invoke modules via -m or if we figure out how to keep modules from hitting the disk with pipelining. * module.tmpdir is the new way to place a file where it will be cleaned automatically. Change format string to not depend on __file__: * cloud/amazon/ec2_elb_lb.py * cloud/amazon/elb_classic_lb.py Use module.tempdir: * packaging/os/apt.py * files/unarchive.py
This commit is contained in:
parent
c227a0c8bb
commit
9350a81ae4
5 changed files with 12 additions and 8 deletions
|
@ -821,8 +821,7 @@ def main():
|
|||
module.fail_json(msg="Source '%s' failed to transfer" % src)
|
||||
# If remote_src=true, and src= contains ://, try and download the file to a temp directory.
|
||||
elif '://' in src:
|
||||
tempdir = os.path.dirname(os.path.realpath(__file__))
|
||||
package = os.path.join(tempdir, str(src.rsplit('/', 1)[1]))
|
||||
new_src = os.path.join(module.tmpdir, to_native(src.rsplit('/', 1)[1], errors='surrogate_or_strict'))
|
||||
try:
|
||||
rsp, info = fetch_url(module, src)
|
||||
# If download fails, raise a proper exception
|
||||
|
@ -830,7 +829,7 @@ def main():
|
|||
raise Exception(info['msg'])
|
||||
|
||||
# open in binary mode for python3
|
||||
f = open(package, 'wb')
|
||||
f = open(new_src, 'wb')
|
||||
# Read 1kb at a time to save on ram
|
||||
while True:
|
||||
data = rsp.read(BUFSIZE)
|
||||
|
@ -841,7 +840,7 @@ def main():
|
|||
|
||||
f.write(data)
|
||||
f.close()
|
||||
src = package
|
||||
src = new_src
|
||||
except Exception as e:
|
||||
module.fail_json(msg="Failure downloading %s, %s" % (src, to_native(e)))
|
||||
else:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue