annotate commons/core/launcher/JobScriptWithFilesCopyTemplate.py @ 16:6135c3075bc5

Deleted selected files
author m-zytnicki
date Mon, 22 Apr 2013 11:09:41 -0400
parents 769e306b7933
children 94ab73e8a190
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 #!/usr/bin/env python
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
2
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
3 import os
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
4 import sys
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
5 import time
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
6 import shutil
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
7 from commons.core.checker.RepetException import RepetException
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
8 from commons.core.sql.TableJobAdaptator import TableJobAdaptator
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
9 from commons.core.sql.DbFactory import DbFactory
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
10 from commons.core.sql.Job import Job
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
11
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
12 try:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
13 newDir = None
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
14 print os.uname()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
15 beginTime = time.time()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
16 print 'beginTime=%f' % beginTime
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
17 print "work in dir '@@tmpDir@@'"
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
18 sys.stdout.flush()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
19 if not os.path.exists("@@tmpDir@@"):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
20 raise IOError("ERROR: temporary directory '@@tmpDir@@' doesn't exist")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
21
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
22 fileSize = 0
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
23 if not os.path.exists("@@groupId@@"):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
24 @@cmdSize@@
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
25 freeGigaNeededInTmpDir = float(1 + fileSize)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
26 freeSpace = os.statvfs("@@tmpDir@@")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
27 if ((freeSpace.f_bavail * freeSpace.f_frsize) / 1073741824.0 < freeGigaNeededInTmpDir):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
28 raise RepetException("ERROR: less than %.2fG of input file in '@@tmpDir@@'" % freeGigaNeededInTmpDir)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
29
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
30 os.chdir("@@tmpDir@@")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
31 if not os.path.exists("@@groupId@@"):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
32 try:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
33 os.mkdir("@@groupId@@")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
34 except OSError, e :
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
35 if e.args[0] != 17:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
36 raise RepetException("ERROR: can't create '@@groupId@@'")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
37 os.chdir("@@groupId@@")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
38 @@cmdCopy@@
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
39 else:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
40 os.chdir("@@groupId@@")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
41
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
42 newDir = "@@groupId@@_@@jobName@@_@@time@@"
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
43 if os.path.exists(newDir):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
44 shutil.rmtree(newDir)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
45 os.mkdir(newDir)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
46 os.chdir(newDir)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
47
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
48 iJob = Job(jobname = "@@jobName@@", groupid = "@@groupId@@", launcherFile = "@@launcher@@", node = os.getenv("HOSTNAME"))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
49 iDb = DbFactory.createInstance()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
50 iTJA = TableJobAdaptator(iDb, "@@jobTableName@@")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
51 print "current status: %s" % iTJA.getJobStatus(iJob)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
52 iTJA.changeJobStatus(iJob, "running")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
53 print "updated status: %s" % iTJA.getJobStatus(iJob)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
54 sys.stdout.flush()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
55 iDb.close()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
56
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
57 @@cmdStart@@
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
58 if log != 0:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
59 raise RepetException("ERROR: job returned %i" % log)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
60 else:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
61 print "job finished successfully"
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
62 sys.stdout.flush()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
63 @@cmdFinish@@
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
64
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
65 os.chdir("..")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
66 shutil.rmtree(newDir)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
67
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
68 iDb = DbFactory.createInstance()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
69 iTJA = TableJobAdaptator(iDb, "@@jobTableName@@")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
70 print "current status: %s" % iTJA.getJobStatus(iJob)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
71 iTJA.changeJobStatus(iJob, "finished")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
72 print "updated status: %s" % iTJA.getJobStatus(iJob)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
73 sys.stdout.flush()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
74 iDb.close()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
75
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
76 endTime = time.time()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
77 print 'endTime=%f' % endTime
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
78 print 'executionTime=%f' % (endTime - beginTime)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
79 print os.uname()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
80 sys.stdout.flush()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
81
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
82 except IOError, e :
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
83 print e
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
84 iJob = Job(jobname = "@@jobName@@", groupid = "@@groupId@@", launcherFile = "@@launcher@@", node = os.getenv("HOSTNAME"))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
85 iDb = DbFactory.createInstance()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
86 iTJA = TableJobAdaptator(iDb, "@@jobTableName@@")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
87 print "current status: %s" % iTJA.getJobStatus(iJob)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
88 iTJA.changeJobStatus(iJob, "error")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
89 print "updated status: %s" % iTJA.getJobStatus(iJob)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
90 sys.stdout.flush()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
91 iDb.close()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
92 sys.exit(1)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
93
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
94 except Exception, e :
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
95 print "tmpDir is : @@tmpDir@@"
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
96 print "cDir is : @@cDir@@"
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
97 print e
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
98 if newDir != None and os.path.exists("../%s" % newDir) and not os.path.exists("@@cDir@@/%s" % newDir):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
99 os.chdir("..")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
100 shutil.move(newDir, "@@cDir@@/%s" % newDir)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
101 iJob = Job(jobname = "@@jobName@@", groupid = "@@groupId@@", launcherFile = "@@launcher@@", node = os.getenv("HOSTNAME"))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
102 iDb = DbFactory.createInstance()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
103 iTJA = TableJobAdaptator(iDb, "@@jobTableName@@")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
104 print "current status: %s" % iTJA.getJobStatus(iJob)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
105 iTJA.changeJobStatus(iJob, "error")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
106 print "updated status: %s" % iTJA.getJobStatus(iJob)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
107 sys.stdout.flush()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
108 iDb.close()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
109 sys.exit(1)