#!/usr/bin/env python # vim: tabstop=4 shiftwidth=4 softtabstop=4 # Copyright 2010 United States Government as represented by the # Administrator of the National Aeronautics and Space Administration. # Copyright 2011 OpenStack LLC. # All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. """ Advance the version of this build """ import os import sys from time import strftime # Determine version of this application. PKG = "barbican" VERSIONFILE = os.path.join(PKG, "version.py") CHANGEFILE = os.path.join("debian", "changelog") current_dir = os.getcwd() if current_dir.endswith('bin'): VERSIONFILE = os.path.join("..", PKG, "version.py") CHANGEFILE = os.path.joih("..", "debian", "changelog") def get_version(): version = "unknown" try: version_file = open(VERSIONFILE, "r") for line in version_file: if line.startswith('__version__'): version = line.split("'")[1] break except EnvironmentError: pass # Okay, there is no version file. return version def bump_version(version): subs = version.split(".") last_index = len(subs) - 1 last_no_dev = subs[last_index] if 'dev' in last_no_dev: last_no_dev = last_no_dev[:-3] last_bumped = int(last_no_dev) + 1 subs[last_index] = str(last_bumped) + 'dev' return '.'.join(subs) def update_versionfile(version): temp_name = VERSIONFILE + "~" file_new = open(temp_name, 'w') try: with open(VERSIONFILE, 'r') as file_old: for line in file_old: if line.startswith('__version__'): subs = line.split("'") subs[1] = version file_new.write("'".join(subs)) else: file_new.write(line) finally: file_new.close() os.rename(temp_name, VERSIONFILE) def update_changefile(version): temp_name = CHANGEFILE + "~" file_new = open(temp_name, 'w') try: with open(CHANGEFILE, 'r') as file_old: for line in file_old: if line.startswith(PKG): new_version_line = PKG + " (" + version + "-1) stable; urgency=high\n" file_new.write(new_version_line) elif 'john.wood' in line: now_text = strftime("%a, %d %b %Y %H:%M:%S %z") new_commiter_line = " -- John Wood " + now_text + "\n" file_new.write(new_commiter_line) else: file_new.write(line) finally: file_new.close() os.rename(temp_name, CHANGEFILE) if __name__ == '__main__': version = get_version() if version: next = bump_version(version) print 'version: ', version print 'next ver: ', next update_versionfile(next) update_changefile(next)