Mercurial > repos > yufei-luo > s_mart
comparison smart_toolShed/commons/core/launcher/test/expFiles/expJobScriptTemplate_cmdWith2Lines.py @ 0:e0f8dcca02ed
Uploaded S-MART tool. A toolbox manages RNA-Seq and ChIP-Seq data.
author | yufei-luo |
---|---|
date | Thu, 17 Jan 2013 10:52:14 -0500 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:e0f8dcca02ed |
---|---|
1 #!/usr/bin/env python | |
2 | |
3 import os | |
4 import sys | |
5 import time | |
6 import shutil | |
7 from commons.core.checker.RepetException import RepetException | |
8 from commons.core.sql.TableJobAdaptator import TableJobAdaptator | |
9 from commons.core.sql.DbFactory import DbFactory | |
10 from commons.core.sql.Job import Job | |
11 | |
12 try: | |
13 newDir = None | |
14 print os.uname() | |
15 beginTime = time.time() | |
16 print 'beginTime=%f' % beginTime | |
17 print "work in dir '/home/user/workspace/repet_pipe/commons/core/launcher/test/dummyScratch'" | |
18 sys.stdout.flush() | |
19 if not os.path.exists( "/home/user/workspace/repet_pipe/commons/core/launcher/test/dummyScratch" ): | |
20 raise IOError("ERROR: temporary directory '/home/user/workspace/repet_pipe/commons/core/launcher/test/dummyScratch' doesn't exist") | |
21 | |
22 minFreeGigaInTmpDir = 1 | |
23 freeSpace = os.statvfs("/home/user/workspace/repet_pipe/commons/core/launcher/test/dummyScratch") | |
24 if ((freeSpace.f_bavail * freeSpace.f_frsize) / 1073741824.0 < minFreeGigaInTmpDir): | |
25 raise RepetException("ERROR: less than %iG of input file in '/home/user/workspace/repet_pipe/commons/core/launcher/test/dummyScratch'" % minFreeGigaInTmpDir) | |
26 | |
27 os.chdir("/home/user/workspace/repet_pipe/commons/core/launcher/test/dummyScratch") | |
28 newDir = "groupid_job1_20110505-105353" | |
29 if os.path.exists(newDir): | |
30 shutil.rmtree(newDir) | |
31 os.mkdir(newDir) | |
32 os.chdir(newDir) | |
33 | |
34 iJob = Job(jobname = "job1", groupid = "groupid", launcherFile = "ClusterLauncher", node = os.getenv("HOSTNAME")) | |
35 iDb = DbFactory.createInstance() | |
36 iTJA = TableJobAdaptator(iDb, "dummyJobsTable") | |
37 print "current status: %s" % iTJA.getJobStatus(iJob) | |
38 iTJA.changeJobStatus(iJob, "running") | |
39 print "updated status: %s" % iTJA.getJobStatus(iJob) | |
40 sys.stdout.flush() | |
41 iDb.close() | |
42 | |
43 print "Hello Yufei" | |
44 log = os.system("touch dummyFile1") | |
45 if log != 0: | |
46 raise RepetException("ERROR: job returned %i" % log) | |
47 else: | |
48 print "job finished successfully" | |
49 sys.stdout.flush() | |
50 shutil.move("dummyFile1", "/home/user/workspace/repet_pipe/commons/core/launcher/test") | |
51 | |
52 os.chdir("..") | |
53 shutil.rmtree(newDir) | |
54 | |
55 iDb = DbFactory.createInstance() | |
56 iTJA = TableJobAdaptator(iDb, "dummyJobsTable") | |
57 print "current status: %s" % iTJA.getJobStatus(iJob) | |
58 iTJA.changeJobStatus(iJob, "finished") | |
59 print "updated status: %s" % iTJA.getJobStatus(iJob) | |
60 sys.stdout.flush() | |
61 iDb.close() | |
62 | |
63 endTime = time.time() | |
64 print 'endTime=%f' % endTime | |
65 print 'executionTime=%f' % (endTime - beginTime) | |
66 print os.uname() | |
67 sys.stdout.flush() | |
68 | |
69 except IOError, e : | |
70 print e | |
71 iJob = Job(jobname = "job1", groupid = "groupid", launcherFile = "ClusterLauncher", node = os.getenv("HOSTNAME")) | |
72 iDb = DbFactory.createInstance() | |
73 iTJA = TableJobAdaptator(iDb, "dummyJobsTable") | |
74 print "current status: %s" % iTJA.getJobStatus(iJob) | |
75 iTJA.changeJobStatus(iJob, "error") | |
76 print "updated status: %s" % iTJA.getJobStatus(iJob) | |
77 sys.stdout.flush() | |
78 iDb.close() | |
79 sys.exit(1) | |
80 | |
81 except Exception, e : | |
82 print "tmpDir is : /home/user/workspace/repet_pipe/commons/core/launcher/test/dummyScratch" | |
83 print "cDir is : /home/user/workspace/repet_pipe/commons/core/launcher/test/" | |
84 print e | |
85 if newDir != None and os.path.exists("../%s" % newDir) and not os.path.exists("/home/user/workspace/repet_pipe/commons/core/launcher/test//%s" % newDir): | |
86 os.chdir("..") | |
87 shutil.move(newDir, "/home/user/workspace/repet_pipe/commons/core/launcher/test//%s" % newDir) | |
88 iJob = Job(jobname = "job1", groupid = "groupid", launcherFile = "ClusterLauncher", node = os.getenv("HOSTNAME")) | |
89 iDb = DbFactory.createInstance() | |
90 iTJA = TableJobAdaptator(iDb, "dummyJobsTable") | |
91 print "current status: %s" % iTJA.getJobStatus(iJob) | |
92 iTJA.changeJobStatus(iJob, "error") | |
93 print "updated status: %s" % iTJA.getJobStatus(iJob) | |
94 sys.stdout.flush() | |
95 iDb.close() | |
96 sys.exit(1) |