Skip to content

Instantly share code, notes, and snippets.

@markstory
Created January 30, 2010 02:48
Show Gist options
  • Save markstory/290371 to your computer and use it in GitHub Desktop.
Save markstory/290371 to your computer and use it in GitHub Desktop.
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",
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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment