Changes between Initial Version and Version 1 of ReleaseScript


Ignore:
Timestamp:
Jun 1, 2018, 8:32:38 AM (6 years ago)
Author:
Tim Graham
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • ReleaseScript

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