|
3 | 3 | ## \file change_version_number.py |
4 | 4 | # \brief Python script for updating the version number of the SU2 suite. |
5 | 5 | # \author A. Aranake |
6 | | -# \version 7.0.0 "Blackbird" |
| 6 | +# \version 7.0.1 "Blackbird" |
7 | 7 | # |
8 | 8 | # SU2 Project Website: https://su2code.github.io |
9 | 9 | # |
|
27 | 27 |
|
28 | 28 | # make print(*args) function available in PY2.6+, does'nt work on PY < 2.6 |
29 | 29 | from __future__ import print_function |
30 | | - |
| 30 | +from optparse import OptionParser |
31 | 31 | # Run the script from the base directory (ie $SU2HOME). Grep will search directories recursively for matches in version number |
32 | 32 | import os,sys |
33 | 33 |
|
| 34 | +parser = OptionParser() |
| 35 | +parser.add_option("-v", "--version", dest="version", |
| 36 | + help="the new version number", metavar="VERSION") |
| 37 | +parser.add_option("-r", "--releasename", dest="releasename", |
| 38 | + help="Name of the new release", metavar="RELEASENAME") |
| 39 | +parser.add_option("-y", action="store_true", dest="yes", help="Answer yes to all questions", metavar="YES") |
| 40 | +(options, args)=parser.parse_args() |
| 41 | + |
| 42 | +if not options.version: |
| 43 | + parser.error("new version number must be provided with -v option") |
| 44 | + |
34 | 45 | #oldvers = '2012-2018' |
35 | 46 | #newvers = '2012-2019' |
36 | | -oldvers = '7.0.0 "Blackbird"' |
37 | | -newvers = '7.0.1 "Blackbird"' |
| 47 | +oldvers = '7.0.1 "Blackbird"' |
| 48 | +oldvers_q= r'7.0.1 \"Blackbird\"' |
| 49 | +newvers = options.version + ' "' + options.releasename + '"' |
| 50 | +newvers_q= options.version + ' \\"' + options.releasename + '\\"' |
38 | 51 |
|
39 | 52 | if sys.version_info[0] > 2: |
40 | 53 | # In PY3, raw_input is replaced with input. |
|
54 | 67 |
|
55 | 68 | #TODO: replace with portable instructions. This works only on unix systems |
56 | 69 | os.system("grep -IFwr '%s' *|grep -vF '.svn' |grep -v ISC > version.txt"%oldvers) |
| 70 | +os.system("grep -IFwr '%s' --exclude='version.txt' *|grep -vF '.svn' |grep -v ISC >> version.txt"%oldvers_q) |
57 | 71 |
|
58 | 72 | # Create a list of files to adjust |
59 | 73 | filelist = [] |
60 | 74 | f = open('version.txt','r') |
61 | 75 | for line in f.readlines(): |
62 | 76 | candidate = line.split(':')[0] |
63 | | - if not candidate in filelist and candidate.find(sys.argv[0])<0: |
| 77 | + if not candidate in filelist: |
64 | 78 | filelist.append(candidate) |
65 | 79 | f.close() |
66 | 80 | print(filelist) |
67 | 81 |
|
68 | 82 | # Prompt user before continuing |
69 | 83 | yorn = '' |
70 | | -while(not yorn.lower()=='y'): |
71 | | - yorn = raw_input('Replace %s with %s in the listed files? [Y/N]: '%(oldvers,newvers)) |
| 84 | +while(not yorn.lower()=='y' and not options.yes): |
| 85 | + yorn = raw_input('Replace %s with %s and %s with %s in the listed files? [Y/N]: '%(oldvers,newvers, oldvers_q, newvers_q)) |
72 | 86 | if yorn.lower()=='n': |
73 | 87 | print('The file version.txt contains matches of oldvers') |
74 | 88 | sys.exit() |
|
77 | 91 | for fname in filelist: |
78 | 92 | s = open(fname,'r').read() |
79 | 93 | s_new = s.replace(oldvers,newvers) |
80 | | - |
| 94 | + s_new = s_new.replace(oldvers_q, newvers_q) |
81 | 95 | f = open(fname,'w') |
82 | 96 | f.write(s_new) |
83 | 97 | f.close() |
|
0 commit comments