ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/ScriptWriter.py
Revision: 1.17
Committed: Fri Nov 30 17:38:21 2007 UTC (17 years, 5 months ago) by mcinquil
Content type: text/x-python
Branch: MAIN
Changes since 1.16: +1 -1 lines
Log Message:
Output sandbox limit reduced to 50MB (was 100MB)

File Contents

# Content
1 from WorkSpace import WorkSpace
2 from JobList import JobList
3 from Scheduler import Scheduler
4 from crab_logger import Logger
5 from crab_exceptions import *
6 import common
7
8 import string,os
9
10 class ScriptWriter:
11 def __init__(self, template, output_troncate_flag): ## added by Matty
12 # pattern -> action
13 ### FEDE added modify_report FOR DBS OUTPUT PUBLICATION
14 self.actions = {
15 'title' : self.title_,
16 'setup_scheduler_environment' : self.setupSchedulerEnvironment_,
17 'setup_jobtype_environment' : self.setupJobTypeEnvironment_,
18 'copy_input' : self.copyInput_,
19 'build_executable' : self.buildExe_,
20 'run_executable' : self.runExe_,
21 'rename_output' : self.renameOutput_,
22 'copy_output' : self.copyOutput_,
23 #'register_output' : self.registerOutput_,
24 'modify_report' : self.modifyReport_,
25 'clean_env' : self.cleanEnv_,
26 'check_output_limit' : self.checkOut_
27 }
28
29 if os.path.isfile("./"+template):
30 self.template = "./"+template
31 elif os.getenv('CRABDIR') and os.path.isfile(os.getenv('CRABDIR')+'/python/'+template):
32 self.template = os.getenv('CRABDIR')+'/python/'+template
33 else:
34 raise CrabException("No crab_template.sh found!")
35 self.nj = -1 # current job number
36
37 self.output_troncate_flag = output_troncate_flag
38
39 return
40
41 def setAction(self, pattern, action):
42 self.actions[pattern] = action
43 return
44
45 def modifyTemplateScript(self):
46 """
47 Create a script from scratch.
48 """
49
50 tpl = open(self.template, 'r')
51 script = open(common.taskDB.dict('ScriptName'),'w')
52
53 for line in tpl:
54 if len(line) > 6 and line[:6] == '#CRAB ':
55 act_str = string.strip(line[6:])
56 try:
57 action = self.actions[act_str]
58 except KeyError:
59 continue
60
61 if action:
62 txt = action()
63 script.write(txt)
64 pass
65 else:
66 script.write(line)
67 pass
68 else:
69 script.write(line)
70 pass
71 pass
72
73 script.close()
74 tpl.close()
75 return
76
77 def title_(self):
78 txt = '# This script was generated by '+common.prog_name
79 txt += ' (version '+common.prog_version_str+').\n'
80 return txt
81
82 def setupSchedulerEnvironment_(self):
83 """
84 Returns part of a job script which does scheduler-specific work.
85 """
86 txt = common.scheduler.wsSetupEnvironment()
87 return txt
88
89 def setupJobTypeEnvironment_(self):
90 """
91 Returns part of a job script which does jobtype-specific work.
92 """
93 jbt = common.job_list.type()
94 txt = jbt.wsSetupEnvironment(self.nj)
95 return txt
96
97 def buildExe_(self):
98 """
99 Returns part of a job script which builds the binary executable.
100 """
101 jbt = common.job_list.type()
102
103 txt = jbt.wsBuildExe(self.nj)
104
105 job = common.job_list[self.nj]
106 exe = job.type().executableName()
107
108 txt += 'executable='+exe+'\n'
109 return txt
110
111 def runExe_(self):
112 """
113 Returns part of a job script which executes the application.
114 """
115 job = common.job_list[self.nj]
116 args = job.type().executableArgs()
117 return '$executable '+args+'\n'
118
119 def renameOutput_(self):
120 """
121 Returns part of a job script which renames output files.
122 """
123 jbt = common.job_list.type()
124 txt = '\n'
125 txt += jbt.wsRenameOutput(self.nj)
126 return txt
127
128 def copyInput_(self):
129 """
130 Returns part of a job script which copies input files from SE.
131 """
132 txt = common.scheduler.wsCopyInput()
133 return txt
134
135 def copyOutput_(self):
136 """
137 Returns part of a job script which copies output files to SE.
138 """
139 txt = common.scheduler.wsCopyOutput()
140 return txt
141
142 #def registerOutput_(self):
143 # """
144 # Returns part of a job script which registers output files to RLS catalog.
145 # """
146 # txt = ''
147 # return txt
148
149 def modifyReport_(self):
150 """
151 Returns part of a job script which modifies the FrameworkJobReport.
152 """
153 jbt = common.job_list.type()
154 txt = jbt.modifyReport(self.nj)
155 return txt
156
157 def cleanEnv_(self):
158 """
159 In OSG environment this function removes the WORKING_DIR
160 """
161 jbt = common.job_list.type()
162 txt = jbt.cleanEnv()
163 return txt
164
165 def checkOut_(self):
166 """
167 With glite check if the output is too big
168 """
169 txt = "\n"
170 if self.output_troncate_flag == 1:
171 limit = 55000000 ##105 MB
172 jbt = common.job_list.type()
173 txt = jbt.checkOut(limit)
174 return txt