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

        from Ganga.GPIDev.Lib.File import FileBuffer

        if not isType(fileobj, FileBuffer):
            raise GangaTypeError(
                'Usage of tuples is not allowed, use FileBuffer instead')

        # 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()),
                                 True)

        fileobj.create(outname)

        if executable:
            chmod_executable(outname)

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

        from Ganga.GPIDev.Lib.File import FileBuffer

        if not isType(fileobj, FileBuffer):
            raise GangaTypeError('Usage of tuples is not allowed, use FileBuffer instead')

        # 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()), True)

        fileobj.create(outname)

        if executable:
            chmod_executable(outname)

        return outname
Exemple #3
0
    def create(self, outname):
        """create a file in  a local filesystem as 'outname', maintain
        the original permissions """
        import shutil

        shutil.copy(expandfilename(self.name), outname)
        if self.executable:
            chmod_executable(outname)
Exemple #4
0
    def create(self, outname):
        """create a file in  a local filesystem as 'outname', maintain
        the original permissions """
        import shutil

        shutil.copy(expandfilename(self.name), outname)
        if self.executable:
            chmod_executable(outname)
Exemple #5
0
    def create(self,outname=None):
        """create a file in a local filesystem as 'outname' """
        if outname is not None:    
            file(outname,'w').write(self.getContents())
        else:   
            file(self.name,'w').write(self.getContents())

        if self.executable:
            from Ganga.Utility.files import chmod_executable
            chmod_executable(outname)
        return self
Exemple #6
0
    def create(self, outname=None):
        """create a file in a local filesystem as 'outname' """
        filename = self.name
        if outname is not None:
            filename = outname

        with open(filename, 'w') as thisfile:
            thisfile.write(self._contents)

        if self.executable:
            from Ganga.Utility.files import chmod_executable
            chmod_executable(filename)

        logger.debug("Created %s in: %s" %
                     (filename, os.path.realpath(filename)))

        return self
Exemple #7
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
Exemple #8
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
Exemple #9
0
            import os
            os.makedirs(self.getPath()+fileobj.subdir)
            logger.debug('created %s',self.getPath())
        except OSError,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

    # remove the workspace (including all files and directories)
    # the part of the tree as resolved by getPath() is pruned recursively
    # if preserve_top is true then the directory specified by getPath() will be preserved
    def remove(self,preserve_top=None):         
        try:
            import shutil
            logger.debug('removing %s',self.getPath())
            if os.path.exists(self.getPath()):
                self.__removeTrials=0
                
                def retryRemove(function, path, excinfo):
                    """ Address AFS/NSF problems with left-over lock files which prevents