aboutsummaryrefslogtreecommitdiffstats
path: root/acispy/pfiles.py
blob: 8a80a143d6954a6fbde1954c62194f90b839fd2b (plain)
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
# Copyright (c) 2017 Weitian LI <liweitianux@live.com>
# MIT license
#
# Weitian LI
# 2017-02-06

"""
Prepare the CIAO parameter files and setup the PFILES environment
variable to keep the pfiles locally, in order to avoid the conflicts
between multiple instance of the same CIAO tools.
"""

import os
import subprocess
import shutil


def setup_pfiles(tools):
    """
    Copy the parameter files of the specified tools to the current
    working directory, and setup the ``PFILES`` environment variable.

    Parameters
    ----------
    tools : list[str]
        Name list of the tools to be set up
    """
    for tool in tools:
        pfile = subprocess.check_output([
            "paccess", tool
        ]).decode("utf-8").strip()
        subprocess.check_call(["punlearn", tool])
        try:
            shutil.copy(pfile, ".")
        except shutil.SameFileError:
            pass
    # Setup the ``PFILES`` environment variable
    os.environ["PFILES"] = "./:" + os.environ["PFILES"]