]> rtime.felk.cvut.cz Git - linux-conf-perf.git/blob - scripts/boot.py
Implement random generation of configurations
[linux-conf-perf.git] / scripts / boot.py
1 import os
2 import sys
3 import subprocess
4 import shutil
5 import importlib
6
7 import utils
8 import initialize
9 from conf import conf
10 from conf import sf
11 from exceptions import MissingFile
12 import database
13
14 def boot(config, to_database = True):
15         try:
16                 os.mkdir(sf(conf.output_folder))
17         except FileExistsError:
18                         pass
19
20         sprc = subprocess.Popen(conf.boot_command, stdout = subprocess.PIPE)
21         with open(os.path.join(sf(conf.output_folder), config.cfile), "a") as f:
22                 for linen in sprc.stdout:
23                         line = linen.decode('utf-8')
24                         if conf.boot_output:
25                                 print(line, end="")
26                         f.write(line)
27
28         # Let user script parse double value
29
30         value = None
31         try:
32                 out = utils.callsubprocess('parse_command', conf.parse_command,
33                                 conf.parse_output, True)
34                 value = float(out[0])
35         except Exception as e:
36                 print("W: parse exception: " + e.__str__())
37
38         if to_database:
39                         dtb = database.database()
40                         dtb.add_measure(config.cfile, config.id, value)
41
42         return config.cfile