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.3 by slacapra, Fri Apr 11 14:54:22 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):
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 <    
19 <    lfnbase = os.path.join(lfnbase, "user", gethnUserName(), ProcessedDataset )
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):
25 <    pfnpath = os.path.join(gethnUserName(), ProcessedDataset )
26 <    return pfnpath
27 <
28 < 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 <    except:
36 <        msg = "Error. Problem with voms-proxy-info -identity command"
37 <        raise CrabException(msg)
38 <    return userdn
39 <
40 < def gethnUserName():
41 <    """
42 <    extract user name from SiteDB
43 <    """
44 <    import urllib
45 <    hnUserName = None
46 <    userdn = getDN()
47 <    try:
48 <        sitedburl="https://cmsweb.cern.ch/sitedb/sitedb/json/index/dnUserName"
49 <        params = urllib.urlencode({'dn': userdn })
50 <        f = urllib.urlopen(sitedburl,params)
51 <        udata = f.read()
52 <        try:
53 <            userinfo= eval(udata)
54 <        except StandardError, ex:
55 <            msg = "Error. Problem extracting user name from %s : %s"%(sitedburl,ex)
56 <            raise CrabException(msg)
57 <        hnUserName = userinfo['user']
58 <    except:
59 <        msg = "Error. Problem extracting user name from %s"%sitedburl
60 <        msg += "Check that you are registered in SiteDB, see https://twiki.cern.ch/twiki/bin/view/CMS/SiteDBForCRAB"
61 <        raise CrabException(msg)
62 <    if not hnUserName:
63 <        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)
64 <        print msg
65 <        raise CrabException(msg)
66 <    return hnUserName
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 >    ### 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 *
71 <    continue_dir="/bohome/fanfani/CRAB"
72 <    cfg_params={'USER.logdir' : continue_dir }
73 <    common.work_space = WorkSpace(continue_dir, cfg_params)
74 <    log = Logger()
75 <    common.logger = log
72 >    import logging
73 >    common.logger = logging
74  
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