exec(open('../tooldog/analyse/container.py').read())

"""
Explanation: Protocol of experiments 31.05.2017
Goal: Test more tools.
Requirements:
1. Installed Docker with the internet access
1. Python3, pip
1. Installed dependencies from requirements.txt 
We import the Container class from docker_wrapper module.
End of explanation
"""


def write_to_file(filename, string = ''):
    """Write string to file

    :param str filename: Filename
    :param str string: String to write
    """
    f = open(filename, 'w')
    f.write(string)
    f.close()

PYTHON_VERSION = 2 # version of python tool

TOOL_NAME = 'integron_finder' # name of the tool, assuming it is available via PyPi

OUTPUT_FORMAT = 'cwl' # output: cwl / xml

OUTPUT_FILENAME = TOOL_NAME + "." + OUTPUT_FORMAT # output filename

PYTHON_PATH = "/usr/local/lib/python3.5/dist-packages/" if PYTHON_VERSION == 3 else \
"/usr/local/lib/python2.7/dist-packages/" # PYTHONPATH, required for argparse2tool

"""
Explanation: As in previous experiment we will define some useful constants and util functions for later use.
End of explanation
"""


c = Container("inkuzm/tooldog-analyser-sandbox",
              "tail -f /dev/null",  # run until we will stop the container
              environment={'PYTHONPATH': PYTHON_PATH})

"""
Explanation: Now we are ready to create a container.
End of explanation
"""


cwl_tool = '' 
with c:
    exe1 = c.exec("pip2 install argparse2tool")
    for line in exe1:
        print(line)
    exe2 = c.exec('pip2 install ' + TOOL_NAME)
    for line in exe2:
        print(line)
    exe3 = c.exec(TOOL_NAME + ' --generate_cwl_tool')
    for line in exe3:
        cwl_tool += line.decode("utf-8")[:-1]

write_to_file(OUTPUT_FILENAME, cwl_tool)

"""
Explanation: Let's create an executional context.
End of explanation
"""


