-
Notifications
You must be signed in to change notification settings - Fork 5
/
bump-release.py
executable file
·96 lines (84 loc) · 3.47 KB
/
bump-release.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/usr/bin/env python
import argparse
import logging
import os
import re
import sys
logger = logging.getLogger()
def reset_version_release(spec_file, previous_version, new_version):
with open(spec_file, 'r+') as f:
lines = f.readlines()
f.seek(0)
for line in lines:
if line.startswith('Version:'):
m = re.search(r'^Version:(\s+)%s$' % previous_version, line)
if not m:
f.write(line)
continue
new_version = "Version:%s%s\n" % (m.group(1), new_version)
logger.info("Modify %s version: old='%s' new='%s'", spec_file, line.strip(), new_version.strip())
f.write(new_version)
elif line.startswith('Release:'):
m = re.search(r'^Release:(\s+)([\d]+)', line)
if not m:
f.write(line)
continue
if 'dist' in line:
new_release = "Release:%s1%%{?dist}\n" % m.group(1)
else:
new_release = "Release:%s1\n" % m.group(1)
logger.info("Modify %s release: old='%s' new='%s'", spec_file, line.strip(), new_release.strip())
f.write(new_release)
else:
f.write(line)
f.truncate()
def main():
usage_examples = """
Usage examples:
Sync given release
%(prog)s --previous-release 1.3 --new-release 1.4
"""
parser = argparse.ArgumentParser(formatter_class=argparse.RawDescriptionHelpFormatter, epilog=usage_examples)
parser.add_argument('-d', '--debug', action='store_true', default=False)
parser.add_argument('-p', '--previous-release', required=True)
parser.add_argument('-n', '--new-release', required=True)
args = parser.parse_args()
if args.debug:
log_level = logging.DEBUG
else:
log_level = logging.INFO
logger.setLevel(log_level)
ch = logging.StreamHandler()
formatter = logging.Formatter('[%(asctime)s] %(levelname)s: %(message)s')
ch.setFormatter(formatter)
logger.addHandler(ch)
repo_dir = os.path.dirname(__file__)
specs_to_modify = [
'packages/ondemand-compute/ondemand-compute.spec',
'packages/ondemand-release/ondemand-release.spec',
'packages/ondemand-runtime/ondemand-runtime.spec',
]
files_to_modify = {
'packages/ondemand-release/ondemand-compute.repo': '/REPLACE/',
'packages/ondemand-release/ondemand-web.repo': '/REPLACE/',
'docker-image/epel-7-x86_64.cfg': '/REPLACE/',
'docker-image/epel-8-x86_64.cfg': '/REPLACE/',
'docker-image/ondemand-el7-x86_64.cfg': '/REPLACE/',
'docker-image/ondemand-el8-x86_64.cfg': '/REPLACE/',
'packages/passenger/passenger.spec': 'runtime_version REPLACE',
'release-manifest.yaml': "'REPLACE",
}
for spec in specs_to_modify:
reset_version_release(spec, args.previous_release, args.new_release)
for _file, replace in files_to_modify.items():
with open(_file, 'r+') as f:
lines = f.read()
f.seek(0)
logger.info("Modify %s replace %s with %s", _file, args.previous_release, args.new_release)
replace_str = replace.replace('REPLACE', args.previous_release)
new_str = replace.replace('REPLACE', args.new_release)
new_lines = lines.replace(replace_str, new_str)
f.write(new_lines)
f.truncate()
if __name__ == '__main__':
main()