-
Notifications
You must be signed in to change notification settings - Fork 2
/
b2analysis-update
executable file
·66 lines (54 loc) · 2.38 KB
/
b2analysis-update
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
#!/usr/bin/env b2anypython
# -*- coding: utf-8 -*-
import sys, os
import textwrap
from versioning import supported_release
import argparse
def get_argument_parser():
description = textwrap.dedent('''\n
This command changes the central release version for the currently set up
analysis. If no central release version is given as argument the recommended
release version is taken.
''')
parser = argparse.ArgumentParser(prog='b2analysis-update',
formatter_class=argparse.RawDescriptionHelpFormatter,
description=description)
parser.add_argument('release',
metavar='RELEASE',
type=str,
nargs='?',
help='A centrally produced release used instead of the recommended one')
return parser
if __name__ == '__main__':
args = get_argument_parser().parse_args()
# get .analysis file and its content
analysis = None
for path in ['.', os.environ.get('BELLE2_ANALYSIS_DIR', '.')]:
filename = os.path.join(path, '.analysis')
if os.path.isfile(filename):
analysis = filename
break
if analysis is None:
sys.stderr.write('Error: No analysis directory found.\n')
sys.exit(1)
current_release = open(analysis).readline().strip()
# if no release is given take the recommended one
if args.release is None:
release = supported_release(current_release)
# if a release is given check whether it is supported
else:
supported = supported_release(args.release)
if args.release != supported:
print('Warning: %s is not supported, instead %s is recommended' % (args.release, supported))
release = args.release
# do the update if the release differs from the current one
if release == current_release:
print('The analysis is already set to %s. No update is done.' % release)
else:
print('Updating from analysis at %s from %s to %s.' % (os.path.dirname(analysis), current_release, release))
print('Please make sure to run b2setup.')
analysis_file = open(analysis, 'w')
analysis_file.write(release + '\n')
analysis_file.close()
os.remove('site_scons')
os.symlink(os.path.join(os.environ['VO_BELLE2_SW_DIR'], 'releases', release, 'site_scons'), 'site_scons')