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