Commit 1d317ff2cc1c549f197ec9f403d01f1f9bef2f7b
1 parent
c2c28f08
Add developer script to set version number of ctools release
Showing
1 changed file
with
211 additions
and
0 deletions
dev/set_version.py
0 → 100755
| 1 | +#! /usr/bin/env python | |
| 2 | +# ========================================================================== | |
| 3 | +# Set the version number of the software | |
| 4 | +# | |
| 5 | +# Copyright (C) 2016 Juergen Knoedlseder | |
| 6 | +# | |
| 7 | +# This program is free software: you can redistribute it and/or modify | |
| 8 | +# it under the terms of the GNU General Public License as published by | |
| 9 | +# the Free Software Foundation, either version 3 of the License, or | |
| 10 | +# (at your option) any later version. | |
| 11 | +# | |
| 12 | +# This program is distributed in the hope that it will be useful, | |
| 13 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 14 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 15 | +# GNU General Public License for more details. | |
| 16 | +# | |
| 17 | +# You should have received a copy of the GNU General Public License | |
| 18 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. | |
| 19 | +# | |
| 20 | +# ========================================================================== | |
| 21 | +import sys | |
| 22 | + | |
| 23 | + | |
| 24 | +# ========================== # | |
| 25 | +# Get current version number # | |
| 26 | +# ========================== # | |
| 27 | +def get_current(): | |
| 28 | + """ | |
| 29 | + Get current version number | |
| 30 | + | |
| 31 | + Returns | |
| 32 | + ------- | |
| 33 | + version : str | |
| 34 | + Version number | |
| 35 | + """ | |
| 36 | + # Initialse version number of empty string | |
| 37 | + version = '' | |
| 38 | + | |
| 39 | + # Open configure.ac file | |
| 40 | + f = open('configure.ac', 'r') | |
| 41 | + | |
| 42 | + # Read all lines | |
| 43 | + for line in f: | |
| 44 | + | |
| 45 | + # Search for pattern | |
| 46 | + if line.startswith('AC_INIT('): | |
| 47 | + | |
| 48 | + # Extract version number | |
| 49 | + start = line.find(',')+1 | |
| 50 | + stop = line.find(',', start) | |
| 51 | + version = line[start:stop].strip().lstrip('[').rstrip(']') | |
| 52 | + | |
| 53 | + # Close file | |
| 54 | + f.close() | |
| 55 | + | |
| 56 | + # Return version | |
| 57 | + return version | |
| 58 | + | |
| 59 | + | |
| 60 | +# ============================== # | |
| 61 | +# Set version number in one file # | |
| 62 | +# ============================== # | |
| 63 | +def set_version(filename, version, current): | |
| 64 | + """ | |
| 65 | + Set version number | |
| 66 | + | |
| 67 | + Parameters | |
| 68 | + ---------- | |
| 69 | + filename : str | |
| 70 | + File name | |
| 71 | + version : str | |
| 72 | + Version number | |
| 73 | + current : str | |
| 74 | + Current version number | |
| 75 | + """ | |
| 76 | + # Open file in read mode | |
| 77 | + f = open(filename, 'r') | |
| 78 | + | |
| 79 | + # Read file content | |
| 80 | + content = f.read() | |
| 81 | + | |
| 82 | + # Close file | |
| 83 | + f.close() | |
| 84 | + | |
| 85 | + # Replace version number | |
| 86 | + new_content = content.replace(current, version) | |
| 87 | + #print(new_content) | |
| 88 | + | |
| 89 | + # Open file in write mode | |
| 90 | + f = open(filename, 'w') | |
| 91 | + | |
| 92 | + # Write file content | |
| 93 | + f.write(new_content) | |
| 94 | + | |
| 95 | + # Close file | |
| 96 | + f.close() | |
| 97 | + | |
| 98 | + # Return | |
| 99 | + return | |
| 100 | + | |
| 101 | + | |
| 102 | +# =============================== # | |
| 103 | +# Set version number in all files # | |
| 104 | +# =============================== # | |
| 105 | +def set_versions(version, current): | |
| 106 | + """ | |
| 107 | + Set version numbers in all files | |
| 108 | + | |
| 109 | + Parameters | |
| 110 | + ---------- | |
| 111 | + version : str | |
| 112 | + Version number | |
| 113 | + current : str | |
| 114 | + Current version number | |
| 115 | + """ | |
| 116 | + # List of all relevant files, including their access paths from the | |
| 117 | + # source directory | |
| 118 | + filenames = ['configure.ac', | |
| 119 | + 'README.md', | |
| 120 | + 'sonar-project.properties', | |
| 121 | + 'doc/Doxyfile', | |
| 122 | + 'doc/source/conf.py'] | |
| 123 | + | |
| 124 | + # Set versions by loop over all files | |
| 125 | + for filename in filenames: | |
| 126 | + set_version(filename, version, current) | |
| 127 | + | |
| 128 | + # Return | |
| 129 | + return | |
| 130 | + | |
| 131 | + | |
| 132 | +# =============================================== # | |
| 133 | +# Set special version number in configure.ac file # | |
| 134 | +# =============================================== # | |
| 135 | +def set_special_configure(version, current): | |
| 136 | + """ | |
| 137 | + Set special version numbers in configure.ac file | |
| 138 | + | |
| 139 | + Parameters | |
| 140 | + ---------- | |
| 141 | + version : str | |
| 142 | + Version number | |
| 143 | + current : str | |
| 144 | + Current version number | |
| 145 | + """ | |
| 146 | + # Generate current version number | |
| 147 | + split = current.split('.') | |
| 148 | + cur = '%s:%s:%s' % (split[0], split[1], split[2]) | |
| 149 | + | |
| 150 | + # Generate new version number | |
| 151 | + split = version.split('.') | |
| 152 | + ver = '%s:%s:%s' % (split[0], split[1], split[2]) | |
| 153 | + | |
| 154 | + # Set version number | |
| 155 | + set_version('configure.ac', ver, cur) | |
| 156 | + | |
| 157 | + # Return | |
| 158 | + return | |
| 159 | + | |
| 160 | + | |
| 161 | +# ===================================================== # | |
| 162 | +# Set special version number in doc/source/conf.py file # | |
| 163 | +# ===================================================== # | |
| 164 | +def set_special_conf(version, current): | |
| 165 | + """ | |
| 166 | + Set special version numbers in doc/source/conf.py file | |
| 167 | + | |
| 168 | + Parameters | |
| 169 | + ---------- | |
| 170 | + version : str | |
| 171 | + Version number | |
| 172 | + current : str | |
| 173 | + Current version number | |
| 174 | + """ | |
| 175 | + # Generate current version number | |
| 176 | + split = current.split('.') | |
| 177 | + cur = '%s.%s' % (split[0], split[1]) | |
| 178 | + | |
| 179 | + # Generate new version number | |
| 180 | + split = version.split('.') | |
| 181 | + ver = '%s.%s' % (split[0], split[1]) | |
| 182 | + | |
| 183 | + # Set version number | |
| 184 | + set_version('doc/source/conf.py', ver, cur) | |
| 185 | + | |
| 186 | + # Return | |
| 187 | + return | |
| 188 | + | |
| 189 | + | |
| 190 | +# ======================== # | |
| 191 | +# Main routine entry point # | |
| 192 | +# ======================== # | |
| 193 | +if __name__ == '__main__': | |
| 194 | + | |
| 195 | + # Check for version number | |
| 196 | + if len(sys.argv) < 2: | |
| 197 | + sys.exit('Usage: set_version.py version') | |
| 198 | + | |
| 199 | + # Extract version number | |
| 200 | + version = sys.argv[1] | |
| 201 | + | |
| 202 | + # Get the current version | |
| 203 | + current = get_current() | |
| 204 | + | |
| 205 | + # Set versions | |
| 206 | + set_versions(version, current) | |
| 207 | + | |
| 208 | + # Set special version number: | |
| 209 | + set_special_configure(version, current) # CTOOLS_LT_VERSION="x:y:z" | |
| 210 | + set_special_conf(version, current) # version = 'x.y' | |
| 211 | + | ... | ... |