Skip to content

Instantly share code, notes, and snippets.

@kostajh
Created February 23, 2012 15:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kostajh/1893300 to your computer and use it in GitHub Desktop.
Save kostajh/1893300 to your computer and use it in GitHub Desktop.
bump versions
# bump_versions.py
# A simple script to bump version numbers based on a release branch
# @author Kosta Harlan
# Usage: `python resources/bump_versions.py`
from os import remove, close
import os
import fileinput
from sys import exit
from tempfile import mkstemp
from shutil import move
# Use to replace version lines in a .info file
def replace(file, pattern, subst):
# Create temp file
fh, abs_path = mkstemp()
new_file = open(abs_path, 'w')
old_file = open(file)
for line in old_file:
new_file.write(line.replace(pattern, subst))
new_file.close()
close(fh)
old_file.close()
remove(file)
move(abs_path, file)
# Define modules and themes used in the project
modules = ['my_module', 'my_module_two', 'my_theme']
# Get the current branch info
f = open("../.git/HEAD", 'r')
git_head = f.readline()
find = git_head.rsplit('/')
git_branch = find.pop()
git_branch_string = git_branch.rstrip()
# Set the base path for the repo
base_path = os.getcwd()
print 'Bumping versions...'
# Update version number for each module
for module in modules:
file_path = base_path + "/../docroot/sites/all/modules/" + module + "/" + module + ".info"
# Custom path for the 'my_theme' theme
if module == "my_theme":
file_path = base_path + "/../docroot/sites/all/themes/" + module + "/" + module + ".info"
if os.path.exists(file_path):
f = open(file_path, 'r')
for line in f:
if line.startswith("version ="):
old_version = line.rstrip()
f.close()
replace(file_path, old_version, "version = 6.x-" + git_branch)
print "Bumped project " + module + " from " + old_version + " to version 6.x-" + git_branch_string
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment