예제 #1
0
 def ParseOptions(self):
     (self.options_, self.args_) = self.parser_.parse_args()
     if self.options_.remoteCopy == None:
         self.remoteOutputDir_ = ""
     else:
         # removing possible trailing slash
         self.remoteOutputDir_ = self.options_.remoteCopy.rstrip('/')
         if "psi.ch" in self.remoteOutputDir_:  # T3 @ PSI:
             # overwriting protection to be improved
             if self.remoteOutputDir_.startswith("/pnfs/psi.ch"):
                 ld_lib_path = os.environ.get('LD_LIBRARY_PATH')
                 if ld_lib_path != "None":
                     os.environ[
                         'LD_LIBRARY_PATH'] = "/usr/lib64/:" + ld_lib_path  # to solve gfal conflict with CMSSW
                 os.system("gfal-mkdir srm://t3se01.psi.ch/" +
                           self.remoteOutputDir_)
                 outputDir = self.options_.outputDir
                 if outputDir == None:
                     today = datetime.today()
                     outputDir = 'OutCmsBatch_%s' % today.strftime(
                         "%d%h%y_%H%M")
                 self.remoteOutputDir_ += "/" + outputDir
                 os.system("gfal-mkdir srm://t3se01.psi.ch/" +
                           self.remoteOutputDir_)
                 if ld_lib_path != "None":
                     os.environ[
                         'LD_LIBRARY_PATH'] = ld_lib_path  # back to original to avoid conflicts
             else:
                 print "remote directory must start with /pnfs/psi.ch to send to the tier3 at PSI"
                 print self.remoteOutputDir_, "not valid"
                 sys.exit(1)
         else:  # assume EOS
             import eostools as castortools
             if not castortools.isLFN(self.remoteOutputDir_):
                 print 'When providing an output directory, you must give its LFN, starting by /store. You gave:'
                 print self.remoteOutputDir_
                 sys.exit(1)
             self.remoteOutputDir_ = castortools.lfnToEOS(
                 self.remoteOutputDir_)
             dirExist = castortools.isDirectory(self.remoteOutputDir_)
             # nsls = 'nsls %s > /dev/null' % self.remoteOutputDir_
             # dirExist = os.system( nsls )
             if dirExist is False:
                 print 'creating ', self.remoteOutputDir_
                 if castortools.isEOSFile(self.remoteOutputDir_):
                     # the output directory is currently a file..
                     # need to remove it.
                     castortools.rm(self.remoteOutputDir_)
                 castortools.createEOSDir(self.remoteOutputDir_)
             else:
                 # directory exists.
                 if self.options_.negate is False and self.options_.force is False:
                     #COLIN need to reimplement protectedRemove in eostools
                     raise ValueError(' '.join([
                         'directory ', self.remoteOutputDir_,
                         ' already exists.'
                     ]))
     self.remoteOutputFile_ = ""
     return (self.options_, self.args_)
예제 #2
0
    def ParseOptions(self):
        (self.options_,self.args_) = self.parser_.parse_args()
        if self.options_.remoteCopy == None:
            self.remoteOutputDir_ = ""
        else:
            # removing possible trailing slash
            self.remoteOutputDir_ = self.options_.remoteCopy.rstrip('/')
            if "psi.ch" in self.remoteOutputDir_: # T3 @ PSI:
                # overwriting protection to be improved
                if self.remoteOutputDir_.startswith("/pnfs/psi.ch"):
                    ld_lib_path = os.environ.get('LD_LIBRARY_PATH')
                    if ld_lib_path != "None":
                        os.environ['LD_LIBRARY_PATH'] = "/usr/lib64/:"+ld_lib_path  # to solve gfal conflict with CMSSW
                    os.system("gfal-mkdir srm://t3se01.psi.ch/"+self.remoteOutputDir_)
                    outputDir = self.options_.outputDir
                    if outputDir==None:
                        today = datetime.today()
                        outputDir = 'OutCmsBatch_%s' % today.strftime("%d%h%y_%H%M")
                    self.remoteOutputDir_+="/"+outputDir
                    os.system("gfal-mkdir srm://t3se01.psi.ch/"+self.remoteOutputDir_)
                    if ld_lib_path != "None":
                        os.environ['LD_LIBRARY_PATH'] = ld_lib_path  # back to original to avoid conflicts
                else:
                    print "remote directory must start with /pnfs/psi.ch to send to the tier3 at PSI"
                    print self.remoteOutputDir_, "not valid"
                    sys.exit(1)
            else: # assume EOS
                if not castortools.isLFN( self.remoteOutputDir_ ):
                    print 'When providing an output directory, you must give its LFN, starting by /store. You gave:'
                    print self.remoteOutputDir_
                    sys.exit(1)
                self.remoteOutputDir_ = castortools.lfnToEOS( self.remoteOutputDir_ )
                dirExist = castortools.isDirectory( self.remoteOutputDir_ )
                # nsls = 'nsls %s > /dev/null' % self.remoteOutputDir_
                # dirExist = os.system( nsls )
                if dirExist is False:
                    print 'creating ', self.remoteOutputDir_
                    if castortools.isEOSFile( self.remoteOutputDir_ ):
                        # the output directory is currently a file..
                        # need to remove it.
                        castortools.rm( self.remoteOutputDir_ )
                    castortools.createEOSDir( self.remoteOutputDir_ )
                else:
                    # directory exists.
                    if self.options_.negate is False and self.options_.force is False:
                        #COLIN need to reimplement protectedRemove in eostools
                        raise ValueError(  ' '.join(['directory ', self.remoteOutputDir_, ' already exists.']))
                    # if not castortools.protectedRemove( self.remoteOutputDir_, '.*root'):
                    # the user does not want to delete the root files

        self.remoteOutputFile_ = ""
        self.ManageOutputDir()
        return (self.options_, self.args_)
예제 #3
0
 def run(self, input):
     if self.user == 'CMS':
         return {'Topdir':None,'Directory':None}
     topdir = castortools.lfnToCastor(castorBaseDir(user=self.user))
     directory = '%s/%s' % (topdir,self.dataset)
     # directory = directory.replace('//','/')
     if not castortools.fileExists(directory):
         if hasattr(self,'create') and self.create:
             castortools.createCastorDir(directory)
             #castortools.chmod(directory,'775')
     if not castortools.isDirectory(directory): 
         raise Exception("Dataset directory '%s' does not exist or could not be created" % directory)
     return {'Topdir':topdir,'Directory':directory}  
예제 #4
0
 def run(self, input):
     if self.user == 'CMS':
         return {'Topdir':None,'Directory':None}
     topdir = castortools.lfnToCastor(castorBaseDir(user=self.user))
     directory = '%s/%s' % (topdir,self.dataset)
     # directory = directory.replace('//','/')
     if not castortools.fileExists(directory):
         if hasattr(self,'create') and self.create:
             castortools.createCastorDir(directory)
             #castortools.chmod(directory,'775')
     if not castortools.isDirectory(directory): 
         raise Exception("Dataset directory '%s' does not exist or could not be created" % directory)
     return {'Topdir':topdir,'Directory':directory}  
예제 #5
0
def castorBaseDir( user=os.environ['USER'], area = None):
    """Gets the top level directory to use for writing for 'user'"""
    
    if area is None:
        user, area = getUserAndArea(user)
    
    d = 'root://eoscms.cern.ch//eos/cms/store/cmst3/%s/%s/CMG' % (area,user)
    exists = castortools.isDirectory( castortools.lfnToCastor(d) )
    if exists:
        return d
    else:
        msg = "The directory '%s' does not exist. Please check the username and area (user/group). You may need to create the directory yourself." % d
        print >> sys.stderr, msg
        raise NameError(msg)