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.16 by fanzago, Thu Oct 23 17:07:22 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, UnixUserName
7 > from crab_util import runCommand, getUserName
8   import common
9   import os, string, time
10 from ProdCommon.SiteDB.SiteDB import SiteDBJSON
10  
11  
12 < def LFNBase(lfn, PrimaryDataset='',ProcessedDataset='',merged=True,LocalUser=False,publish=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")
15      if (PrimaryDataset == 'null'):
16          PrimaryDataset = ProcessedDataset
17 <   # lfnbase = os.path.join(lfnbase, "user", getUserName(LocalUser=LocalUser), PrimaryDataset, ProcessedDataset )
18 <    lfnbase = os.path.join(lfn, getUserName(LocalUser=LocalUser), PrimaryDataset, ProcessedDataset)
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 getUnixUserName():
27 <    """
28 <    extract username from whoami
27 > def checkLength(lfnbase, forced_path, PrimaryDataset, ProcessedDataset):
28      """
30    return UnixUserName()
31
32 def getDN():
29      """
30 <    extract DN from user proxy's identity
31 <    """
32 <    try:
33 <        userdn = runCommand("voms-proxy-info -identity")
34 <        userdn = string.strip(userdn)
35 <        #search for a / to avoid picking up warning messages
36 <        userdn = userdn[userdn.find('/'):]
37 <    except:
38 <        msg = "Error. Problem with voms-proxy-info -identity command"
39 <        raise CrabException(msg)
40 <    return userdn.split('\n')[0]
41 <
42 < def gethnUserNameFromSiteDB():
43 <    """
44 <    extract user name from SiteDB
45 <    """
46 <    hnUserName = None
47 <    userdn = getDN()
48 <    mySiteDB = SiteDBJSON()
49 <    try:
50 <        hnUserName = mySiteDB.dnUserName(dn=userdn)
51 <    except:
52 <        msg = "Error. Problem extracting user name from SiteDB"
53 <        msg += "\n Check that you are registered in SiteDB, see https://twiki.cern.ch/twiki/bin/view/CMS/SiteDBForCRAB"
54 <        raise CrabException(msg)
55 <    if not hnUserName:
56 <        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
57 <        print msg
58 <        raise CrabException(msg)
59 <    return hnUserName
60 <
61 <
62 < def gethnUserName():
63 <    """
64 <    cache the username extracted from SiteDB for 24hours
69 <    """
70 <    userconfigFileName="SiteDBusername.conf"
71 <    if not os.path.exists(userconfigFileName):
72 <        common.logger.debug(5,"Downloading from SiteDB username into %s"%userconfigFileName)
73 <        nameuser = gethnUserNameFromSiteDB()
74 <        userfile = open(userconfigFileName, 'w')
75 <        userfile.write(nameuser)
76 <        userfile.close()
77 <    else:
78 <        statinfo = os.stat(userconfigFileName)
79 <        ## if the file is older then 24 hours it is re-downloaded to update the configuration
80 <        oldness = 24*3600
81 <        if (time.time() - statinfo.st_ctime) > oldness:
82 <           common.logger.debug(5,"Downloading from SiteDB username into %s"%userconfigFileName)
83 <           nameuser = gethnUserNameFromSiteDB()
84 <           userfile = open(userconfigFileName, 'w')
85 <           userfile.write(nameuser)
86 <           userfile.close()
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 <           userfile = open(userconfigFileName, 'r')
67 <           for line in userfile.readlines():
68 <               nameuser = line
69 <           userfile.close()
70 <           nameuser = string.strip(nameuser)
93 <    return nameuser  
94 <
95 < def getUserName(LocalUser=False):
96 <    """
97 <    extract user name from either SiteDB or Unix
98 <    """
99 <    if LocalUser:
100 <       common.logger.debug(10,"Using as username the Unix user name")
101 <       UserName=getUnixUserName()
102 <       return UserName
103 <
104 <    UserName=gethnUserName()
105 <    return UserName
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 *
112 <    continue_dir = os.path.expanduser("~")
113 <    cfg_params={'USER.logdir' : continue_dir }
114 <    common.work_space = WorkSpace(continue_dir, cfg_params)
115 <    log = Logger()
116 <    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