public
Last active

a simple script for helping do cakephp releases

  • Download Gist
cakephp_version_bump.py
Python
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
#! /usr/bin/env python
 
import os, re
from optparse import OptionParser
 
"""
Helper script for making releases
 
- Bumps version numbers
- Updates changelog urls
 
"""
 
def main():
"""
Main dispatcher for other commands.
"""
usage = 'usage %prog [options] <command> <version_number>'
parser = OptionParser(usage)
parser.add_option('-w', '--working-dir', dest="working_dir",
help="The working directory Cake is in, defaults to the CWD.", metavar="CWD",
default=os.getcwd())
(options, args) = parser.parse_args()
 
if len(args) == 0:
parser.error('A command is required!')
if len(args) == 1:
parser.error('A version number is required!')
 
functions = {
'version': version,
'changelog': changelog,
'update': update
}
command = args[0].lower()
try:
functions[command](args, options)
except KeyError:
print 'Could not find that command'
 
def update(args, options):
"""
Bump the version number in the version files
and update the changelog link
"""
version(args, options)
changelog(args, options)
 
 
def version(args, options):
"""
Update version numbers in the two files its in.
"""
new_version = args[1]
 
# Update VERSION.txt
path = os.path.join(options.working_dir, 'cake/VERSION.txt');
version_file = open(path, 'r')
contents = version_file.read()
contents = re.sub(r"""\n([0-9\.\-A-Z]+)""", "\n%s\n" % new_version, contents)
 
version_file = open(path, 'w')
version_file.write(contents)
version_file.close()
 
# Update cake/config/config.php
path = os.path.join(options.working_dir, 'cake/config/config.php');
 
version_conf = open(path, 'r')
contents = version_conf.read()
version_conf.close()
 
contents = re.sub(r"""(')([^'"]+)(';\n)""", "'%s';\n" % new_version, contents)
 
version_conf = open(path, 'w+')
version_conf.write(contents)
version_conf.close()
 
 
def changelog(args, options):
"""
Find and fix the changelog files.
"""
new_version = args[1]
 
# Fix home.ctp in libs dir.
path = os.path.join(options.working_dir, 'cake/libs/view/pages/home.ctp');
home = open(path, 'r')
contents = home.read()
home.close()
 
contents = re.sub(r"""changelogs/([^"']+)""", 'changelogs/%s' % new_version, contents)
 
home = open(path, 'w+')
home.write(contents)
home.close()
 
 
if __name__ == '__main__':
main()

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.