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.5 by afanfani, Wed May 28 13:01:17 2008 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
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 >    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 PFNportion(ProcessedDataset,LocalUser=False):
25 <    pfnpath = os.path.join(getUserName(LocalUser=LocalUser), ProcessedDataset )
26 <    return pfnpath
27 <
28 < def getUnixUserName():
29 <    """
30 <    extract username from whoami
31 <    """
32 <    try:
33 <        UserName = runCommand("whoami")
34 <        UserName = string.strip(UserName)
35 <    except:
36 <        msg = "Error. Problem with whoami command"
37 <        raise CrabException(msg)
38 <    return UserName
39 <
40 < def getDN():
41 <    """
42 <    extract DN from user proxy's identity
43 <    """
44 <    try:
45 <        userdn = runCommand("voms-proxy-info -identity")
46 <        userdn = string.strip(userdn)
47 <    except:
48 <        msg = "Error. Problem with voms-proxy-info -identity command"
49 <        raise CrabException(msg)
50 <    return userdn
51 <
50 < def gethnUserName():
51 <    """
52 <    extract user name from SiteDB
53 <    """
54 <    import urllib
55 <    hnUserName = None
56 <    userdn = getDN()
57 <    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"%(sitedburl,ex)
66 <            raise CrabException(msg)
67 <        hnUserName = userinfo['user']
68 <    except:
69 <        msg = "Error. Problem extracting user name from %s"%sitedburl
70 <        msg += "Check that you are registered in SiteDB, see https://twiki.cern.ch/twiki/bin/view/CMS/SiteDBForCRAB"
71 <        raise CrabException(msg)
72 <    if not hnUserName:
73 <        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)
74 <        print msg
75 <        raise CrabException(msg)
76 <    return hnUserName
77 <
78 < def getUserName(LocalUser=False):
79 <    """
80 <    extract user name from either SiteDB or Unix
81 <    """
82 <    if LocalUser:
83 <       common.logger.message("==> Using as username the Unix user name")
84 <       UserName=getUnixUserName()
85 <       return UserName
24 > def checkLength(lfnbase, forced_path, PrimaryDataset, ProcessedDataset):
25 >    """
26 >    """
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 <    UserName=gethnUserName()
54 <    return UserName
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 >            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 *
95 <    continue_dir="/afs/cern.ch/user/a/afanfani/"
96 <    cfg_params={'USER.logdir' : continue_dir }
97 <    common.work_space = WorkSpace(continue_dir, cfg_params)
98 <    log = Logger()
99 <    common.logger = log
72 >    import logging
73 >    common.logger = logging
74  
75 <    print "xx %s xx"%getUserName()
75 >    print "xx %s xx"%getUserName()
76      baselfn = LFNBase("datasetstring")
77 <    print baselfn    
77 >    print baselfn
78  
79      unmergedlfn = LFNBase("datasetstring",merged=False)
80 <    print unmergedlfn  
80 >    print unmergedlfn
81      print PFNportion("datasetstring")

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines