Esempio n. 1
0
    def prepare(self, force=False):
        """
        A method to place the Root application into a prepared state.
        """
        if (self.is_prepared is not None) and (force is not True):
            raise ApplicationPrepareError(
                '%s application has already been prepared. Use prepare(force=True) to prepare again.'
                % getName(self))
        self.is_prepared = ShareDir()
        logger.info('Created shared directory: %s' % (self.is_prepared.name))

        try:
            copy_worked = self.copyPreparables()
            if copy_worked == 0:
                logger.error(
                    'Failed during prepare() phase. Unpreparing application.')
                self.unprepare()
                return 0
            else:
                # add the newly created shared directory into the metadata
                # system if the app is associated with a persisted object
                self.checkPreparedHasParent(self)
                self.post_prepare()
                return 1
        except:
            self.unprepare()
            raise
Esempio n. 2
0
    def prepare(self, force=False):
        """
        This writes the wrapper script for the Notebook application.

        """
        if force:
            self.unprepare()

        if (self.is_prepared is not None):
            raise ApplicationPrepareError(
                '%s application has already been prepared. Use prepare(force=True) to prepare again.'
                % getName(self))

        logger.info('Preparing %s application.' % getName(self))
        self.is_prepared = ShareDir()
        logger.info('Created shared directory: %s' % (self.is_prepared.name))

        # Prevent orphaned shared directories
        try:
            self.checkPreparedHasParent(self)

            script = self.wrapper(self.regexp, self.version, self.timeout,
                                  self.kernel)
            logger.debug("Creating: %s" %
                         path.join(self.getSharedPath(), script.name))
            script.create(path.join(self.getSharedPath(), script.name))

            self.post_prepare()

        except Exception as err:
            self.unprepare()
            raise

        return 1
Esempio n. 3
0
    def prepare(self, force=False):
        """
        This prepares the Im3ShapeApp application and copies any LocalFile objects which are allocated to: im3_location, ini_location and blacklist into the prepared sandbox to be shipped to the WN
        Args:
            force (bool): Should force the prepare step to run
        """

        if (self.is_prepared is not None) and (force is not True):
            raise ApplicationPrepareError(
                '%s application has already been prepared. Use prepare(force=True) to prepare again.'
                % getName(self))

        logger.info('Preparing %s application.' % getName(self))
        self.is_prepared = ShareDir()
        logger.info('Created shared directory: %s' % (self.is_prepared.name))

        try:
            # copy any 'preparable' objects into the shared directory
            send_to_sharedir = self.copyPreparables()
            # add the newly created shared directory into the metadata system
            # if the app is associated with a persisted object
            self.checkPreparedHasParent(self)
            for file_ in [
                    self.ini_location, self.im3_location, self.blacklist
            ]:
                if isinstance(file_, LocalFile):
                    self.copyIntoPrepDir(file_.namePattern)
                assert type(file_) in [LocalFile, DiracFile]
            # return
            # [os.path.join(self.is_prepared.name,os.path.basename(send_to_sharedir))]
            self.post_prepare()

        except Exception as err:
            logger.debug("Err: %s" % str(err))
            self.unprepare()
            raise

        return 1
Esempio n. 4
0
    def prepare(self, force=False):
        """
        A method to place the Executable application into a prepared state.

        The application wil have a Shared Directory object created for it. 
        If the application's 'exe' attribute references a File() object or
        is a string equivalent to the absolute path of a file, the file 
        will be copied into the Shared Directory.

        Otherwise, it is assumed that the 'exe' attribute is referencing a 
        file available in the user's path (as per the default "echo Hello World"
        example). In this case, a wrapper script which calls this same command 
        is created and placed into the Shared Directory.

        When the application is submitted for execution, it is the contents of the
        Shared Directory that are shipped to the execution backend. 

        The Shared Directory contents can be queried with 
        shareref.ls('directory_name')

        See help(shareref) for further information.
        """

        if (self.is_prepared is not None) and not force:
            raise ApplicationPrepareError('%s application has already been prepared. Use prepare(force=True) to prepare again.' % getName(self))

        # lets use the same criteria as the configure() method for checking file existence & sanity
        # this will bail us out of prepare if there's somthing odd with the job config - like the executable
        # file is unspecified, has a space or is a relative path
        self.configure(self)
        logger.info('Preparing %s application.' % getName(self))
        self.is_prepared = ShareDir()
        logger.info('Created shared directory: %s' % (self.is_prepared.name))

        try:
            # copy any 'preparable' objects into the shared directory
            send_to_sharedir = self.copyPreparables()
            # add the newly created shared directory into the metadata system
            # if the app is associated with a persisted object
            self.checkPreparedHasParent(self)
            # return
            # [os.path.join(self.is_prepared.name,os.path.basename(send_to_sharedir))]
            self.post_prepare()

            if isinstance(self.exe, File):
                source = self.exe.name
            elif isinstance(self.exe, str):
                source = self.exe
            
            if not os.path.exists(source):
                logger.debug("Error copying exe: %s to input workspace" % str(source))
            else:
                try:
                    parent_job = self.getJobObject()
                except:
                    parent_job = None
                    pass
                if parent_job is not None:
                    input_dir = parent_job.getInputWorkspace(create=True).getPath()
                    shutil.copy2(source, input_dir)

        except Exception as err:
            logger.debug("Err: %s" % str(err))
            self.unprepare()
            raise

        return 1