-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpre_execution.py
More file actions
47 lines (40 loc) · 1.4 KB
/
pre_execution.py
File metadata and controls
47 lines (40 loc) · 1.4 KB
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
import os
import logging
class pre_execution:
def __init__(self, config):
self.config = config
self.config_class = []
logging.info("Setting commands configuration.")
for program in self.config.config_class:
self.setup_commands(program)
self.config_class.append(program)
logging.info("Commands envirement is ready.")
def setup_commands(self, program):
if program.workingdir == "None":
program.workingdir = os.getcwd() + '/'
elif not os.path.isdir(program.workingdir):
os.makedirs(program.workingdir)
if program.umask != "None":
os.umask(program.umask)
if program.stdout != "None":
try:
with open(program.stdout, "w") as file:
pass
except Exception as e:
print(e)
if program.stderr != "None":
try:
with open(program.stderr, "w") as file:
pass
except Exception as e:
print(e)
self.setup_env(program)
def setup_env(self, program):
env = os.environ
if program.env != "None":
env = os.environ
for var in program.env :
env[var.split("=")[0]] = var.split("=")[1]
program.env = env
else :
program.env = None