diff options
author | Karel Kočí <cynerd@email.cz> | 2015-02-03 20:57:20 +0100 |
---|---|---|
committer | Karel Kočí <cynerd@email.cz> | 2015-02-03 20:57:20 +0100 |
commit | ef85245f159402fd948ff045b56ad9095d22b39e (patch) | |
tree | cf5d0f0ce017ed4c29c2c46da0cb6311c88c2733 /scripts/main_loop.py | |
parent | 9f07dd89b7cd2de6ce341afd1aed3e6bd0122a27 (diff) | |
download | linux-conf-perf-ef85245f159402fd948ff045b56ad9095d22b39e.tar.gz linux-conf-perf-ef85245f159402fd948ff045b56ad9095d22b39e.tar.bz2 linux-conf-perf-ef85245f159402fd948ff045b56ad9095d22b39e.zip |
Implementing main loop
These new scripts are part of main loop.
kernel is not finished!!
Divides kconfig_parser, sat_solution to better named modules.
Phasing and iteration is implemented for loop watching.
Diffstat (limited to 'scripts/main_loop.py')
-rwxr-xr-x | scripts/main_loop.py | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/scripts/main_loop.py b/scripts/main_loop.py new file mode 100755 index 0000000..9dd8c08 --- /dev/null +++ b/scripts/main_loop.py @@ -0,0 +1,102 @@ +#!/bin/python3 +import os +import sys +import subprocess +import signal +from threading import Thread + +from conf import conf +import initialize +import phase +import solution +import kernel +from exceptions import MissingFile +import iteration + +def step(): + phs = phase.get() + if phs == phase.phs("Not Initialized"): + try: + os.mkdir(conf.build_folder) + except FileExistsError: + pass + phase.set(1) + elif phs == phase.phs("Initializing"): + print("-- Initializing ...") + initialize.kconfig_parser() + try: + initialize.gen_requred() + except MissingFile: + pass + iteration.reset() + phase.set(2) + elif phs == phase.phs("Initialized"): + print("-- Initialized") + phase.set(3) + elif phs == phase.phs("Solution generating"): + print("-- Generating solution ...") + solution.generate() + iteration.inc() + phase.set(4) + elif phs == phase.phs("Solution generated"): + print("-- Solution generated") + phase.set(5) + elif phs == phase.phs("Solution applying"): + print("-- Applying generated solution ...") + solution.apply() + phase.set(6) + elif phs == phase.phs("Solution applied"): + print("-- Generated solution applied") + phase.set(2) # TODO edited + elif phs == phase.phs("Kernel configuration"): + print("-- Kernel configure ...") + phase.set(8) + elif phs == phase.phs("Kernel configured"): + print("-- Kernel configured") + phase.set(9) + elif phs == phase.phs("Kernel build"): + print("-- Build Linux ...") + kernel.build() + phase.set(10) + elif phs == phase.phs("Kernel built"): + print("-- Linux built") + phase.set(2) + +# TODO repair, not working +def reset(): + os.rmdir(conf.build_folder) + os.chdir(conf.linux_sources) + subprocess.call(['make','clean']) + os.rm('.config') # remove linux config file + + +class mainThread(Thread): + def __init__(self, name): + Thread.__init__(self, name=name) + self.term = False + def run(self): + while not self.term: + step() + +def loop_term(): + global thr + thr.term = True + +def sigterm_handler(_signo, _stack_frame): + loop_term() + +def main_loop(): + global thr + thr = mainThread("thred") + thr.start() + try: + thr.join() + except KeyboardInterrupt: + loop_term() + +################################################################################# + +if __name__ == '__main__': + print("Start") + signal.signal(signal.SIGTERM, sigterm_handler) + main_loop() |