def main(): output_zip = os.path.join(os.getcwd(), sys.argv[1]) input_files = get_input_files(sys.argv[2]) # Copy all the input_files into output_zip. # Adding contextlib.closing to be python 2.6 (for centos 6.7) compatible with contextlib.closing( zipfile.ZipFile(output_zip, 'w', zipfile.ZIP_DEFLATED)) as output_zip: zipinfo = zipfile.ZipInfo('WORKSPACE', (1980, 1, 1, 0, 0, 0)) zipinfo.external_attr = 0o644 << 16 output_zip.writestr(zipinfo, 'workspace(name = "bazel_tools")\n') zipinfo = zipfile.ZipInfo('tools/defaults/BUILD', (1980, 1, 1, 0, 0, 0)) zipinfo.external_attr = 0o644 << 16 output_zip.writestr(zipinfo, '') for archive_file, input_file in input_files: if os.path.basename(archive_file) in ('jdk.tar.gz', 'jdk.zip'): copy_jdk_into_archive(output_zip, archive_file, input_file) else: zipinfo = zipfile.ZipInfo(archive_file, (1980, 1, 1, 0, 0, 0)) zipinfo.external_attr = 0o755 << 16 if is_executable( input_file) else 0o644 << 16 zipinfo.compress_type = zipfile.ZIP_DEFLATED with open(input_file, 'rb') as f: output_zip.writestr(zipinfo, f.read())
def main(): output_zip = os.path.join(os.getcwd(), sys.argv[1]) input_files = get_input_files(sys.argv[2]) # Copy all the input_files into output_zip. # Adding contextlib.closing to be python 2.6 (for centos 6.7) compatible with contextlib.closing( zipfile.ZipFile(output_zip, 'w', zipfile.ZIP_DEFLATED)) as output_zip: zipinfo = zipfile.ZipInfo('WORKSPACE', (1980, 1, 1, 0, 0, 0)) zipinfo.external_attr = 0o644 << 16 output_zip.writestr(zipinfo, 'workspace(name = "bazel_tools")\n') zipinfo = zipfile.ZipInfo('tools/defaults/BUILD', (1980, 1, 1, 0, 0, 0)) zipinfo.external_attr = 0o644 << 16 output_zip.writestr(zipinfo, '') for archive_file, input_file in input_files: if os.path.basename(archive_file) in ('jdk.tar.gz', 'jdk.zip'): copy_jdk_into_archive(output_zip, archive_file, input_file) else: zipinfo = zipfile.ZipInfo(archive_file, (1980, 1, 1, 0, 0, 0)) zipinfo.external_attr = 0o755 << 16 if is_executable( input_file) else 0o644 << 16 zipinfo.compress_type = zipfile.ZIP_DEFLATED with open(input_file, 'rb') as f: output_zip.writestr(zipinfo, f.read())