ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/LFNBaseName.py
(Generate patch)

Comparing COMP/CRAB/python/LFNBaseName.py (file contents):
Revision 1.10 by fanzago, Wed Aug 20 12:43:43 2008 UTC vs.
Revision 1.24 by spiga, Wed Sep 30 10:32:21 2009 UTC

# Line 4 | Line 4 | _LFNBaseName_
4   """
5  
6   from crab_exceptions import *
7 < from crab_util import runCommand
7 > from crab_util import runCommand, getUserName
8   import common
9 < import os, string
10 < from ProdCommon.SiteDB.SiteDB import SiteDBJSON
9 > import os, string, time
10  
11  
12 < def LFNBase(PrimaryDataset,ProcessedDataset,merged=True,LocalUser=False):
12 > def LFNBase(forced_path, PrimaryDataset='',ProcessedDataset='',merged=True,publish=False):
13      """
14      """
16    lfnbase = "/store"
17    if not merged:
18        lfnbase = os.path.join(lfnbase,"tmp")
19    #lfnbase = os.path.join(lfnbase, "user", getUserName(LocalUser=LocalUser), ProcessedDataset )
20    ### FEDE FOR NEW LFN ###
15      if (PrimaryDataset == 'null'):
16          PrimaryDataset = ProcessedDataset
17 <    lfnbase = os.path.join(lfnbase, "user", getUserName(LocalUser=LocalUser), PrimaryDataset, ProcessedDataset )
18 <    ########################
19 <
17 >    if PrimaryDataset != '':
18 >        if ( PrimaryDataset[0] == '/' ):  PrimaryDataset=PrimaryDataset[1:]  
19 >    if forced_path.find('store/group')>0:
20 >        lfnbase = os.path.join(forced_path, PrimaryDataset, ProcessedDataset)
21 >    else:
22 >        lfnbase = os.path.join(forced_path, getUserName(), PrimaryDataset, ProcessedDataset)
23 >    if (publish == True):
24 >        checkLength(lfnbase, forced_path, PrimaryDataset, ProcessedDataset)
25      return lfnbase
26  
27 < def PFNportion(PrimaryDataset,ProcessedDataset,LocalUser=False):
28 <    ### FEDE FOR NEW LFN ###
29 <    #pfnpath = os.path.join(getUserName(LocalUser=LocalUser), ProcessedDataset )
30 <    pfnpath = os.path.join(getUserName(LocalUser=LocalUser), PrimaryDataset, ProcessedDataset )
31 <    ########################
32 <    return pfnpath
33 <
34 < def getUnixUserName():
35 <    """
36 <    extract username from whoami
37 <    """
38 <    try:
39 <        UserName = runCommand("whoami")
40 <        UserName = string.strip(UserName)
41 <    except:
42 <        msg = "Error. Problem with whoami command"
43 <        raise CrabException(msg)
44 <    return UserName
45 <
46 < def getDN():
47 <    """
48 <    extract DN from user proxy's identity
49 <    """
50 <    try:
51 <        userdn = runCommand("voms-proxy-info -identity")
52 <        userdn = string.strip(userdn)
53 <        #search for a / to avoid picking up warning messages
54 <        userdn = userdn[userdn.find('/'):]
55 <    except:
56 <        msg = "Error. Problem with voms-proxy-info -identity command"
57 <        raise CrabException(msg)
58 <    return userdn.split('\n')[0]
59 <
60 < def gethnUserName():
61 <    """
62 <    extract user name from SiteDB
63 <    """
64 <    hnUserName = None
65 <    userdn = getDN()
66 <    mySiteDB = SiteDBJSON()
67 <
68 <    try:
69 <        hnUserName = mySiteDB.dnUserName(dn=userdn)
70 <    except:
72 <        msg = "Error. Problem extracting user name from SiteDB"
73 <        msg += "\n Check that you are registered in SiteDB, see https://twiki.cern.ch/twiki/bin/view/CMS/SiteDBForCRAB"
74 <        raise CrabException(msg)
75 <    if not hnUserName:
76 <        msg = "Error. There is no user name associated to DN %s in SiteDB. You need to register in SiteDB with the instructions at https://twiki.cern.ch/twiki/bin/view/CMS/SiteDBForCRAB" % userdn
77 <        print msg
78 <        raise CrabException(msg)
79 <    return hnUserName
80 <
81 < def getUserName(LocalUser=False):
82 <    """
83 <    extract user name from either SiteDB or Unix
84 <    """
85 <    if LocalUser:
86 <       common.logger.message("==> Using as username the Unix user name")
87 <       UserName=getUnixUserName()
88 <       return UserName
89 <
90 <    UserName=gethnUserName()
91 <    return UserName
27 > def checkLength(lfnbase, forced_path, PrimaryDataset, ProcessedDataset):
28 >    """
29 >    """
30 >    
31 >    len_primary = len(PrimaryDataset)
32 >    
33 >    common.logger.debug("CheckLength of LFN and User DatasetName")
34 >    common.logger.debug("max length for complete LFN is 500 characters, max length for primary dataset is 100 characters")
35 >    common.logger.debug("PrimaryDataset = " + PrimaryDataset)
36 >    common.logger.debug("len_primary = " + str(len_primary))
37 >
38 >    if (len_primary > 100):
39 >       raise CrabException("Warning: you required user_data_publication. The PrimaryDatasetName has to be < 100 characters")
40 >    
41 >    if (PrimaryDataset != ProcessedDataset):
42 >        common.logger.debug("ProcessedDataset = " + ProcessedDataset)
43 >        common.logger.debug("len(ProcessedDataset) = " + str(len(ProcessedDataset)))
44 >
45 >    common.logger.debug("forced_path = " + forced_path)
46 >    common.logger.debug("len(forced_path) = " + str(len(forced_path)))    
47 >    
48 >    user = getUserName()
49 >    len_user_name = len(user)
50 >    common.logger.debug("user = " + user)
51 >    common.logger.debug("len_user_name = " + str(len_user_name))
52 >    
53 >    common.logger.debug("lfnbase = " + lfnbase)
54 >    common.logger.debug("len(lfnbase) = " + str(len(lfnbase)))
55 >    
56 >    ### we suppose a output_file_name of 50 characters ###
57 >    if len(lfnbase)>450:
58 >        if (PrimaryDataset != ProcessedDataset):
59 >            #500 - len_user_name - len_primary - len(forced) - len(PSETHASH = 32) - 4(/) - output(50)
60 >            #~400 - len_user_name - len_primary - len(forced)
61 >            if (len(ProcessedDataset) > (400 - len_user_name - len_primary - len(forced_path))):
62 >                raise CrabException("Warning: publication name too long. USER.publish_data_name has to be < " + str(400 - len_user_name - len_primary - len(forced_path)) + " characters")
63 >            else:
64 >                raise CrabException("Warning: LFN > 500 characters")
65 >        else:
66 >            if (len(ProcessedDataset) > (400 - len_user_name - len(forced_path)) / 2):
67 >                raise CrabException("Warning: publication name too long. USER.publish_data_name has to be < " + str((400 - len_user_name - len(forced_path)) / 2) + " characters")
68 >            else:
69 >                raise CrabException("Warning: LFN > 500 characters")
70 >            
71  
72   if __name__ == '__main__' :
73      """
74      """
75 <    from crab_logger import Logger
76 <    from WorkSpace import *
98 <    continue_dir = os.path.expanduser("~")
99 <    cfg_params={'USER.logdir' : continue_dir }
100 <    common.work_space = WorkSpace(continue_dir, cfg_params)
101 <    log = Logger()
102 <    common.logger = log
75 >    import logging
76 >    common.logger = logging
77  
78      print "xx %s xx"%getUserName()
79      baselfn = LFNBase("datasetstring")

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines