-
Notifications
You must be signed in to change notification settings - Fork 55
/
subdirs.py
76 lines (69 loc) · 2.11 KB
/
subdirs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#****************************************************************************
# Copyright (C) 2013 SUNCAT
# This file is distributed under the terms of the
# GNU General Public License. See the file `COPYING'
# in the root directory of the present distribution,
# or http://www.gnu.org/copyleft/gpl.txt .
#****************************************************************************
### subroutines for creation of subdirectories & clean-up
import os
def mklocaltmp(odir, site):
if site.batch:
s = site.submitdir
job = site.jobid
else:
s = os.getcwd()
job = ''
if odir is None or len(odir)==0:
p = os.popen('mktemp -d '+s+'/qe'+job+'_XXXXX', 'r')
tdir = p.readline().strip()
p.close()
else:
if odir[0]=='/':
tdir = odir
else:
tdir = s+'/'+odir
os.system('mkdir -p '+tdir)
return tdir
def mkscratch(localtmp, site):
if site.batch:
pernodeexec = site.perHostMpiExec
job = site.jobid
else:
pernodeexec = ''
job = ''
p = os.popen('mktemp -d '+site.scratch+'/qe'+job+'_XXXXX', 'r')
tdir = p.readline().strip()
p.close()
if pernodeexec!='':
cdir = os.getcwd()
os.chdir(localtmp)
os.system(pernodeexec + ' mkdir -p '+tdir)
os.chdir(cdir)
return tdir
def cleanup(tmp, scratch, removewf, removesave, calc, site):
try:
calc.stop()
except:
pass
if site.batch:
pernodeexec = site.perHostMpiExec
else:
pernodeexec = ''
if removewf:
os.system('rm -r '+scratch+'/*.wfc* '+scratch+'/*.hub* 2>/dev/null')
if not removesave:
os.system('cp -r '+scratch+' '+tmp)
cdir = os.getcwd()
os.chdir(tmp)
os.system(pernodeexec + ' rm -r '+scratch+' 2>/dev/null')
os.chdir(cdir)
if hasattr(site, 'mpdshutdown') and not os.environ.has_key('QEASE_MPD_ISSHUTDOWN'):
os.environ['QEASE_MPD_ISSHUTDOWN'] = 'yes'
os.system(site.mpdshutdown)
def getsubmitorcurrentdir(site):
s = site.submitdir
if s!=None:
return s
else:
return os.getcwd()