Added missing version utility modules
This commit is contained in:
parent
fa348b62e8
commit
67e6c93d7a
112
bin/versionbump
Executable file
112
bin/versionbump
Executable file
@ -0,0 +1,112 @@
|
||||
#!/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 <john.wood@rackspace.com> " + 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)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
118
bin/versionrelease
Executable file
118
bin/versionrelease
Executable file
@ -0,0 +1,118 @@
|
||||
#!/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.
|
||||
|
||||
"""
|
||||
Product a release version of this build (by removing the 'dev' suffix)
|
||||
"""
|
||||
|
||||
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")
|
||||
SIMPLEFILE = 'versiononly.txt'
|
||||
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 release_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]
|
||||
else:
|
||||
raise ValueError("Version is already in release format (i.e. with no 'dev' suffix)")
|
||||
subs[last_index] = last_no_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 <john.wood@rackspace.com> " + 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:
|
||||
# Create a release version and update the version.py file accordingly.
|
||||
release = release_version(version)
|
||||
print 'version: ', version
|
||||
print 'release: ', release
|
||||
update_versionfile(release)
|
||||
update_changefile(release)
|
||||
|
||||
# Output the version number to a flat file.
|
||||
with open(SIMPLEFILE, 'w') as outver:
|
||||
outver.write(release)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user