-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathchangeversion.py
executable file
·53 lines (40 loc) · 1.93 KB
/
changeversion.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/python3
# -*-coding:Utf-8 -*
#Deus, in adjutorium meum intende
"""Change version of the soft in different places"""
import argparse
import collections
import re
FileData = collections.namedtuple('FileData',('path','line','line_clue'))
def change_version(new_version: str,path: str,line: str,line_clue: str) -> None:
"""Put new version into line where line_clue is
in the file path"""
with open(path) as f:
file = f.read().split('\n')
new_file = []
for line_ in file:
if line_clue in line_:
line_ = line.format(new_version)
new_file.append(line_)
with open(path,'w') as f:
f.write('\n'.join(new_file))
return None
def main(new_version: str) -> None:
if not re.match("^\d+\.\d+\.\d+$",new_version):
raise ValueError("The new version doesn't seem to follow the correct syntax for a new version.\nPlease enter a version like X.X.X where X is a number")
for file_item in files_data:
change_version(new_version,file_item.path,file_item.line,file_item.line_clue)
print('Please do not forget to apply following commands: `./manage.py makemigrations && ./manage.py migrate`')
return None
files_data = (
FileData('programme/command_line.py',4*' '+"""system.add_argument('--version', action='version',version='%(prog)s {}')""","""'--version', action='version',version='"""),
FileData('README.md','Latest version is {}','Latest version is'),
FileData('README.md','## New features available in {}','## New features available in'),
FileData('programme/web/help/models.py','VERSION = "{}"','VERSION = '),
FileData('programme/web/kalendarium/views.py',4*' '+'VERSION = "{}"','VERSION = '),
)
parser = argparse.ArgumentParser(description="Change version of the soft in different places")
parser.add_argument("version",help="Change version number.")
if __name__ == '__main__':
args=parser.parse_args()
main(args.version)