-
Notifications
You must be signed in to change notification settings - Fork 2
/
b2setup-externals.py
85 lines (69 loc) · 3.19 KB
/
b2setup-externals.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
# -*- coding: utf-8 -*-
from __future__ import print_function
import sys
import os
import textwrap
from setup_tools import get_var, update_environment, SetupToolsArgumentParser, NoExitHelpAction
def get_argument_parser(available=None, default=None):
description = textwrap.dedent('''\n
This command sets up the Belle II externals to be used without any specific release
of the Belle II software. It's useful if you just want to enable the software
included in the Belle II externals like an updated ROOT or git version. Without an
argument it will setup the latest version it can find, otherwise it will setup
the specified version
''')
parser = SetupToolsArgumentParser(prog='b2setup-externals',
error_message="You can try installing unavailable versions by using 'b2install-externals VERSION'",
add_help=False,
description=description)
parser.add_argument('release',
metavar='RELEASE',
type=str,
default=default,
choices=available,
nargs='?')
parser.add_argument('--csh',
default=False,
action='store_true',
help='To be used with csh shells.')
parser.add_argument('--help', '-h', '-?',
nargs=0,
action=NoExitHelpAction)
return parser
if __name__ == '__main__':
# prepare list of available versions
top_dir = os.environ["BELLE2_EXTERNALS_TOPDIR"]
# get sorted list of directories in externals directory
try:
available_versions = sorted(next(os.walk(top_dir))[1])
except:
available_versions = []
# and chose the latest one as default
if available_versions:
default_version = available_versions[-1]
else:
default_version = None
if not available_versions:
print(textwrap.dedent("""
Error: Cannot find any externals in the top directory '%s'.
Try installing externals with b2install-externals first""" % top_dir), file=sys.stderr)
sys.exit(1)
# check that no Belle II software is set up
if 'BELLE2_RELEASE' in os.environ.keys() or 'BELLE2_LOCAL_DIR' in os.environ.keys():
print('Error: This command can only be used if no Belle II software is set up.', file=sys.stderr)
sys.exit(1)
args = get_argument_parser(available=available_versions, default=default_version).parse_args()
if args.help and available_versions:
print(textwrap.dedent("""
Available Versions: %s
Default Version: %s""" % (", ".join(available_versions), default_version)), file=sys.stderr)
# setup externals
update_environment(externals_version=args.release, csh=args.csh)
try:
extdir = get_var('BELLE2_EXTERNALS_DIR')
sys.path[:0] = [extdir]
from externals import check_externals
if not check_externals(extdir):
sys.stderr.write('Error: Check of externals at %s failed.\n' % extdir)
except:
sys.stderr.write('Error: Check of externals at %s failed.\n' % extdir)