Ejemplo n.º 1
0
def addUserToFC(clip):
    """
  Add the user to the filecatalog
  Try to figure out in which VOs the user must be, and create the catalog entries accordingly
  """
    from DIRAC.ConfigurationSystem.Client.Helpers import Registry
    from DIRAC.Resources.Catalog.FileCatalogClient import FileCatalogClient
    from DIRAC.ConfigurationSystem.Client.Helpers.Operations import Operations
    fc = FileCatalogClient()
    res = fc.addUser(clip.uname)
    if not res['OK']:
        gLogger.error(
            "Failed to add user to FC, but it does not really matter:",
            res['Message'])
        gLogger.error("Add by hand (in the FC-CLI: user add %s)" %
                      (clip.uname))

    bpath = ''
    for grp in clip.groups:
        bpath = '/'
        voName = Registry.getVOForGroup(grp)
        if not voName:
            gLogger.error("NO VO for group", grp)
            continue
        bpath += voName + "/"
        lfnprefix = Operations(vo=voName).getValue("LFNUserPrefix")
        if lfnprefix:
            bpath += lfnprefix + "/"
        bpath += clip.uname[0] + "/" + clip.uname

        res = fc.createDirectory(bpath)
        if not res['OK']:
            gLogger.error(res['Message'])
            continue

        res = fc.changePathGroup({bpath: grp}, False)
        if not res['OK']:
            gLogger.error(res['Message'])

        res = fc.changePathOwner({bpath: clip.uname}, False)
        if not res['OK']:
            gLogger.error(res['Message'])

        res = fc.setMetadata(bpath, {"Owner": clip.uname})
        if not res['OK']:
            gLogger.error(res['Message'])
Ejemplo n.º 2
0
def addUserToFC(clip):
  """
  Add the user to the filecatalog
  Try to figure out in which VOs the user must be, and create the catalog entries accordingly
  """
  from DIRAC.ConfigurationSystem.Client.Helpers  import Registry
  from DIRAC.Resources.Catalog.FileCatalogClient import FileCatalogClient
  from DIRAC.ConfigurationSystem.Client.Helpers.Operations import Operations
  fc = FileCatalogClient()
  res = fc.addUser(clip.uname)
  if not res['OK']:
    gLogger.error("Failed to add user to FC, but it does not really matter:", res['Message'])
    gLogger.error("Add by hand (in the FC-CLI: user add %s)" %(clip.uname) )

  bpath = ''
  for grp in clip.groups:
    bpath = '/'
    voName = Registry.getVOForGroup(grp)
    if not voName:
      gLogger.error("NO VO for group", grp )
      continue
    bpath += voName+"/"
    lfnprefix = Operations( vo = voName ).getValue("LFNUserPrefix")
    if lfnprefix:
      bpath += lfnprefix+"/"
    bpath += clip.uname[0]+"/"+clip.uname

    res = fc.createDirectory(bpath)
    if not res['OK']:
      gLogger.error(res['Message'])
      continue

    res = fc.changePathGroup({ bpath: grp }, False)
    if not res['OK']:
      gLogger.error(res['Message'])

    res = fc.changePathOwner({ bpath: clip.uname }, False)
    if not res['OK']:
      gLogger.error(res['Message'])

    res = fc.setMetadata(bpath, {"Owner":clip.uname})
    if not res['OK']:
      gLogger.error(res['Message'])
Ejemplo n.º 3
0
def chown(directories,
          user=None,
          group=None,
          mode=None,
          recursive=False,
          ndirs=None,
          fcClient=None):
    """
  This method may change the user, group or mode of a directory and apply it recursively if required
  """
    if ndirs is None:
        ndirs = 0
    if not directories:
        return S_OK(ndirs)
    if isinstance(directories, basestring):
        directories = directories.split(',')
    if fcClient is None:
        fcClient = FileCatalogClient()
    if user is not None:
        res = fcClient.changePathOwner(dict.fromkeys(directories, user))
        if not res['OK']:
            res = fcClient.changePathOwner(
                dict.fromkeys(directories, {'Owner': user}))
            if not res['OK']:
                return res
    if group is not None:
        res = fcClient.changePathGroup(dict.fromkeys(directories, group))
        if not res['OK']:
            res = fcClient.changePathGroup(
                dict.fromkeys(directories, {'Group': group}))
            if not res['OK']:
                return res
    if mode is not None:
        res = fcClient.changePathMode(dict.fromkeys(directories, mode))
        if not res['OK']:
            res = fcClient.changePathMode(
                dict.fromkeys(directories, {'Mode': mode}))
            if not res['OK']:
                return res
    if recursive:
        for subDir in directories:
            if ndirs % 10 == 0:
                sys.stdout.write('.')
                sys.stdout.flush()
            ndirs += 1
            res = fcClient.listDirectory(subDir)
            if res['OK']:
                subDirectories = res['Value']['Successful'][subDir]['SubDirs']
                if subDirectories:
                    # print subDir, len( subDirectories ), ndirs
                    res = chown(subDirectories,
                                user,
                                group=group,
                                mode=mode,
                                recursive=True,
                                ndirs=ndirs,
                                fcClient=fcClient)
                    if not res['OK']:
                        return res
                    ndirs = res['Value']
    else:
        ndirs += len(directories)
    return S_OK(ndirs)