Skip to content
Create a gist now

Instantly share code, notes, and snippets.

a simple script for helping do cakephp releases
#! /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",
(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()
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 =
contents = re.sub(r"""\n([0-9\.\-A-Z]+)""", "\n%s\n" % new_version, contents)
version_file = open(path, 'w')
# Update cake/config/config.php
path = os.path.join(options.working_dir, 'cake/config/config.php');
version_conf = open(path, 'r')
contents =
contents = re.sub(r"""(')([^'"]+)(';\n)""", "'%s';\n" % new_version, contents)
version_conf = open(path, 'w+')
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 =
contents = re.sub(r"""changelogs/([^"']+)""", 'changelogs/%s' % new_version, contents)
home = open(path, 'w+')
if __name__ == '__main__':
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.