-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
set_new_version.py
executable file
·53 lines (41 loc) · 1.76 KB
/
set_new_version.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/env python3
# There's too many places where the version has to be set, so I've made a little script to do it for me each time.
import argparse
import os.path
import re
class FilePatternReplacement:
def __init__(self, file, pattern, replacement):
self.file = file
self.pattern = pattern
self.replacement = replacement
def replace(self):
if not os.path.exists(self.file):
return f"{self.file} does not exist"
with open(self.file, 'r', encoding='utf-8') as f:
content = f.read()
modified_content = re.sub(self.pattern, self.replacement, content)
with open(self.file, 'w', encoding='utf-8') as f:
f.write(modified_content)
if __name__ == '__main__':
parser = argparse.ArgumentParser(prog='Set new version')
parser.add_argument('version', nargs='?', type=str)
args = parser.parse_args()
version = args.version
if version is None or version == "":
parser.print_help()
sys.exit(1)
file_pattern_replacements = [
FilePatternReplacement('ChebsNecromancy/ChebsNecromancy.csproj',
'<Version>[0-9.]+<\/Version>',
f'<Version>{version}.0</Version>'),
FilePatternReplacement('ChebsNecromancy/BasePlugin.cs',
'PluginVersion = [".0-9]+',
f'PluginVersion = "{version}"'),
FilePatternReplacement('ChebsNecromancy/Package/manifest.json',
'"version_number": [".0-9]+',
f'"version_number": "{version}"'),
]
errors = [x.replace() for x in file_pattern_replacements]
for error in errors:
if error is not None:
print(error)