comparison commons/core/launcher/WriteScript.py @ 6:769e306b7933

Change the repository level.
author yufei-luo
date Fri, 18 Jan 2013 04:54:14 -0500
parents
children
comparison
equal deleted inserted replaced
5:ea3082881bf8 6:769e306b7933
1 import os
2 import time
3
4 class WriteScript(object):
5
6 def __init__(self, job = None, jobdb = None, cdir = "", tmpdir = "", chooseTemplateWithCopy = False, chooseTemplateLight = False):
7 self._iJob = job
8 self._iJobdb = jobdb
9 self._cDir = cdir
10 self._tmpDir = tmpdir
11 self._chooseTemplateWithCopy = chooseTemplateWithCopy
12 self._chooseTemplateLight = chooseTemplateLight
13
14 def run(self, cmdStart, cmdFinish, pyFileName, cmdSize = "", cmdCopy = ""):
15 if self._chooseTemplateLight:
16 d = self.createJobScriptLightDict(cmdStart, cmdFinish, cmdSize, cmdCopy)
17 else:
18 d = self.createJobScriptDict(cmdStart, cmdFinish, cmdSize, cmdCopy)
19 self.fillTemplate(pyFileName, d)
20
21 def fillTemplate(self, outputFileName, dict):
22 if self._chooseTemplateWithCopy:
23 inputFileName = "%s/commons/core/launcher/JobScriptWithFilesCopyTemplate.py" % os.environ["REPET_PATH"]
24 else:
25 inputFileName = "%s/commons/core/launcher/JobScriptTemplate.py" % os.environ["REPET_PATH"]
26
27 if self._chooseTemplateLight:
28 inputFileName = "%s/commons/core/launcher/JobScriptTemplateLight.py" % os.environ["REPET_PATH"]
29
30 input = open(inputFileName, "r")
31 data = input.read()
32 input.close()
33 for key, value in dict.items():
34 data = data.replace("@@%s@@" % key, value)
35 output = open(outputFileName, "w")
36 output.write(data)
37 output.close()
38
39 def createJobScriptDict(self, cmdStart, cmdFinish, cmdSize, cmdCopy):
40 dict = {
41 "tmpDir" : self._tmpDir,
42 "jobTableName" : self._iJobdb._table,
43 "groupId" : self._iJob.groupid,
44 "jobName" : self._iJob.jobname,
45 "launcher" : self._iJob.launcher,
46 "time" : time.strftime("%Y%m%d-%H%M%S"),
47 "repet_path" : os.environ["REPET_PATH"],
48 "repet_host" : os.environ["REPET_HOST"],
49 "repet_user" : os.environ["REPET_USER"],
50 "repet_pw" : os.environ["REPET_PW"],
51 "repet_db" : os.environ["REPET_DB"],
52 "repet_port" : os.environ["REPET_PORT"],
53 "cmdStart" : cmdStart,
54 "cmdFinish" : cmdFinish,
55 "cDir" : self._cDir,
56 "cmdSize" : cmdSize,
57 "cmdCopy" : cmdCopy
58 }
59 return dict
60
61 def createJobScriptLightDict(self, cmdStart, cmdFinish, cmdSize, cmdCopy):
62 dict = {
63 "tmpDir" : self._tmpDir,
64 "jobTableName" : self._iJobdb._table,
65 "groupId" : self._iJob.groupid,
66 "jobName" : self._iJob.jobname,
67 "launcher" : self._iJob.launcher,
68 "time" : time.strftime("%Y%m%d-%H%M%S"),
69 "repet_path" : os.environ["REPET_PATH"],
70 "cmdStart" : cmdStart,
71 "cmdFinish" : cmdFinish,
72 "cDir" : self._cDir,
73 "cmdSize" : cmdSize,
74 "cmdCopy" : cmdCopy
75 }
76 return dict