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.20 by spiga, Thu Jan 22 18:19:14 2009 UTC vs.
Revision 1.23 by fanzago, Fri Jul 31 16:21:12 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 WMCore.Services.SiteDB.SiteDB import SiteDBJSON
10  
11  
12 < def LFNBase(forced_path, 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      if PrimaryDataset != '':
18          if ( PrimaryDataset[0] == '/' ):  PrimaryDataset=PrimaryDataset[1:]  
19 <   # lfnbase = os.path.join(lfnbase, "user", getUserName(LocalUser=LocalUser), PrimaryDataset, ProcessedDataset )
20 <    lfnbase = os.path.join(forced_path, getUserName(LocalUser=LocalUser), PrimaryDataset, ProcessedDataset)
21 <
19 >    lfnbase = os.path.join(forced_path, getUserName(), PrimaryDataset, ProcessedDataset)
20 >    if (publish == True):
21 >        checkLength(lfnbase, forced_path, PrimaryDataset, ProcessedDataset)
22      return lfnbase
23  
24 < def getUnixUserName():
29 <    """
30 <    extract username from whoami
24 > def checkLength(lfnbase, forced_path, PrimaryDataset, ProcessedDataset):
25      """
32    return UnixUserName()
33
34 def getDN():
26      """
27 <    extract DN from user proxy's identity
28 <    """
29 <    try:
30 <        userdn = runCommand("voms-proxy-info -identity")
31 <        userdn = string.strip(userdn)
32 <        #search for a / to avoid picking up warning messages
33 <        userdn = userdn[userdn.find('/'):]
34 <    except:
35 <        msg = "Error. Problem with voms-proxy-info -identity command"
36 <        raise CrabException(msg)
37 <    return userdn.split('\n')[0]
38 <
39 < def gethnUserNameFromSiteDB():
40 <    """
41 <    extract user name from SiteDB
42 <    """
43 <    hnUserName = None
44 <    userdn = getDN()
45 <    mySiteDB = SiteDBJSON()
46 <    try:
47 <        hnUserName = mySiteDB.dnUserName(dn=userdn)
48 <    except:
49 <        msg = "Error. Problem extracting user name from SiteDB"
50 <        msg += "\n Check that you are registered in SiteDB, see https://twiki.cern.ch/twiki/bin/view/CMS/SiteDBForCRAB"
51 <        raise CrabException(msg)
52 <    if not hnUserName:
53 <        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
54 <        print msg
55 <        raise CrabException(msg)
56 <    return hnUserName
57 <
58 <
59 < def gethnUserName():
60 <    """
61 <    cache the username extracted from SiteDB for 24hours
71 <    """
72 <    userconfigFileName="SiteDBusername.conf"
73 <    if not os.path.exists(userconfigFileName):
74 <        common.logger.debug(5,"Downloading from SiteDB username into %s"%userconfigFileName)
75 <        nameuser = gethnUserNameFromSiteDB()
76 <        userfile = open(userconfigFileName, 'w')
77 <        userfile.write(nameuser)
78 <        userfile.close()
79 <    else:
80 <        statinfo = os.stat(userconfigFileName)
81 <        ## if the file is older then 24 hours it is re-downloaded to update the configuration
82 <        oldness = 24*3600
83 <        if (time.time() - statinfo.st_ctime) > oldness:
84 <           common.logger.debug(5,"Downloading from SiteDB username into %s"%userconfigFileName)
85 <           nameuser = gethnUserNameFromSiteDB()
86 <           userfile = open(userconfigFileName, 'w')
87 <           userfile.write(nameuser)
88 <           userfile.close()
27 >    
28 >    len_primary = len(PrimaryDataset)
29 >    
30 >    common.logger.debug("CheckLength of LFN and User DatasetName")
31 >    common.logger.debug("max length for complete LFN is 500 characters, max length for primary dataset is 100 characters")
32 >    common.logger.debug("PrimaryDataset = " + PrimaryDataset)
33 >    common.logger.debug("len_primary = " + str(len_primary))
34 >
35 >    if (len_primary > 100):
36 >       raise CrabException("Warning: you required user_data_publication. The PrimaryDatasetName has to be < 100 characters")
37 >    
38 >    if (PrimaryDataset != ProcessedDataset):
39 >        common.logger.debug("ProcessedDataset = " + ProcessedDataset)
40 >        common.logger.debug("len(ProcessedDataset) = " + str(len(ProcessedDataset)))
41 >
42 >    common.logger.debug("forced_path = " + forced_path)
43 >    common.logger.debug("len(forced_path) = " + str(len(forced_path)))    
44 >    
45 >    user = getUserName()
46 >    len_user_name = len(user)
47 >    common.logger.debug("user = " + user)
48 >    common.logger.debug("len_user_name = " + str(len_user_name))
49 >    
50 >    common.logger.debug("lfnbase = " + lfnbase)
51 >    common.logger.debug("len(lfnbase) = " + str(len(lfnbase)))
52 >    
53 >    ### we suppose a output_file_name of 50 characters ###
54 >    if len(lfnbase)>450:
55 >        if (PrimaryDataset != ProcessedDataset):
56 >            #500 - len_user_name - len_primary - len(forced) - len(PSETHASH = 32) - 4(/) - output(50)
57 >            #~400 - len_user_name - len_primary - len(forced)
58 >            if (len(ProcessedDataset) > (400 - len_user_name - len_primary - len(forced_path))):
59 >                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")
60 >            else:
61 >                raise CrabException("Warning: LFN > 500 characters")
62          else:
63 <           userfile = open(userconfigFileName, 'r')
64 <           for line in userfile.readlines():
65 <               nameuser = line
66 <           userfile.close()
67 <           nameuser = string.strip(nameuser)
95 <    return nameuser
96 <
97 < def getUserName(LocalUser=False):
98 <    """
99 <    extract user name from either SiteDB or Unix
100 <    """
101 <    if LocalUser:
102 <       common.logger.debug(10,"Using as username the Unix user name")
103 <       UserName=getUnixUserName()
104 <       return UserName
105 <
106 <    UserName=gethnUserName()
107 <    return UserName
63 >            if (len(ProcessedDataset) > (400 - len_user_name - len(forced_path)) / 2):
64 >                raise CrabException("Warning: publication name too long. USER.publish_data_name has to be < " + str((400 - len_user_name - len(forced_path)) / 2) + " characters")
65 >            else:
66 >                raise CrabException("Warning: LFN > 500 characters")
67 >            
68  
69   if __name__ == '__main__' :
70      """
71      """
72 <    from crab_logger import Logger
73 <    from WorkSpace import *
114 <    continue_dir = os.path.expanduser("~")
115 <    cfg_params={'USER.logdir' : continue_dir }
116 <    common.work_space = WorkSpace(continue_dir, cfg_params)
117 <    log = Logger()
118 <    common.logger = log
72 >    import logging
73 >    common.logger = logging
74  
75      print "xx %s xx"%getUserName()
76      baselfn = LFNBase("datasetstring")

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines