Example #1
0
    def delete ( self, path = None ):
        """ Deletes the associated directory from the file system.
        """
        if path is None:
            path = self.path

        not_deleted = 0
        try:
            for name in listdir( path ):
                fn = join( path, name )
                if isfile( fn ):
                    if self.include_file( fn ):
                        remove( fn )
                    else:
                        not_deleted += 1
                elif isdir( fn ) and ( not self.delete( fn ) ):
                    not_deleted += 1
            if not_deleted == 0:
                rmdir( path )
                return True

        except:
            error( self.handler.parent, "Could not delete '%s'" % fn )

        # Indicate that the directory was not deleted:
        return False
Example #2
0
    def _children_items_set ( self, event ):
        """ Handles changes to the 'children' facet.
        """
        for child in event.added:
            if not isinstance( child, DirectoryNode ):
                continue

            new_path = join( self.path, child.dir_name )
            if isfile( new_path ):
                error( self.handler.parent,
                       ("Cannot create the directory '%s'.\nThere is already a "
                        "file with that name.") % child.dir_name )
                return

            if not isdir( new_path ):
                try:
                    mkdir( new_path )
                except:
                    error( self.handler.parent, ( "An error occurred creating "
                           "the directory '%s'" ) % child.dir_name )
                    return

            child.set( path = new_path, file_space = self.file_space )

            self.initialized = False
Example #3
0
 def delete ( self ):
     """ Deletes the associated file from the file system.
     """
     try:
         remove( self.path )
     except:
         error( self.handler.parent, "Could not delete the file '%s'" %
                                     basename( self.path )[ 0 ] )
Example #4
0
 def tno_set_label ( self, node, label ):
     """ Sets the label for a specified object.
     """
     old_name = self.path
     dir_name = dirname( old_name )
     new_name = join( dir_name, label )
     try:
         rename( old_name, new_name )
         self.path     = new_name
     except:
         error( self.handler.parent, ( "An error occurred while trying to "
                "rename '%s' to '%s'" ) % ( basename( old_name ), label ) )