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 |
> |
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 PFNportion(ProcessedDataset): |
28 |
< |
pfnpath = os.path.join(gethnUserName(), ProcessedDataset ) |
29 |
< |
return pfnpath |
30 |
< |
|
31 |
< |
def getDN(): |
32 |
< |
""" |
33 |
< |
extract DN from user proxy's identity |
34 |
< |
""" |
35 |
< |
try: |
36 |
< |
userdn = runCommand("voms-proxy-info -identity") |
37 |
< |
userdn = string.strip(userdn) |
38 |
< |
except: |
39 |
< |
msg = "Error. Problem with voms-proxy-info -identity command" |
40 |
< |
raise CrabException(msg) |
41 |
< |
return userdn |
42 |
< |
|
43 |
< |
def gethnUserName(): |
44 |
< |
""" |
45 |
< |
extract user name from SiteDB |
46 |
< |
""" |
47 |
< |
import urllib |
48 |
< |
hnUserName = None |
49 |
< |
userdn = getDN() |
50 |
< |
try: |
51 |
< |
sitedburl="https://cmsweb.cern.ch/sitedb/sitedb/json/index/dnUserName" |
52 |
< |
params = urllib.urlencode({'dn': userdn }) |
53 |
< |
f = urllib.urlopen(sitedburl,params) |
54 |
< |
udata = f.read() |
55 |
< |
try: |
56 |
< |
userinfo= eval(udata) |
57 |
< |
except StandardError, ex: |
58 |
< |
msg = "Error. Problem extracting user name from %s : %s"%(sitedburl,ex) |
59 |
< |
raise CrabException(msg) |
60 |
< |
hnUserName = userinfo['user'] |
61 |
< |
except: |
62 |
< |
msg = "Error. Problem extracting user name from %s"%sitedburl |
63 |
< |
msg += "Check that you are registered in SiteDB, see https://twiki.cern.ch/twiki/bin/view/CMS/SiteDBForCRAB" |
64 |
< |
raise CrabException(msg) |
65 |
< |
if not hnUserName: |
66 |
< |
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) |
67 |
< |
print msg |
68 |
< |
raise CrabException(msg) |
69 |
< |
return hnUserName |
27 |
> |
def checkLength(lfnbase, forced_path, PrimaryDataset, ProcessedDataset): |
28 |
> |
""" |
29 |
> |
""" |
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 |
> |
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 * |
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 |
75 |
> |
import logging |
76 |
> |
common.logger = logging |
77 |
|
|
78 |
+ |
print "xx %s xx"%getUserName() |
79 |
|
baselfn = LFNBase("datasetstring") |
80 |
< |
print baselfn |
80 |
> |
print baselfn |
81 |
|
|
82 |
|
unmergedlfn = LFNBase("datasetstring",merged=False) |
83 |
< |
print unmergedlfn |
83 |
> |
print unmergedlfn |
84 |
|
print PFNportion("datasetstring") |