1
2
3
4
5
6 """
7 This module allows you to control Simcoal2.
8
9 """
10
11 import os
12 import sys
13 import tempfile
14 from shutil import copyfile
15 from logging import debug
16
19 """Initializes the controller.
20
21 simcoal_dir is the directory where simcoal is.
22
23 The initializer checks for existance and executability of binaries.
24 """
25 self.simcoal_dir = simcoal_dir
26 self.os_name = os.name
27 dir_contents = os.listdir(self.simcoal_dir)
28
29
30 if self.os_name=='nt' or sys.platform=='cygwin':
31 self.bin_name = 'simcoal2.exe'
32
33 dir_contents = [x.lower() for x in dir_contents]
34 else:
35 self.bin_name = 'simcoal2'
36 if self.bin_name in dir_contents:
37 if not os.access(self.simcoal_dir + os.sep +
38 self.bin_name, os.X_OK):
39 raise IOError("SimCoal not executable")
40 else:
41 raise IOError("SimCoal not available")
42
43 - def run_simcoal(self, par_file, num_sims, ploydi = '1', par_dir = '.'):
44 """Executes SimCoal.
45 """
46 if par_dir == None:
47 par_dir = os.sep.join([".", 'SimCoal', 'runs'])
48 curr_dir = os.getcwd()
49
50 os.chdir(par_dir)
51 cmd = self.simcoal_dir + os.sep + self.bin_name + ' ' + \
52 par_file + ' ' + str(num_sims) + ' ' + ploydi
53 if sys.platform=="win32":
54
55 cmd += ' > nul 2>nul'
56 else:
57 cmd += ' >/dev/null 2>&1'
58 os.system(cmd)
59 os.chdir(curr_dir)
60