]> rtime.felk.cvut.cz Git - linux-conf-perf.git/blob - scripts/main_loop.py
Implementing main loop
[linux-conf-perf.git] / scripts / main_loop.py
1 #!/bin/python3
2 import os
3 import sys
4 import subprocess
5 import signal
6 from threading import Thread
7
8 from conf import conf
9 import initialize
10 import phase
11 import solution
12 import kernel
13 from exceptions import MissingFile
14 import iteration
15
16 def step():
17         phs = phase.get()
18         if phs == phase.phs("Not Initialized"):
19                 try:
20                         os.mkdir(conf.build_folder)
21                 except FileExistsError:
22                         pass
23                 phase.set(1)
24         elif phs == phase.phs("Initializing"):
25                 print("-- Initializing ...")
26                 initialize.kconfig_parser()
27                 try:
28                         initialize.gen_requred()
29                 except MissingFile:
30                         pass
31                 iteration.reset()
32                 phase.set(2)
33         elif phs == phase.phs("Initialized"):
34                 print("-- Initialized")
35                 phase.set(3)
36         elif phs == phase.phs("Solution generating"):
37                 print("-- Generating solution ...")
38                 solution.generate()
39                 iteration.inc()
40                 phase.set(4)
41         elif phs == phase.phs("Solution generated"):
42                 print("-- Solution generated")
43                 phase.set(5)
44         elif phs == phase.phs("Solution applying"):
45                 print("-- Applying generated solution ...")
46                 solution.apply()
47                 phase.set(6)
48         elif phs == phase.phs("Solution applied"):
49                 print("-- Generated solution applied")
50                 phase.set(2) # TODO edited
51         elif phs == phase.phs("Kernel configuration"):
52                 print("-- Kernel configure ...")
53                 phase.set(8)
54         elif phs == phase.phs("Kernel configured"):
55                 print("-- Kernel configured")
56                 phase.set(9)
57         elif phs == phase.phs("Kernel build"):
58                 print("-- Build Linux ...")
59                 kernel.build()
60                 phase.set(10)
61         elif phs == phase.phs("Kernel built"):
62                 print("-- Linux built")
63                 phase.set(2)
64
65 # TODO repair, not working
66 def reset():
67         os.rmdir(conf.build_folder)
68         os.chdir(conf.linux_sources)
69         subprocess.call(['make','clean'])
70         os.rm('.config') # remove linux config file
71
72
73 class mainThread(Thread):
74         def __init__(self, name):
75                 Thread.__init__(self, name=name)
76                 self.term = False
77         def run(self):
78                 while not self.term:
79                         step()
80         
81 def loop_term():
82         global thr
83         thr.term = True
84
85 def sigterm_handler(_signo, _stack_frame):
86         loop_term()
87
88 def main_loop():
89         global thr
90         thr = mainThread("thred")
91         thr.start()
92         try:
93                 thr.join()
94         except KeyboardInterrupt:
95                 loop_term()
96
97 #################################################################################
98
99 if __name__ == '__main__':
100         print("Start")
101         signal.signal(signal.SIGTERM, sigterm_handler)
102         main_loop()