Commit aeaaea034e8ef18bae002c4e317f91d2b751814c
1 parent
cc01022c
Add ctools release manager
Showing
2 changed files
with
722 additions
and
302 deletions
dev/release.py
0 → 100755
| 1 | +#! /usr/bin/env python | ||
| 2 | +# ========================================================================== | ||
| 3 | +# ctools release manager | ||
| 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 os | ||
| 22 | +import sys | ||
| 23 | +import commands | ||
| 24 | + | ||
| 25 | + | ||
| 26 | +# ================= # | ||
| 27 | +# Confirm something # | ||
| 28 | +# ================= # | ||
| 29 | +def confirm(text): | ||
| 30 | + """ | ||
| 31 | + Confirm something | ||
| 32 | + | ||
| 33 | + Parameters | ||
| 34 | + ---------- | ||
| 35 | + text : str | ||
| 36 | + Thing to confirm | ||
| 37 | + | ||
| 38 | + Returns | ||
| 39 | + ------- | ||
| 40 | + flag : bool | ||
| 41 | + True if something is confirmed | ||
| 42 | + """ | ||
| 43 | + # Confirmation loop | ||
| 44 | + waiting = True | ||
| 45 | + while waiting: | ||
| 46 | + confirmation = str(raw_input(text+' (y/n): ')) | ||
| 47 | + if confirmation == 'q': | ||
| 48 | + sys.exit() | ||
| 49 | + elif confirmation == 'y': | ||
| 50 | + flag = True | ||
| 51 | + waiting = False | ||
| 52 | + elif confirmation == 'n': | ||
| 53 | + flag = False | ||
| 54 | + waiting = False | ||
| 55 | + | ||
| 56 | + # Return confirmation flag | ||
| 57 | + return flag | ||
| 58 | + | ||
| 59 | + | ||
| 60 | +# ============== # | ||
| 61 | +# Commit changes # | ||
| 62 | +# ============== # | ||
| 63 | +def commit(message): | ||
| 64 | + """ | ||
| 65 | + Commit changes into git repo | ||
| 66 | + | ||
| 67 | + Parameters | ||
| 68 | + ---------- | ||
| 69 | + message : str | ||
| 70 | + Commit message | ||
| 71 | + """ | ||
| 72 | + # Show changes | ||
| 73 | + print("The following files have been changed:") | ||
| 74 | + os.system('git status -s') | ||
| 75 | + | ||
| 76 | + # Ask again whether the changes should be committed | ||
| 77 | + if confirm("Commit all changes?"): | ||
| 78 | + | ||
| 79 | + # Optionally enter a commit message | ||
| 80 | + if len(message) == 0: | ||
| 81 | + message = str(raw_input("Please enter a commit message: ")) | ||
| 82 | + | ||
| 83 | + # Stage all files | ||
| 84 | + os.system('git add -u') | ||
| 85 | + | ||
| 86 | + # Commit all changes | ||
| 87 | + os.system('git commit -m "%s"' % message) | ||
| 88 | + | ||
| 89 | + # Return | ||
| 90 | + return | ||
| 91 | + | ||
| 92 | + | ||
| 93 | +# ========================== # | ||
| 94 | +# Check if git branch exists # | ||
| 95 | +# ========================== # | ||
| 96 | +def git_branch_exists(branch): | ||
| 97 | + """ | ||
| 98 | + Check if git branch exists | ||
| 99 | + | ||
| 100 | + Parameters | ||
| 101 | + ---------- | ||
| 102 | + branch : str | ||
| 103 | + Branch name | ||
| 104 | + | ||
| 105 | + Returns | ||
| 106 | + ------- | ||
| 107 | + exists : bool | ||
| 108 | + True if git branch exists | ||
| 109 | + """ | ||
| 110 | + # Check if git branch exists | ||
| 111 | + rc = os.system('git rev-parse --verify %s >/dev/null 2>&1' % branch) | ||
| 112 | + | ||
| 113 | + # Set exists flag | ||
| 114 | + if rc == 0: | ||
| 115 | + exists = True | ||
| 116 | + else: | ||
| 117 | + exists = False | ||
| 118 | + | ||
| 119 | + # Return flag | ||
| 120 | + return exists | ||
| 121 | + | ||
| 122 | + | ||
| 123 | +# ================= # | ||
| 124 | +# Create git branch # | ||
| 125 | +# ================= # | ||
| 126 | +def create_git_branch(branch): | ||
| 127 | + """ | ||
| 128 | + Create a git branch | ||
| 129 | + | ||
| 130 | + Parameters | ||
| 131 | + ---------- | ||
| 132 | + branch : str | ||
| 133 | + Branch name | ||
| 134 | + """ | ||
| 135 | + # If branch exists already then ask whether it should be deleted | ||
| 136 | + if git_branch_exists(branch): | ||
| 137 | + if confirm("Git branch '%s' exists already, do you want to delete " | ||
| 138 | + "it?" % branch): | ||
| 139 | + os.system('git branch -D %s' % branch) | ||
| 140 | + | ||
| 141 | + # If branch exists already then switch to the new branch, otherwise create | ||
| 142 | + # new branch and switch to it | ||
| 143 | + if git_branch_exists(branch): | ||
| 144 | + os.system('git checkout %s' % branch) | ||
| 145 | + else: | ||
| 146 | + print("Created new branch '%s'" % branch) | ||
| 147 | + os.system('git checkout -b %s' % branch) | ||
| 148 | + | ||
| 149 | + # Return | ||
| 150 | + return | ||
| 151 | + | ||
| 152 | + | ||
| 153 | +# ======================================= # | ||
| 154 | +# Check whether version string is correct # | ||
| 155 | +# ======================================= # | ||
| 156 | +def check_version(version): | ||
| 157 | + """ | ||
| 158 | + Check whether version string is correct | ||
| 159 | + | ||
| 160 | + Parameters | ||
| 161 | + ---------- | ||
| 162 | + version : str | ||
| 163 | + Version number | ||
| 164 | + | ||
| 165 | + Returns | ||
| 166 | + ------- | ||
| 167 | + check : bool | ||
| 168 | + True if version string is correct | ||
| 169 | + """ | ||
| 170 | + # Initialise check with False | ||
| 171 | + check = False | ||
| 172 | + | ||
| 173 | + # Split version string | ||
| 174 | + split = version.split('.') | ||
| 175 | + | ||
| 176 | + # If there are three elements or four elements we may have a valid version | ||
| 177 | + # string | ||
| 178 | + if len(split) == 3 or len(split) == 4: | ||
| 179 | + | ||
| 180 | + # If the three first elements are integers we may have a valid version | ||
| 181 | + # string | ||
| 182 | + if split[0].isdigit() and split[1].isdigit() and split[2].isdigit(): | ||
| 183 | + | ||
| 184 | + # If we have three elements the version is valid and we are done | ||
| 185 | + if len(split) == 3: | ||
| 186 | + check = True | ||
| 187 | + | ||
| 188 | + # Otherwise check if the 4th element is of format devn, where n | ||
| 189 | + # is an integer number | ||
| 190 | + elif split[3][0:3] == 'dev': | ||
| 191 | + if split[3][3:].isdigit(): | ||
| 192 | + check = True | ||
| 193 | + | ||
| 194 | + # Return check | ||
| 195 | + return check | ||
| 196 | + | ||
| 197 | + | ||
| 198 | +# ========================== # | ||
| 199 | +# Get current version number # | ||
| 200 | +# ========================== # | ||
| 201 | +def get_current_version(): | ||
| 202 | + """ | ||
| 203 | + Get current version number | ||
| 204 | + | ||
| 205 | + Returns | ||
| 206 | + ------- | ||
| 207 | + version : str | ||
| 208 | + Version number | ||
| 209 | + """ | ||
| 210 | + # Initialse version number of empty string | ||
| 211 | + version = '' | ||
| 212 | + | ||
| 213 | + # Open configure.ac file | ||
| 214 | + f = open('configure.ac', 'r') | ||
| 215 | + | ||
| 216 | + # Read all lines | ||
| 217 | + for line in f: | ||
| 218 | + | ||
| 219 | + # Search for pattern | ||
| 220 | + if line.startswith('AC_INIT('): | ||
| 221 | + | ||
| 222 | + # Extract version number | ||
| 223 | + start = line.find(',')+1 | ||
| 224 | + stop = line.find(',', start) | ||
| 225 | + version = line[start:stop].strip().lstrip('[').rstrip(']') | ||
| 226 | + | ||
| 227 | + # Close file | ||
| 228 | + f.close() | ||
| 229 | + | ||
| 230 | + # Return version | ||
| 231 | + return version | ||
| 232 | + | ||
| 233 | + | ||
| 234 | +# ========================== # | ||
| 235 | +# Get libtool version number # | ||
| 236 | +# ========================== # | ||
| 237 | +def get_libtool_version(): | ||
| 238 | + """ | ||
| 239 | + Get libtools version number | ||
| 240 | + | ||
| 241 | + Returns | ||
| 242 | + ------- | ||
| 243 | + version : str | ||
| 244 | + Version number | ||
| 245 | + """ | ||
| 246 | + # Initialse version number of empty string | ||
| 247 | + version = '' | ||
| 248 | + | ||
| 249 | + # Open configure.ac file | ||
| 250 | + f = open('configure.ac', 'r') | ||
| 251 | + | ||
| 252 | + # Read all lines | ||
| 253 | + for line in f: | ||
| 254 | + | ||
| 255 | + # Search for pattern | ||
| 256 | + if line.startswith('CTOOLS_LT_VERSION='): | ||
| 257 | + | ||
| 258 | + # Extract version number | ||
| 259 | + start = line.find('"')+1 | ||
| 260 | + stop = line.find('"', start) | ||
| 261 | + version = line[start:stop].strip() | ||
| 262 | + | ||
| 263 | + # Close file | ||
| 264 | + f.close() | ||
| 265 | + | ||
| 266 | + # Return version | ||
| 267 | + return version | ||
| 268 | + | ||
| 269 | + | ||
| 270 | +# =============================================== # | ||
| 271 | +# Set libtool version number in configure.ac file # | ||
| 272 | +# =============================================== # | ||
| 273 | +def set_libtool_version(library=False, added=False, removed=False, changed=False): | ||
| 274 | + """ | ||
| 275 | + Set special version numbers in configure.ac file | ||
| 276 | + | ||
| 277 | + Parameters | ||
| 278 | + ---------- | ||
| 279 | + library : bool, optional | ||
| 280 | + Library source code changed | ||
| 281 | + added : bool, optional | ||
| 282 | + Interfaces added | ||
| 283 | + removed : bool, optional | ||
| 284 | + Interfaces removed | ||
| 285 | + changed : bool, optional | ||
| 286 | + Interfaces changed | ||
| 287 | + """ | ||
| 288 | + # Get libtool version number | ||
| 289 | + old = get_libtool_version() | ||
| 290 | + split = old.split(':') | ||
| 291 | + | ||
| 292 | + # Decompose libtool version number | ||
| 293 | + current = int(split[0]) | ||
| 294 | + revision = int(split[1]) | ||
| 295 | + age = int(split[2]) | ||
| 296 | + | ||
| 297 | + # If the library source code has changed at all since the last update, then | ||
| 298 | + # increment revision | ||
| 299 | + if library: | ||
| 300 | + revision += 1 | ||
| 301 | + | ||
| 302 | + # If any interfaces have been added, removed, or changed since the last | ||
| 303 | + # update, increment current, and set revision to 0 | ||
| 304 | + if added or removed or changed: | ||
| 305 | + current += 1 | ||
| 306 | + revision = 0 | ||
| 307 | + | ||
| 308 | + # If any interfaces have been added since the last public release, then | ||
| 309 | + # increment age | ||
| 310 | + if added: | ||
| 311 | + age += 1 | ||
| 312 | + | ||
| 313 | + # If any interfaces have been removed or changed since the last public | ||
| 314 | + # release, then set age to 0 | ||
| 315 | + if removed or changed: | ||
| 316 | + age = 0 | ||
| 317 | + | ||
| 318 | + # Build new libtool version number | ||
| 319 | + version = '%d:%d:%d' % (current, revision, age) | ||
| 320 | + | ||
| 321 | + # Set libtool version number | ||
| 322 | + set_version_in_file('configure.ac', version, old) | ||
| 323 | + | ||
| 324 | + # Return | ||
| 325 | + return | ||
| 326 | + | ||
| 327 | + | ||
| 328 | +# ============================== # | ||
| 329 | +# Set version number in one file # | ||
| 330 | +# ============================== # | ||
| 331 | +def set_version_in_file(filename, version, current): | ||
| 332 | + """ | ||
| 333 | + Set version number in one file | ||
| 334 | + | ||
| 335 | + The function replaces all current version numbers in a file by a new | ||
| 336 | + version number. | ||
| 337 | + | ||
| 338 | + Parameters | ||
| 339 | + ---------- | ||
| 340 | + filename : str | ||
| 341 | + File name | ||
| 342 | + version : str | ||
| 343 | + New version number | ||
| 344 | + current : str | ||
| 345 | + Current version number | ||
| 346 | + """ | ||
| 347 | + # Open file in read mode | ||
| 348 | + f = open(filename, 'r') | ||
| 349 | + | ||
| 350 | + # Read file content | ||
| 351 | + content = f.read() | ||
| 352 | + | ||
| 353 | + # Close file | ||
| 354 | + f.close() | ||
| 355 | + | ||
| 356 | + # Replace version number | ||
| 357 | + new_content = content.replace(current, version) | ||
| 358 | + | ||
| 359 | + # Open file in write mode | ||
| 360 | + f = open(filename, 'w') | ||
| 361 | + | ||
| 362 | + # Write file content | ||
| 363 | + f.write(new_content) | ||
| 364 | + | ||
| 365 | + # Close file | ||
| 366 | + f.close() | ||
| 367 | + | ||
| 368 | + # Return | ||
| 369 | + return | ||
| 370 | + | ||
| 371 | + | ||
| 372 | +# ======================= # | ||
| 373 | +# Set the package version # | ||
| 374 | +# ======================= # | ||
| 375 | +def set_package_version(version): | ||
| 376 | + """ | ||
| 377 | + Set the package version | ||
| 378 | + | ||
| 379 | + Parameters | ||
| 380 | + ---------- | ||
| 381 | + version : str | ||
| 382 | + Version number | ||
| 383 | + """ | ||
| 384 | + # List of all files in which the version numbers should be changed. The | ||
| 385 | + # file name should include their access paths with respect to the source | ||
| 386 | + # directory | ||
| 387 | + filenames = ['configure.ac', | ||
| 388 | + 'ctools.pc.in', | ||
| 389 | + 'README.md', | ||
| 390 | + 'sonar-project.properties', | ||
| 391 | + 'doc/Doxyfile', | ||
| 392 | + 'doc/source/conf.py'] | ||
| 393 | + | ||
| 394 | + | ||
| 395 | + # Get the current package version | ||
| 396 | + current = get_current_version() | ||
| 397 | + | ||
| 398 | + # Set versions by loop over all files | ||
| 399 | + for filename in filenames: | ||
| 400 | + set_version_in_file(filename, version, current) | ||
| 401 | + | ||
| 402 | + # Generate current version number | ||
| 403 | + split = current.split('.') | ||
| 404 | + cur = '%s.%s' % (split[0], split[1]) | ||
| 405 | + | ||
| 406 | + # Generate new version number | ||
| 407 | + split = version.split('.') | ||
| 408 | + ver = '%s.%s' % (split[0], split[1]) | ||
| 409 | + | ||
| 410 | + # Set version number in doc/source/conf.py file | ||
| 411 | + set_version_in_file('doc/source/conf.py', ver, cur) | ||
| 412 | + | ||
| 413 | + # Return | ||
| 414 | + return | ||
| 415 | + | ||
| 416 | + | ||
| 417 | +# ============= # | ||
| 418 | +# Build tarball # | ||
| 419 | +# ============= # | ||
| 420 | +def build_tarball(): | ||
| 421 | + """ | ||
| 422 | + Build tarball using 'make dist' | ||
| 423 | + """ | ||
| 424 | + # Set base path | ||
| 425 | + base_path = os.getcwd() | ||
| 426 | + | ||
| 427 | + # Enable/disable logging | ||
| 428 | + if confirm("Log actions in logfile?"): | ||
| 429 | + verbosity = ' >> %s/make_dist.log 2>&1' % (base_path) | ||
| 430 | + os.system('rm -rf make_dist.log >/dev/null 2>&1') | ||
| 431 | + else: | ||
| 432 | + verbosity = ' >/dev/null 2>&1' | ||
| 433 | + | ||
| 434 | + # Configure package | ||
| 435 | + print("Configure package") | ||
| 436 | + rc = os.system('./configure%s' % verbosity) | ||
| 437 | + if rc == 0: | ||
| 438 | + print("Package configuration successful") | ||
| 439 | + else: | ||
| 440 | + print("*** Failure in package configuration") | ||
| 441 | + | ||
| 442 | + # Check package | ||
| 443 | + print("Create tarball") | ||
| 444 | + rc = os.system('make dist%s' % verbosity) | ||
| 445 | + if rc == 0: | ||
| 446 | + print("Tarball creation successful") | ||
| 447 | + else: | ||
| 448 | + print("*** Failure in creation of tarball") | ||
| 449 | + | ||
| 450 | + # Return | ||
| 451 | + return | ||
| 452 | + | ||
| 453 | + | ||
| 454 | +# ============= # | ||
| 455 | +# Check tarball # | ||
| 456 | +# ============= # | ||
| 457 | +def check_tarball(): | ||
| 458 | + """ | ||
| 459 | + Check tarball using 'make distcheck' | ||
| 460 | + | ||
| 461 | + Parameters | ||
| 462 | + ---------- | ||
| 463 | + filename : str | ||
| 464 | + Tarball file name | ||
| 465 | + """ | ||
| 466 | + # Set base path | ||
| 467 | + base_path = os.getcwd() | ||
| 468 | + | ||
| 469 | + # Enable/disable logging | ||
| 470 | + if confirm("Log check in logfile?"): | ||
| 471 | + verbosity = ' >> %s/make_distcheck.log 2>&1' % (base_path) | ||
| 472 | + os.system('rm -rf make_distcheck.log >/dev/null 2>&1') | ||
| 473 | + else: | ||
| 474 | + verbosity = ' >/dev/null 2>&1' | ||
| 475 | + | ||
| 476 | + # Configure package | ||
| 477 | + print("Configure package") | ||
| 478 | + rc = os.system('./configure%s' % verbosity) | ||
| 479 | + if rc == 0: | ||
| 480 | + print("Package configuration successful") | ||
| 481 | + else: | ||
| 482 | + print("*** Failure in package configuration") | ||
| 483 | + | ||
| 484 | + # Check tarball | ||
| 485 | + print("Check tarball") | ||
| 486 | + rc = os.system('make distcheck%s' % verbosity) | ||
| 487 | + if rc == 0: | ||
| 488 | + print("Tarball checking successful") | ||
| 489 | + else: | ||
| 490 | + print("*** Failure in checking of tarball") | ||
| 491 | + | ||
| 492 | + # Return | ||
| 493 | + return | ||
| 494 | + | ||
| 495 | + | ||
| 496 | +# ================ # | ||
| 497 | +# Manage main menu # | ||
| 498 | +# ================ # | ||
| 499 | +def main_menu(): | ||
| 500 | + """ | ||
| 501 | + Manage main menu | ||
| 502 | + """ | ||
| 503 | + # Print main menu | ||
| 504 | + print('[1] Make a new release') | ||
| 505 | + print('[2] Set the package version in current branch') | ||
| 506 | + print('[3] Set the libtool version in current branch') | ||
| 507 | + print('[4] Commit changes in current branch') | ||
| 508 | + print('[5] Create tarball from current branch') | ||
| 509 | + print('[6] Check tarball') | ||
| 510 | + print('[q] Quit') | ||
| 511 | + | ||
| 512 | + # Wait for the input | ||
| 513 | + waiting = True | ||
| 514 | + while waiting: | ||
| 515 | + choice = str(raw_input('Enter your choice: ')) | ||
| 516 | + if choice == '1' or choice == '2' or choice == '3' or choice == '4' or \ | ||
| 517 | + choice == '5' or choice == '6' or choice == 'q': | ||
| 518 | + waiting = False | ||
| 519 | + | ||
| 520 | + # Return choice | ||
| 521 | + return choice | ||
| 522 | + | ||
| 523 | + | ||
| 524 | +# ====================== # | ||
| 525 | +# Manage package release # | ||
| 526 | +# ====================== # | ||
| 527 | +def release_menu(branch='release'): | ||
| 528 | + """ | ||
| 529 | + Manage package release | ||
| 530 | + | ||
| 531 | + Parameters | ||
| 532 | + ---------- | ||
| 533 | + branch : str, optional | ||
| 534 | + Release branch name | ||
| 535 | + """ | ||
| 536 | + # Annonce actions | ||
| 537 | + print("") | ||
| 538 | + print("Make a new release") | ||
| 539 | + print("------------------") | ||
| 540 | + | ||
| 541 | + # Step 1: Create a release branch | ||
| 542 | + if confirm("Step 1: Do you want to create a '%s' branch?" % branch): | ||
| 543 | + create_git_branch(branch) | ||
| 544 | + else: | ||
| 545 | + if git_branch_exists(branch): | ||
| 546 | + os.system('git checkout %s' % branch) | ||
| 547 | + else: | ||
| 548 | + requested = branch | ||
| 549 | + branch = commands.getoutput('git rev-parse --abbrev-ref HEAD') | ||
| 550 | + print("WARNING: No '%s' branch found, continue working on " | ||
| 551 | + "current branch '%s'" % (requested, branch)) | ||
| 552 | + | ||
| 553 | + # Get current package version | ||
| 554 | + current = get_current_version() | ||
| 555 | + | ||
| 556 | + # Step 2: Set package version | ||
| 557 | + print("") | ||
| 558 | + if confirm("Step 2: Current ctools version is '%s'. Do you want to " | ||
| 559 | + "change the package version?" % current): | ||
| 560 | + package_version_menu() | ||
| 561 | + | ||
| 562 | + # Get current libtool version | ||
| 563 | + current = get_libtool_version() | ||
| 564 | + | ||
| 565 | + # Step 3: Set libtool version | ||
| 566 | + print("") | ||
| 567 | + if confirm("Step 3: Current Libtool version is '%s'. Do you want to " | ||
| 568 | + "change the libtool version?" % current): | ||
| 569 | + libtool_version_menu() | ||
| 570 | + | ||
| 571 | + # Step 4: Commit changes | ||
| 572 | + print("") | ||
| 573 | + if confirm("Step 4: Commit changes?"): | ||
| 574 | + package = get_current_version() | ||
| 575 | + libtool = get_libtool_version() | ||
| 576 | + message = "ctools package version set to '%s' and libtool version "\ | ||
| 577 | + "set to '%s'" % (package, libtool) | ||
| 578 | + commit(message) | ||
| 579 | + | ||
| 580 | + # Step 5: Push branch into git | ||
| 581 | + print("") | ||
| 582 | + if confirm("Step 5: Push changes?"): | ||
| 583 | + os.system('git push origin %s' % branch) | ||
| 584 | + | ||
| 585 | + # Step 6: Build tarball | ||
| 586 | + print("") | ||
| 587 | + if confirm("Step 6: Build tarball?"): | ||
| 588 | + build_tarball() | ||
| 589 | + | ||
| 590 | + # Step 7: Check tarball | ||
| 591 | + print("") | ||
| 592 | + if confirm("Step 7: Check tarball?"): | ||
| 593 | + check_tarball() | ||
| 594 | + | ||
| 595 | + # Print separator | ||
| 596 | + print("") | ||
| 597 | + | ||
| 598 | + # Return | ||
| 599 | + return | ||
| 600 | + | ||
| 601 | + | ||
| 602 | +# ============================== # | ||
| 603 | +# Manage package version setting # | ||
| 604 | +# ============================== # | ||
| 605 | +def package_version_menu(): | ||
| 606 | + """ | ||
| 607 | + Manage package version setting | ||
| 608 | + """ | ||
| 609 | + # Get the current package version | ||
| 610 | + current = get_current_version() | ||
| 611 | + | ||
| 612 | + # Looping until the version change is accepted | ||
| 613 | + looping = True | ||
| 614 | + while looping: | ||
| 615 | + | ||
| 616 | + # Get package version from input | ||
| 617 | + waiting = True | ||
| 618 | + while waiting: | ||
| 619 | + version = str(raw_input("Current ctools version is '%s'. Please " | ||
| 620 | + "enter new ctools version: " % current)) | ||
| 621 | + if version == "q": | ||
| 622 | + sys.exit() | ||
| 623 | + if check_version(version) == False: | ||
| 624 | + print("*** Invalid ctools version. " | ||
| 625 | + "Please enter the version in the format x.y.z[.devn]") | ||
| 626 | + else: | ||
| 627 | + waiting = False | ||
| 628 | + | ||
| 629 | + # If the version number change is confirmed then do the change | ||
| 630 | + if confirm("Change version to '%s'?" % version): | ||
| 631 | + | ||
| 632 | + # Set package version | ||
| 633 | + set_package_version(version) | ||
| 634 | + | ||
| 635 | + # Get new package and libtool versions | ||
| 636 | + version = get_current_version() | ||
| 637 | + | ||
| 638 | + # Inform about version change | ||
| 639 | + print("ctools version changed to '%s'" % (version)) | ||
| 640 | + | ||
| 641 | + # Signal that we can exit looping | ||
| 642 | + looping = False | ||
| 643 | + | ||
| 644 | + # Return | ||
| 645 | + return | ||
| 646 | + | ||
| 647 | + | ||
| 648 | +# ============================== # | ||
| 649 | +# Manage libtool version setting # | ||
| 650 | +# ============================== # | ||
| 651 | +def libtool_version_menu(): | ||
| 652 | + """ | ||
| 653 | + Manage libtool version setting | ||
| 654 | + """ | ||
| 655 | + # Get current libtool version | ||
| 656 | + current = get_libtool_version() | ||
| 657 | + | ||
| 658 | + # Continue only if libtool version should be changed | ||
| 659 | + if confirm("Current libtool version is '%s'. Do you want to change the " | ||
| 660 | + "version?" % current): | ||
| 661 | + | ||
| 662 | + # Determine package changes | ||
| 663 | + library = confirm(" Has the source code changed since last release?") | ||
| 664 | + added = confirm(" Have interfaces been added since last release?") | ||
| 665 | + removed = confirm(" Have interfaces been removed since last release?") | ||
| 666 | + changed = confirm(" Have interfaces changed since last release?") | ||
| 667 | + | ||
| 668 | + # Set libtool version | ||
| 669 | + set_libtool_version(library=library, added=added, removed=removed, | ||
| 670 | + changed=changed) | ||
| 671 | + | ||
| 672 | + # Get new libtool version | ||
| 673 | + version = get_libtool_version() | ||
| 674 | + | ||
| 675 | + # Print new libtool version | ||
| 676 | + print("Libtool version changed to '%s'" % version) | ||
| 677 | + | ||
| 678 | + # Return | ||
| 679 | + return | ||
| 680 | + | ||
| 681 | + | ||
| 682 | +# ======================== # | ||
| 683 | +# Main routine entry point # | ||
| 684 | +# ======================== # | ||
| 685 | +if __name__ == '__main__': | ||
| 686 | + | ||
| 687 | + # Clear console | ||
| 688 | + os.system('clear') | ||
| 689 | + | ||
| 690 | + # Print header | ||
| 691 | + print('ctools release manager') | ||
| 692 | + print('======================') | ||
| 693 | + print('') | ||
| 694 | + | ||
| 695 | + # Enter endless loop | ||
| 696 | + while True: | ||
| 697 | + | ||
| 698 | + # Show main menu | ||
| 699 | + choice = main_menu() | ||
| 700 | + | ||
| 701 | + # Dispatch according to choice | ||
| 702 | + if choice == '1': | ||
| 703 | + release_menu() | ||
| 704 | + print('') | ||
| 705 | + elif choice == '2': | ||
| 706 | + package_version_menu() | ||
| 707 | + print('') | ||
| 708 | + elif choice == '3': | ||
| 709 | + libtool_version_menu() | ||
| 710 | + print('') | ||
| 711 | + elif choice == '4': | ||
| 712 | + commit('') | ||
| 713 | + print('') | ||
| 714 | + elif choice == '5': | ||
| 715 | + build_tarball() | ||
| 716 | + print('') | ||
| 717 | + elif choice == '6': | ||
| 718 | + check_tarball() | ||
| 719 | + print('') | ||
| 720 | + elif choice == 'q': | ||
| 721 | + break | ||
| 722 | + |
dev/set_version.py deleted
| 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 | -# Get libtool version number # | ||
| 62 | -# ========================== # | ||
| 63 | -def get_libtool(): | ||
| 64 | - """ | ||
| 65 | - Get libtools version number | ||
| 66 | - | ||
| 67 | - Returns | ||
| 68 | - ------- | ||
| 69 | - version : str | ||
| 70 | - Version number | ||
| 71 | - """ | ||
| 72 | - # Initialse version number of empty string | ||
| 73 | - version = '' | ||
| 74 | - | ||
| 75 | - # Open configure.ac file | ||
| 76 | - f = open('configure.ac', 'r') | ||
| 77 | - | ||
| 78 | - # Read all lines | ||
| 79 | - for line in f: | ||
| 80 | - | ||
| 81 | - # Search for pattern | ||
| 82 | - if line.startswith('CTOOLS_LT_VERSION='): | ||
| 83 | - | ||
| 84 | - # Extract version number | ||
| 85 | - start = line.find('"')+1 | ||
| 86 | - stop = line.find('"', start) | ||
| 87 | - version = line[start:stop].strip() | ||
| 88 | - | ||
| 89 | - # Close file | ||
| 90 | - f.close() | ||
| 91 | - | ||
| 92 | - # Return version | ||
| 93 | - return version | ||
| 94 | - | ||
| 95 | - | ||
| 96 | -# ============================== # | ||
| 97 | -# Set version number in one file # | ||
| 98 | -# ============================== # | ||
| 99 | -def set_version(filename, version, current): | ||
| 100 | - """ | ||
| 101 | - Set version number | ||
| 102 | - | ||
| 103 | - Parameters | ||
| 104 | - ---------- | ||
| 105 | - filename : str | ||
| 106 | - File name | ||
| 107 | - version : str | ||
| 108 | - Version number | ||
| 109 | - current : str | ||
| 110 | - Current version number | ||
| 111 | - """ | ||
| 112 | - # Open file in read mode | ||
| 113 | - f = open(filename, 'r') | ||
| 114 | - | ||
| 115 | - # Read file content | ||
| 116 | - content = f.read() | ||
| 117 | - | ||
| 118 | - # Close file | ||
| 119 | - f.close() | ||
| 120 | - | ||
| 121 | - # Replace version number | ||
| 122 | - new_content = content.replace(current, version) | ||
| 123 | - | ||
| 124 | - # Open file in write mode | ||
| 125 | - f = open(filename, 'w') | ||
| 126 | - | ||
| 127 | - # Write file content | ||
| 128 | - f.write(new_content) | ||
| 129 | - | ||
| 130 | - # Close file | ||
| 131 | - f.close() | ||
| 132 | - | ||
| 133 | - # Return | ||
| 134 | - return | ||
| 135 | - | ||
| 136 | - | ||
| 137 | -# =============================== # | ||
| 138 | -# Set version number in all files # | ||
| 139 | -# =============================== # | ||
| 140 | -def set_versions(version, current): | ||
| 141 | - """ | ||
| 142 | - Set version numbers in all files | ||
| 143 | - | ||
| 144 | - Parameters | ||
| 145 | - ---------- | ||
| 146 | - version : str | ||
| 147 | - Version number | ||
| 148 | - current : str | ||
| 149 | - Current version number | ||
| 150 | - """ | ||
| 151 | - # List of all relevant files, including their access paths from the | ||
| 152 | - # source directory | ||
| 153 | - filenames = ['configure.ac', | ||
| 154 | - 'ctools.pc.in', | ||
| 155 | - 'README.md', | ||
| 156 | - 'sonar-project.properties', | ||
| 157 | - 'doc/Doxyfile', | ||
| 158 | - 'doc/source/conf.py'] | ||
| 159 | - | ||
| 160 | - # Set versions by loop over all files | ||
| 161 | - for filename in filenames: | ||
| 162 | - set_version(filename, version, current) | ||
| 163 | - | ||
| 164 | - # Return | ||
| 165 | - return | ||
| 166 | - | ||
| 167 | - | ||
| 168 | -# =============================================== # | ||
| 169 | -# Set libtool version number in configure.ac file # | ||
| 170 | -# =============================================== # | ||
| 171 | -def set_libtool_version(library=False, added=False, removed=False, changed=False): | ||
| 172 | - """ | ||
| 173 | - Set special version numbers in configure.ac file | ||
| 174 | - | ||
| 175 | - Parameters | ||
| 176 | - ---------- | ||
| 177 | - library : bool, optional | ||
| 178 | - Library source code changed | ||
| 179 | - added : bool, optional | ||
| 180 | - Interfaces added | ||
| 181 | - removed : bool, optional | ||
| 182 | - Interfaces removed | ||
| 183 | - changed : bool, optional | ||
| 184 | - Interfaces changed | ||
| 185 | - """ | ||
| 186 | - # Get libtool version number | ||
| 187 | - old = get_libtool() | ||
| 188 | - split = old.split(':') | ||
| 189 | - | ||
| 190 | - # Decompose libtool version number | ||
| 191 | - current = int(split[0]) | ||
| 192 | - revision = int(split[1]) | ||
| 193 | - age = int(split[2]) | ||
| 194 | - | ||
| 195 | - # If the library source code has changed at all since the last update, then | ||
| 196 | - # increment revision | ||
| 197 | - if library: | ||
| 198 | - revision += 1 | ||
| 199 | - | ||
| 200 | - # If any interfaces have been added, removed, or changed since the last | ||
| 201 | - # update, increment current, and set revision to 0 | ||
| 202 | - if added or removed or changed: | ||
| 203 | - current += 1 | ||
| 204 | - revision = 0 | ||
| 205 | - | ||
| 206 | - # If any interfaces have been added since the last public release, then | ||
| 207 | - # increment age | ||
| 208 | - if added: | ||
| 209 | - age += 1 | ||
| 210 | - | ||
| 211 | - # If any interfaces have been removed or changed since the last public | ||
| 212 | - # release, then set age to 0 | ||
| 213 | - if removed or changed: | ||
| 214 | - age = 0 | ||
| 215 | - | ||
| 216 | - # Build new libtool version number | ||
| 217 | - version = '%d:%d:%d' % (current, revision, age) | ||
| 218 | - | ||
| 219 | - # Set libtool version number | ||
| 220 | - set_version('configure.ac', version, old) | ||
| 221 | - | ||
| 222 | - # Return | ||
| 223 | - return | ||
| 224 | - | ||
| 225 | - | ||
| 226 | -# ===================================================== # | ||
| 227 | -# Set special version number in doc/source/conf.py file # | ||
| 228 | -# ===================================================== # | ||
| 229 | -def set_special_conf(version, current): | ||
| 230 | - """ | ||
| 231 | - Set special version numbers in doc/source/conf.py file | ||
| 232 | - | ||
| 233 | - Parameters | ||
| 234 | - ---------- | ||
| 235 | - version : str | ||
| 236 | - Version number | ||
| 237 | - current : str | ||
| 238 | - Current version number | ||
| 239 | - """ | ||
| 240 | - # Generate current version number | ||
| 241 | - split = current.split('.') | ||
| 242 | - cur = '%s.%s' % (split[0], split[1]) | ||
| 243 | - | ||
| 244 | - # Generate new version number | ||
| 245 | - split = version.split('.') | ||
| 246 | - ver = '%s.%s' % (split[0], split[1]) | ||
| 247 | - | ||
| 248 | - # Set version number | ||
| 249 | - set_version('doc/source/conf.py', ver, cur) | ||
| 250 | - | ||
| 251 | - # Return | ||
| 252 | - return | ||
| 253 | - | ||
| 254 | - | ||
| 255 | -# ======================== # | ||
| 256 | -# Main routine entry point # | ||
| 257 | -# ======================== # | ||
| 258 | -if __name__ == '__main__': | ||
| 259 | - | ||
| 260 | - # Check for version number | ||
| 261 | - if len(sys.argv) < 3: | ||
| 262 | - print('Usage: set_version.py version [larc]') | ||
| 263 | - print(' l : source code changed') | ||
| 264 | - print(' a : interface(s) added') | ||
| 265 | - print(' r : interface(s) removed') | ||
| 266 | - print(' c : interface(s) changed') | ||
| 267 | - sys.exit() | ||
| 268 | - | ||
| 269 | - # Extract version number | ||
| 270 | - version = sys.argv[1] | ||
| 271 | - | ||
| 272 | - # Extract code change flags | ||
| 273 | - if len(sys.argv) == 3: | ||
| 274 | - flags = sys.argv[2] | ||
| 275 | - | ||
| 276 | - # Set change flags | ||
| 277 | - library = False | ||
| 278 | - added = False | ||
| 279 | - removed = False | ||
| 280 | - changed = False | ||
| 281 | - if flags.find('l') != -1: | ||
| 282 | - library = True | ||
| 283 | - if flags.find('a') != -1: | ||
| 284 | - added = True | ||
| 285 | - if flags.find('r') != -1: | ||
| 286 | - removed = True | ||
| 287 | - if flags.find('c') != -1: | ||
| 288 | - changed = True | ||
| 289 | - | ||
| 290 | - # Get the current version | ||
| 291 | - current = get_current() | ||
| 292 | - | ||
| 293 | - # Set versions | ||
| 294 | - set_versions(version, current) | ||
| 295 | - | ||
| 296 | - # Set libtool version | ||
| 297 | - set_libtool_version(library=library, added=added, removed=removed, | ||
| 298 | - changed=changed) | ||
| 299 | - | ||
| 300 | - # Set special version number in doc/source/conf.py file | ||
| 301 | - set_special_conf(version, current) | ||
| 302 | - |