示例#1
0
    def writefile(self, fileobj, executable=None):

        from Ganga.GPIDev.Lib.File import FileBuffer

        if not isType(fileobj, FileBuffer):

            try:
                name, contents = fileobj
            except TypeError as err:
                import traceback
                traceback.print_stack()
                logger.debug("TypeError: %s" % str(err))
                pass
            else:
                fileobj = FileBuffer(name, contents)
                logger.warning('file "%s": usage of tuples is deprecated, use FileBuffer instead', name)

        # output file name
        # Added a subdir to files, (see Ganga/GPIDev/Lib/File/File.py) This allows
        # to copy files into the a subdirectory of the workspace

        # FIXME: make a helper method for os.makedirs
        path_to_build = os.path.join(self.getPath(), fileobj.subdir)
        if not os.path.isdir(path_to_build):
            os.makedirs(path_to_build)
            logger.debug('created %s', self.getPath())
        else:
            logger.debug('already exists: %s', self.getPath())

        outname = expandfilename(self.getPath(fileobj.getPathInSandbox()))

        fileobj.create(outname)

        if executable:
            chmod_executable(outname)

        return outname
示例#2
0
    def writefile(self, fileobj, executable=None):

        from Ganga.GPIDev.Lib.File import FileBuffer

        try:
            name, contents = fileobj
        except TypeError:
            pass
        else:
            fileobj = FileBuffer(name, contents)
            logger.warning(
                'file "%s": usage of tuples is deprecated, use FileBuffer instead', name)

        # output file name
        # Added a subdir to files, (see Ganga/GPIDev/Lib/File/File.py) This allows
        # to copy files into the a subdirectory of the workspace

        # FIXME: make a helper method for os.makedirs
        try:
            os.makedirs(self.getPath() + fileobj.subdir)
            logger.debug('created %s', self.getPath())
        except OSError as x:
            import errno
            if x.errno == errno.EEXIST:
                logger.debug('EEXIT: %s', self.getPath())
            else:
                raise

        outname = expandfilename(self.getPath(fileobj.getPathInSandbox()))

        fileobj.create(outname)

        if executable:
            chmod_executable(outname)

        return outname