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