Esempio n. 1
0
    def __init__(self, subject, *args):
        """Set up a TASK child class environment.

        Initialise the Global Configuration, the Logger, the system load routines.
        Define a list of dependencies prerequisite to run this tasks.
        Define, create and aliases a Working directory for the tasks.

        If more arguments have been supplied to generic tasks, GenericTask will create an alias
        for each additionnal arg adding the suffix Dir to the name provided and then create  an alias 'dependDir'
        on the first optionnal arg provided to __init__

        """

        self.__order = None
        self.__name = self.__class__.__name__.lower()
        self.__cleanupBeforeImplement = True
        self.config = subject.getConfig()
        self.subjectDir = subject.getDir()
        self.toadDir = self.config.get('arguments', 'toadDir')
        self.workingDir = os.path.join(
            self.subjectDir,
            self.__class__.__module__.split(".")[-1])
        Logger.__init__(self, subject.getLogDir())
        Load.__init__(self, self.config.get('general', 'nthreads'))
        self.dependencies = []
        self.__dependenciesDirNames = {}
        for arg in args:
            self.dependencies.append(arg)
        for i, arg in enumerate(args):
            images = glob.glob("{}/tasks/??-{}.py".format(self.toadDir, arg))
            if len(images) == 1:
                [name, ext] = os.path.splitext(os.path.basename(images[0]))
                dir = os.path.join(self.subjectDir, name)
                setattr(self, "{}Dir".format(arg), dir)
                self.__dependenciesDirNames["{}Dir".format(arg)] = dir
                if i == 0:
                    self.dependDir = dir