test_manifest.py 1.88 KB
Newer Older
Paul McCarthy's avatar
Paul McCarthy committed
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
#!/usr/bin/env python
#
# test_manifest.py - Run the fslinstaller script on a generated manifest file.

import os.path as op
import os
import sys
import json

from manifest_rules.utils import sprun, tempdir, download_file


def main():
    manifest_file    = op.abspath(sys.argv[1])
    environment_file = op.abspath(sys.argv[2])

    # credentials for logging into
    # internal FSL conda channel
    username = os.environ['FSLCONDA_USERNAME']
    password = os.environ['FSLCONDA_PASSWORD']

    with open(manifest_file, 'rt') as f:
        manifest = json.loads(f.read())

    installer_url = manifest['installer']['url']
    latest        = manifest['versions'].get('latest', None)

    # This skip can be removed when we
    # actually have a conda-based FSL release
    if latest is None:
        print('Manifest file does not specify a "latest" FSL '
              'release - cannot run fslinstaller.py')
        sys.exit(0)

    with tempdir():
        download_file(installer_url, 'fslinstaller.py')

        os.mkdir('homedir')
        os.mkdir('workdir')

        print(sprun(f'{sys.executable} ./fslinstaller.py '
                    f'--manifest {manifest_file} '
                    '--listversions'))

        try:
            print(sprun(f'{sys.executable} ./fslinstaller.py '
                  f'--manifest {manifest_file} '
                  f'--environment {environment_file} '
                  f'--username {username} --password {password} '
                  '--dest fsl --workdir workdir --homedir homedir'))
        finally:
            logfile = op.join('workdir', 'fslinstaller.log')
            if op.exists(logfile):
                print('Contents of fslinstaller.log file:')
                with open(logfile, 'rt') as f:
                    print(f.read())
            else:
                print('fslinstaller.log file was not created!')


if __name__ == '__main__':
    sys.exit(main())