def get_zip_file(self): """Returns a zip file file-like object with all the required source on it.""" self.project.create_workspace() destination = tempfile.mkdtemp(dir=self.project.get_workspace()) try: self._collect_lambda_content(destination) except subprocess.CalledProcessError as exc: shutil.rmtree(destination) raise exceptions.LambdaBuildProcessError(exc, self) with tempfile.SpooledTemporaryFile(0, 'wb') as tmp: with zipfile.ZipFile(tmp, 'w') as zf: for basedir, dirs, files in os.walk(destination): relative = os.path.relpath(basedir, destination) for filename in files: source = os.path.join(destination, basedir, filename) relative_destination = os.path.join(relative, filename) zf.write(source, relative_destination) tmp.seek(0) output = six.BytesIO(tmp.read()) output.seek(0) shutil.rmtree(destination) return output
def collect_and_run(self, stdin): self.project.create_workspace() destination = tempfile.mkdtemp(dir=self.project.get_workspace()) # Translate pythona architecture to go architecture. # https://go.googlesource.com/go/+/master/src/cmd/dist/build.go#1086 go_target_arch = {'i386': '386', 'x86_64': 'amd64'}[platform.processor()] try: self._collect_lambda_content( destination, go_target_os=platform.system().lower(), go_target_arch=go_target_arch ) except subprocess.CalledProcessError as exc: shutil.rmtree(destination) raise exceptions.LambdaBuildProcessError(exc, self) try: self.run(destination, stdin) finally: shutil.rmtree(destination)