cdftools.py 726 Bytes
Newer Older
import subprocess
import os
from log import Log


class CDFTools:

    def __init__(self, path=''):
        self.path = path

    def run(self, command, input, output=None, options=None):
        line = [os.path.join(self.path, command)]
        if input:
Javier Vegas-Regidor's avatar
Javier Vegas-Regidor committed
            if isinstance(input, basestring):
                line.append(input)
            else:
                for element in input:
                    line.append(element)
        if options:
            for option in options:
                line.append(option)
        if output:
            line.append('-o')
            line.append(output)

        process = subprocess.Popen(line, stdout=subprocess.PIPE)
        Log.log.log(Log.INFO, process.communicate())