Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:23:30

0001 #!/usr/bin/env python
0002 from __future__ import print_function
0003 from __future__ import absolute_import
0004 import os, sys
0005 from . import eostools as castortools
0006 
0007 def getUserAndArea(user):
0008     """Factor out the magic user hack for use in other classes"""
0009     
0010     area = 'user'
0011     
0012     tokens = user.split('_')
0013     if tokens and len(tokens) > 1:
0014         user = tokens[0]
0015         area = tokens[1]
0016     return user, area
0017 
0018 def castorBaseDir( user=os.environ['USER'], area = None):
0019     """Gets the top level directory to use for writing for 'user'"""
0020     
0021     if area is None:
0022         user, area = getUserAndArea(user)
0023     
0024     d = 'root://eoscms.cern.ch//eos/cms/store/cmst3/%s/%s/CMG' % (area,user)
0025     exists = castortools.isDirectory( castortools.lfnToCastor(d) )
0026     if exists:
0027         return d
0028     else:
0029         msg = "The directory '%s' does not exist. Please check the username and area (user/group). You may need to create the directory yourself." % d
0030         print(msg, file=sys.stderr)
0031         raise NameError(msg)
0032 
0033 def myCastorBaseDir():
0034     """Gets the top level directory to use for writing for the current user"""
0035     return castorBaseDir()