]> rtime.felk.cvut.cz Git - linux-conf-perf.git/blob - scripts/initialize.py
Add source .config backup
[linux-conf-perf.git] / scripts / initialize.py
1 import os
2 import sys
3 import subprocess
4 import shutil
5
6 import utils
7 from conf import conf
8 from exceptions import MissingFile
9
10 def kconfig_parser():
11         "Execute kconfig_parser in linux_sources directory and parsed output is placed to build_folder."
12         env = dict(os.environ)
13         env['SRCARCH'] = conf.SRCARCH
14         env['ARCH'] = conf.ARCH
15         env['KERNELVERSION'] = 'KERNELVERSION' # hides error
16         wd = os.getcwd()
17         os.chdir(conf.linux_sources)
18         if conf.kconfig_parser_output:
19                 subprocess.call([conf.kconfig_parser, conf.linux_kconfig_head, conf.build_folder, "-v", "-v"], env=env)
20         else:
21                 subprocess.call([conf.kconfig_parser, conf.linux_kconfig_head, conf.build_folder], env=env)
22
23         os.chdir(wd)
24
25 def gen_requred():
26         "Generates required depenpency from required file."
27         utils.build_symbol_map()
28         srmap = {value:key for key, value in utils.smap.items()}
29
30         try:
31                 os.remove(conf.required_file)
32                 os.remove(conf.dot_config_file)
33         except OSError:
34                 pass
35
36         shutil.copy(conf.linux_sources + '/.config', conf.dot_config_back_file)
37
38         with open(conf.linux_sources + '/.config', 'r') as f:
39                 with open(conf.required_file, 'w') as freq:
40                         with open(conf.dot_config_fragment_file, 'w') as fconf:
41                                 for line in f:
42                                         if (line[0] == '#') or (not '=' in line):
43                                                 continue
44                                         indx = line.index('=')
45                                         if (line[indx + 1] == 'y' or line[indx + 1] == 'm'):
46                                                 freq.write(srmap[line[7:indx]] + "\n")
47                                         elif (line[indx + 1] == 'n'):
48                                                 freq.write("-" + srmap[line[7:indx]] + "\n")
49                                         else:
50                                                 fconf.write(line);