| 45 | package.close() |
| 46 | |
| 47 | def create_package(filename, input_dir): |
| 48 | print('Creating package:', filename) |
| 49 | if filename.endswith('.tar.gz'): |
| 50 | with tarfile.open(filename, "w:gz") as package: |
| 51 | package.add(input_dir, arcname=os.path.basename(input_dir)) |
| 52 | elif filename.endswith('.zip'): |
| 53 | shutil.make_archive(filename[:-4], 'zip', os.path.dirname(input_dir), os.path.basename(input_dir)) |
| 54 | else: |
| 55 | raise Exception('unsupported package format') |
| 56 | |
| 57 | # Detect the OS and architecture |
| 58 | OS = {'Windows' : 'windows', 'Linux' : 'linux', 'Darwin' : 'macos'}[platform.system()] |