I'm trying to automate a process to zip a python file and all of its dependencies with 755 permissions. (The reason for this is to upload them for an AWS Lambda which requires 755 permissions on the file).
If I just wanted to zip with dependencies I would just run
zip -r9 ${OLDPWD}/function.zip .
And, from How do I set permissions (attributes) on a file in a ZIP file using Python's zipfile module? I was able to write a python script to zip with permissions using
def main(lambda_filename):
zipname = lambda_filename + ".zip"
filename = lambda_filename + ".py"
zip = zipfile.ZipFile(zipname, 'w', zipfile.ZIP_DEFLATED)
f = open(filename, 'r')
bytes = f.read()
f.close()
info = zipfile.ZipInfo(filename)
info.external_attr = 0o755 << 16
zip.writestr(info, bytes, zipfile.ZIP_DEFLATED)
zip.close()
if __name__ == "__main__":
filename = sys.argv[1]
main(filename)
But, how would I combine these two so that I can zip all my dependencies and then add my file with the 755 permissions? Is there some way I can run my zip -r9
and then add my file later without overwriting?
Thanks!