| | 1 | This Python script helps release Django. |
| | 2 | |
| | 3 | You must run `git clean -fdx` in your Django checkout first. |
| | 4 | |
| | 5 | {{{ |
| | 6 | import hashlib |
| | 7 | import os |
| | 8 | import re |
| | 9 | import subprocess |
| | 10 | from datetime import date |
| | 11 | from io import StringIO |
| | 12 | |
| | 13 | PGP_KEY_ID = '1E8ABDC773EDE252' # replace with your PGP key |
| | 14 | PATH_TO_DJANGO = '/media/evo/release-django/' # replace |
| | 15 | CHECKSUM_DEST_DIR = '/home/tim/Desktop/' # replace |
| | 16 | |
| | 17 | checksum_file_text = \ |
| | 18 | """This file contains MD5, SHA1, and SHA256 checksums for the source-code |
| | 19 | tarball and wheel files of Django {django_version}, released {release_date}. |
| | 20 | |
| | 21 | To use this file, you will need a working install of PGP or other |
| | 22 | compatible public-key encryption software. You will also need to have |
| | 23 | the Django release manager's public key in your keyring; this key has |
| | 24 | the ID ``{pgp_key_id}`` and can be imported from the MIT |
| | 25 | keyserver. For example, if using the open-source GNU Privacy Guard |
| | 26 | implementation of PGP: |
| | 27 | |
| | 28 | gpg --keyserver pgp.mit.edu --recv-key {pgp_key_id} |
| | 29 | |
| | 30 | Once the key is imported, verify this file:: |
| | 31 | |
| | 32 | gpg --verify <<THIS FILENAME>> |
| | 33 | |
| | 34 | Once you have verified this file, you can use normal MD5, SHA1, or SHA256 |
| | 35 | checksumming applications to generate the checksums of the Django |
| | 36 | package and compare them to the checksums listed below. |
| | 37 | |
| | 38 | Release packages: |
| | 39 | ================= |
| | 40 | |
| | 41 | """ |
| | 42 | |
| | 43 | dist_path = os.path.join(PATH_TO_DJANGO, 'dist/') |
| | 44 | |
| | 45 | ## Build release files. |
| | 46 | subprocess.call(["make", "-f", os.path.join(PATH_TO_DJANGO, 'extras/Makefile')]) |
| | 47 | release_files = os.listdir(dist_path) |
| | 48 | for f in release_files: |
| | 49 | if f.endswith('.whl'): |
| | 50 | wheel_name = f |
| | 51 | break |
| | 52 | |
| | 53 | assert wheel_name.endswith('.whl') |
| | 54 | django_version = wheel_name.split('-')[1] |
| | 55 | django_major_version = '.'.join(django_version.split('.')[:2]) |
| | 56 | # Chop alpha/beta/rc suffix |
| | 57 | match = re.search("[abrc]", django_major_version) |
| | 58 | if match: |
| | 59 | django_major_version = django_major_version[:match.start()] |
| | 60 | |
| | 61 | checksum_file_text = checksum_file_text.format( |
| | 62 | release_date = date.today().strftime('%B %-d, %Y'), |
| | 63 | pgp_key_id = PGP_KEY_ID, |
| | 64 | django_version=django_version, |
| | 65 | ) |
| | 66 | |
| | 67 | for release_file in release_files: |
| | 68 | checksum_file_text += 'https://www.djangoproject.com/m/releases/' + django_major_version + '/' + release_file + '\n' |
| | 69 | |
| | 70 | |
| | 71 | checksums = ( |
| | 72 | ('MD5', hashlib.md5), |
| | 73 | ('SHA1', hashlib.sha1), |
| | 74 | ('SHA256', hashlib.sha256), |
| | 75 | ) |
| | 76 | |
| | 77 | for checksum_name, checksum_algo in checksums: |
| | 78 | checksum_file_text += "\n%s checksums\n" % checksum_name |
| | 79 | checksum_file_text += "=" * len(checksum_name) + "==========\n\n" |
| | 80 | |
| | 81 | for release_file in release_files: |
| | 82 | checksum = checksum_algo(open(os.path.join(dist_path, release_file) ,'rb').read()).hexdigest() |
| | 83 | checksum_file_text += checksum + " " + release_file + "\n" |
| | 84 | |
| | 85 | # Create the checksum file |
| | 86 | checksum_file_name = 'Django-%s.checksum.txt' % django_version |
| | 87 | checksum_file_path = os.path.join(CHECKSUM_DEST_DIR, checksum_file_name) |
| | 88 | with open(checksum_file_path,'wb') as f: |
| | 89 | f.write(checksum_file_text.encode('ascii')) |
| | 90 | |
| | 91 | print() |
| | 92 | print('Commands to run:') |
| | 93 | |
| | 94 | # Sign the checkusm file |
| | 95 | print('gpg --clearsign --digest-algo SHA256 %s' % checksum_file_path) |
| | 96 | |
| | 97 | # Upload the checksum file |
| | 98 | print('scp {filepath}.asc root@djangoproject.com:/home/www/www/media/pgp/{filename}'.format(filepath=checksum_file_path, filename=checksum_file_name)) |
| | 99 | |
| | 100 | # Upload release files to the djangoproject server. |
| | 101 | print('scp dist/Django-* root@djangoproject.com:/home/www/www/media/releases/%s' % django_major_version) |
| | 102 | |
| | 103 | print('git tag --sign --message="Tag {release}" {release}'.format(release=django_version)) |
| | 104 | print('twine upload -s dist/*') |
| | 105 | }}} |