forked from eggnogdb/eggnog-mapper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
release.py
executable file
·98 lines (82 loc) · 3.08 KB
/
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
import re
import subprocess
import os
import sys
import readline
from optparse import OptionParser
WD = os.path.abspath(os.path.split(__file__)[0])
os.chdir(WD)
parser = OptionParser()
parser.add_option("--notest", dest="notest", action='store_true')
parser.add_option("--simulate", dest="simulate", action='store_true')
parser.add_option("--verbose", dest="verbose", action='store_true')
parser.add_option("--doconly", dest="doconly", action='store_true')
(options, args) = parser.parse_args()
def _ex(cmd, interrupt=True):
if options.verbose or options.simulate:
print("***", cmd)
if not options.simulate:
s = os.system(cmd)
if s != 0 and interrupt:
sys.exit(s)
else:
return s
else:
return 0
def ask(string, valid_values, default=-1, case_sensitive=False):
""" Asks for a keyborad answer """
v = None
if not case_sensitive:
valid_values = [value.lower() for value in valid_values]
while v not in valid_values:
readline.set_startup_hook(lambda: readline.insert_text(default))
try:
v = input("%s [%s] " % (string, ', '.join(valid_values))).strip()
if v == '' and default>=0:
v = valid_values[default]
if not case_sensitive:
v = v.lower()
finally:
readline.set_startup_hook()
return v
def ask_path(string, default_path):
v = None
while v is None:
v = input("%s [%s] " % (string, default_path)).strip()
if v == '':
v = default_path
if not os.path.exists(v):
print(v, "does not exist.", file=sys.stderr)
v = None
return v
TEMP_PATH = "/tmp"
CURRENT_VERSION = open('VERSION').readline().strip()
a, b, c, tag, ncom, hcom = re.search("(\d+)\.(\d+)\.(\d+)(-?\w+\d+)?-?(\d+)?-?(\w+)?", CURRENT_VERSION).groups()
a, b, c = list(map(int, (a, b, c)))
SERIES_VERSION = "%s.%s" %(a, b)
print('====================================================')
print('CURRENT VERSION:', a, b, c, tag, ncom, hcom)
print('====================================================')
# test examples
input('continue?')
if not options.doconly:
# commit changes in VERSION
if tag:
tag1, tag2 = re.search('(.+?)(\d+)', tag).groups()
tag2 = int(tag2)
NEW_VERSION = "%s.%s.%s%s%s" %(a, b, c, tag1, tag2+1)
else:
NEW_VERSION = "%s.%s.%s" %(a, b, c+1)
if ask('Increase version to "%s" ?' %NEW_VERSION, ['y', 'n']) == 'n':
NEW_VERSION = input('new version string:').strip()
if ask('Write "%s" and commit changes?' %NEW_VERSION, ['y', 'n']) == 'y':
open('VERSION', 'w').write(NEW_VERSION)
open("eggnogmapper/version.py", 'w').write("#autogenerated during release process. Do not modify\n__VERSION__='%s'\n" %(NEW_VERSION))
_ex('git commit -a -m "release %s " && git tag -f %s' %(NEW_VERSION, NEW_VERSION))
if ask('push changes and release "%s" ?' %NEW_VERSION, ['y', 'n']) == 'y':
_ex('git push')
_ex('git push --tags')
else:
print('Aborted')
sys.exit(1)
sys.exit(0)