DirectoryClosure

DIRAC FileCatalog component representing a directory tree with a closure table

General warning: when we return the number of affected row, if the values did not change
then they are not taken into account, so we might return “Dir does not exist” while it does…. the timestamp update should prevent this to happen, however if you do it several times within 1 second, then there will be no changed, and affected = 0
class DIRAC.DataManagementSystem.DB.FileCatalogComponents.WithFkAndPs.DirectoryClosure.DirectoryClosure(database=None)

Bases: DIRAC.DataManagementSystem.DB.FileCatalogComponents.DirectoryTreeBase.DirectoryTreeBase

Class managing Directory Tree with a closure table http://technobytz.com/closure_table_store_hierarchical_data.html http://fungus.teststation.com/~jon/treehandling/TreeHandling.htm http://www.slideshare.net/billkarwin/sql-antipatterns-strike-back http://dirtsimple.org/2010/11/simplest-way-to-do-tree-based-queries.html

__init__(database=None)
changeDirectoryGroup(paths, recursive=False)

Bulk setting of the directory group

:param dictionary paths : dictionary < lfn : group >

changeDirectoryMode(paths, recursive=False)

Bulk setting of the directory mode

:param dictionary paths : dictionary < lfn : mode >

changeDirectoryOwner(paths, recursive=False)

Bulk setting of the directory owner

:param dictionary paths : dictionary < lfn : owner >

countSubdirectories(dirId, includeParent=True)

Count the number of subdirectories

:param dirID : id of the directory :param includeParent : count itself

Returns:S_OK(value)
createDirectory(dirs, credDict)

Checking for existence of directories

exists(lfns)
existsDir(path)

Check the existence of a directory at the specified path

:param path : directory path

:returns S_OK( { ‘Exists’ : False } ) if the directory does not exist
S_OK( { ‘Exists’ : True, ‘DirID’ : directory id } ) if the directory exists
findDir(path, connection=False)

Find directory ID for the given path

:param path : path of the directory

Returns:S_OK(id) and res[‘Level’] as the depth
findDirs(paths, connection=False)

Find DirIDs for the given path list

Parameters:paths – list of path
Returns:S_OK( { path : ID} )
getAllSubdirectoriesByID(dirIdList)

Get IDs of all the subdirectories of directories in a given list

:param dirList : list of dir Ids :returns: S_OK([ unordered dir ids ])

getChildren(path, connection=False)

Get child directory IDs for the given directory

getDirectoryCounters(connection=False)

Get the total number of directories

getDirectoryParameters(pathOrDirId)

Get parameters of the given directory

:param pathOrDirID : the path or the id of the directory

Returns S_OK(dict), where dict has the following keys:
 “DirID”, “UID”, “Owner”, “GID”, “OwnerGroup”, “Status”, “Mode”, “CreationDate”, “ModificationDate”
getDirectoryPath(dirID)

Get directory name by directory ID

:param dirID : directory ID

Returns:S_OK(dir name), or S_ERROR if it does not exist
getDirectoryPaths(dirIDList)

Get directory names by directory ID list :param dirIDList : list of dirIds :returns S_OK( { dirID : dirName} )

getDirectoryPermissions(path, credDict)

Get permissions for the given user/group to manipulate the given directory

getDirectoryReplicas(lfns, allStatus=False)

Get replicas for files in the given directories

getDirectorySize(lfns, longOutput=False, rawFileTables=False)

Get the total size of the requested directories. If long flag is True, get also physical size per Storage Element

getFileIDsInDirectoryWithLimits(dirID, credDict, startItem=1, maxItems=25)

Get file IDs for the given directory

getFileLFNsInDirectory(dirID, credDict)

Get file lfns for the given directory or directory list

getFileLFNsInDirectoryByDirectory(dirID, credDict)

Get file lfns for the given directory or directory list

getPathIDs(path)

Get IDs of all the directories in the parent hierarchy for a directory specified by its path, including itself

:param path : path of the directory

Returns:S_OK( list of ids ), S_ERROR if not found
getPathIDsByID(dirID)

Get IDs of all the directories in the parent hierarchy for a directory specified by its ID, including itself

:param dirID : id of the dictionary

Returns:S_OK( list of ids )
getPathPermissions(lfns, credDict)

Get permissions for the given user/group to manipulate the given lfns

getSubdirectories(path)

Get subdirectories of the given directory

:param path : path of the directory

Returns:S_OK ( { dirID, depth } )
getSubdirectoriesByID(dirID, requestString=False, includeParent=False)

Get all the subdirectories of the given directory at a given level

:param dirID : id of the directory :param requestString : if true, returns an sql query to get the information :param includeParent : if true, the parent (dirID) will be included

Returns:S_OK ( { dirID, depth } ) if requestString is False S_OK(request) if requestString is True
getTreeTable()

Get the string of the Directory Tree type

isDirectory(paths)

Checking for existence of directories

isEmpty(path)

Find out if the given directory is empty

Rem: the speed could be enhanced if we were joining the FC_Files and FC_Directory* in the query.
For the time being, it can stay like this

:param path : path of the directory

Returns:S_OK(true) if there are no file nor directorie, S_OK(False) otherwise
listDirectory(lfns, verbose=False)

Get the directory listing

makeDir(path)
makeDirectories(path, credDict)

Make all the directories recursively in the path. The return value is the dictionary containing all the parameters of the newly created directory

makeDirectory(path, credDict, status=1)

Create a directory

:param path : has to be an absolute path. The parent dir has to exist :param credDict : credential dict of the owner of the directory :param: status ????

Returns:S_OK (dirID) with a flag res[‘NewDirectory’] to True or False S_ERROR if there is a problem, or if there is no parent
removeDir(path)

Remove directory

Removing a non existing directory is successful. In that case, DirID is 0

:param path : path of the dir

Returns:S_OK() and res[‘DirID’] the id of the directory removed
removeDirectory(dirs, force=False)

Remove an empty directory from the catalog

setDatabase(database)
setDirectoryStatus(path, status)

set the directory status