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.6 by afanfani, Wed May 28 18:18:05 2008 UTC vs.
Revision 1.25 by fanzago, Mon Oct 12 10:03:13 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
9 > import os, string, time
10  
11  
12 < def LFNBase(ProcessedDataset,merged=True,LocalUser=False):
12 > def LFNBase(forced_path, PrimaryDataset='',ProcessedDataset='',merged=True,publish=False):
13      """
14      """
15 <    lfnbase = "/store"
16 <    if not merged:
17 <        lfnbase = os.path.join(lfnbase,"tmp")  
18 <    lfnbase = os.path.join(lfnbase, "user", getUserName(LocalUser=LocalUser), ProcessedDataset )
19 <      
15 >    if (PrimaryDataset == 'null'):
16 >        PrimaryDataset = ProcessedDataset
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 >        checkSlash(ProcessedDataset)
25 >        checkLength(lfnbase, forced_path, PrimaryDataset, ProcessedDataset)
26      return lfnbase
27  
28 < def PFNportion(ProcessedDataset,LocalUser=False):
29 <    pfnpath = os.path.join(getUserName(LocalUser=LocalUser), ProcessedDataset )
30 <    return pfnpath
31 <
32 < def getUnixUserName():
33 <    """
34 <    extract username from whoami
35 <    """
36 <    try:
37 <        UserName = runCommand("whoami")
38 <        UserName = string.strip(UserName)
39 <    except:
40 <        msg = "Error. Problem with whoami command"
41 <        raise CrabException(msg)
42 <    return UserName
43 <
44 < def getDN():
45 <    """
46 <    extract DN from user proxy's identity
47 <    """
48 <    try:
49 <        userdn = runCommand("voms-proxy-info -identity")
50 <        userdn = string.strip(userdn)
51 <    except:
52 <        msg = "Error. Problem with voms-proxy-info -identity command"
53 <        raise CrabException(msg)
54 <    return userdn
55 <
56 < def gethnUserName():
57 <    """
58 <    extract user name from SiteDB
59 <    """
60 <    import urllib
61 <    hnUserName = None
62 <    userdn = getDN()
63 <    try:
58 <        sitedburl="https://cmsweb.cern.ch/sitedb/sitedb/json/index/dnUserName"
59 <        params = urllib.urlencode({'dn': userdn })
60 <        f = urllib.urlopen(sitedburl,params)
61 <        udata = f.read()
62 <        try:
63 <            userinfo= eval(udata)
64 <        except StandardError, ex:
65 <            msg = "Error. Problem extracting user name from %s : %s \n SiteDB call output: \n %s"%(sitedburl,ex,udata)
66 <            raise CrabException(msg)
67 <        hnUserName = userinfo['user']
68 <    except:
69 <        msg = "Error. Problem extracting user name from %s "%sitedburl
70 <        msg += "\n Check that you are registered in SiteDB, see https://twiki.cern.ch/twiki/bin/view/CMS/SiteDBForCRAB"
71 <        msg += "\n SiteDB call output: \n %s"%udata
72 <        raise CrabException(msg)
73 <    if not hnUserName:
74 <        msg = "Error. There is no user name associated to DN %s in %s. You need to register in SiteDB with the instructions at https://twiki.cern.ch/twiki/bin/view/CMS/SiteDBForCRAB"%(userdn,sitedburl)
75 <        print msg
76 <        raise CrabException(msg)
77 <    return hnUserName
78 <
79 < def getUserName(LocalUser=False):
80 <    """
81 <    extract user name from either SiteDB or Unix
82 <    """
83 <    if LocalUser:
84 <       common.logger.message("==> Using as username the Unix user name")
85 <       UserName=getUnixUserName()
86 <       return UserName
28 > def checkSlash(ProcessedDataset):
29 >    """
30 >    check if [USER].publish_data_name contains not allowed slash
31 >    """
32 >    
33 >    if (str(ProcessedDataset).find("/") > -1):
34 >            raise CrabException("Warning: [USER] publication_data_name contains a '/' characters that is not allowed. Please change the publication_data_name value")
35 >
36 > def checkLength(lfnbase, forced_path, PrimaryDataset, ProcessedDataset):
37 >    """
38 >    """
39 >    
40 >    len_primary = len(PrimaryDataset)
41 >    
42 >    common.logger.debug("CheckLength of LFN and User DatasetName")
43 >    common.logger.debug("max length for complete LFN is 500 characters, max length for primary dataset is 100 characters")
44 >    common.logger.debug("PrimaryDataset = " + PrimaryDataset)
45 >    common.logger.debug("len_primary = " + str(len_primary))
46 >
47 >    if (len_primary > 100):
48 >       raise CrabException("Warning: you required user_data_publication. The PrimaryDatasetName has to be < 100 characters")
49 >    
50 >    if (PrimaryDataset != ProcessedDataset):
51 >        common.logger.debug("ProcessedDataset = " + ProcessedDataset)
52 >        common.logger.debug("len(ProcessedDataset) = " + str(len(ProcessedDataset)))
53 >
54 >    common.logger.debug("forced_path = " + forced_path)
55 >    common.logger.debug("len(forced_path) = " + str(len(forced_path)))    
56 >    
57 >    user = getUserName()
58 >    len_user_name = len(user)
59 >    common.logger.debug("user = " + user)
60 >    common.logger.debug("len_user_name = " + str(len_user_name))
61 >    
62 >    common.logger.debug("lfnbase = " + lfnbase)
63 >    common.logger.debug("len(lfnbase) = " + str(len(lfnbase)))
64      
65 <    UserName=gethnUserName()
66 <    return UserName
65 >    ### we suppose a output_file_name of 50 characters ###
66 >    if len(lfnbase)>450:
67 >        if (PrimaryDataset != ProcessedDataset):
68 >            #500 - len_user_name - len_primary - len(forced) - len(PSETHASH = 32) - 4(/) - output(50)
69 >            #~400 - len_user_name - len_primary - len(forced)
70 >            if (len(ProcessedDataset) > (400 - len_user_name - len_primary - len(forced_path))):
71 >                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")
72 >            else:
73 >                raise CrabException("Warning: LFN > 500 characters")
74 >        else:
75 >            if (len(ProcessedDataset) > (400 - len_user_name - len(forced_path)) / 2):
76 >                raise CrabException("Warning: publication name too long. USER.publish_data_name has to be < " + str((400 - len_user_name - len(forced_path)) / 2) + " characters")
77 >            else:
78 >                raise CrabException("Warning: LFN > 500 characters")
79 >            
80  
81   if __name__ == '__main__' :
82      """
83      """
84 <    from crab_logger import Logger
85 <    from WorkSpace import *
96 <    continue_dir="/afs/cern.ch/user/a/afanfani/"
97 <    cfg_params={'USER.logdir' : continue_dir }
98 <    common.work_space = WorkSpace(continue_dir, cfg_params)
99 <    log = Logger()
100 <    common.logger = log
84 >    import logging
85 >    common.logger = logging
86  
87 <    print "xx %s xx"%getUserName()
87 >    print "xx %s xx"%getUserName()
88      baselfn = LFNBase("datasetstring")
89 <    print baselfn    
89 >    print baselfn
90  
91      unmergedlfn = LFNBase("datasetstring",merged=False)
92 <    print unmergedlfn  
92 >    print unmergedlfn
93      print PFNportion("datasetstring")

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines