| 1 |
#!/usr/bin/env python |
| 2 |
# |
| 3 |
# Copyright 2014 Calum Lind <[email protected]> |
| 4 |
# |
| 5 |
# This file is part of Deluge and is licensed under GNU General Public License 3.0, or later, with |
| 6 |
# the additional special exception to link portions of this program with the OpenSSL library. |
| 7 |
# See LICENSE for more details. |
| 8 |
# |
| 9 |
import os.path |
| 10 |
from hashlib import sha256 |
| 11 |
from subprocess import call, check_output |
| 12 |
|
| 13 |
sdist_formats = 'xztar' |
| 14 |
|
| 15 |
version = check_output(['python', 'version.py']).strip().decode() |
| 16 |
|
| 17 |
# Create release archive |
| 18 |
release_dir = 'dist/release-%s' % version |
| 19 |
print('Creating release archive for ' + version) |
| 20 |
|
| 21 |
call( |
| 22 |
'python setup.py --quiet egg_info --egg-base /tmp sdist --formats=%s --dist-dir=%s' |
| 23 |
% (sdist_formats, release_dir), |
| 24 |
shell=True, |
| 25 |
) |
| 26 |
|
| 27 |
|
| 28 |
if sdist_formats == 'xztar': |
| 29 |
tarxz_path = os.path.join(release_dir, 'deluge-%s.tar.xz' % version) |
| 30 |
else: |
| 31 |
# Compress release archive with xz |
| 32 |
tar_path = os.path.join(release_dir, 'deluge-%s.tar' % version) |
| 33 |
tarxz_path = tar_path + '.xz' |
| 34 |
print('Compressing tar (%s) with xz' % tar_path) |
| 35 |
try: |
| 36 |
from backports import lzma |
| 37 |
except ImportError: |
| 38 |
print('backports.lzma not installed, falling back to xz shell command') |
| 39 |
call(['xz', '-e9zkf', tar_path]) |
| 40 |
else: |
| 41 |
with open(tar_path, 'rb') as tar_file, open(tarxz_path, 'wb') as xz_file: |
| 42 |
xz_file.write( |
| 43 |
lzma.compress(bytes(tar_file.read()), preset=9 | lzma.PRESET_EXTREME) |
| 44 |
) |
| 45 |
|
| 46 |
# Calculate shasum and add to sha256sums.txt |
| 47 |
with open(tarxz_path, 'rb') as _file: |
| 48 |
sha256sum = '{} {}'.format( |
| 49 |
sha256(_file.read()).hexdigest(), |
| 50 |
os.path.basename(tarxz_path), |
| 51 |
) |
| 52 |
with open(os.path.join(release_dir, 'sha256sums.txt'), 'w') as _file: |
| 53 |
_file.write(sha256sum + '\n') |
| 54 |
|
| 55 |
print('Complete: %s' % release_dir) |