]> rtime.felk.cvut.cz Git - linux-conf-perf.git/blob - scripts/initialize.py
Fix error in initialize script and dedicate config for .config file
[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 parse_kconfig():
11         "Execute parse_kconfig 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.parse_kconfig_output:
19                 subprocess.call([conf.parse_kconfig, conf.linux_kconfig_head, conf.build_folder, "-v", "-v"], env=env)
20         else:
21                 subprocess.call([conf.parse_kconfig, 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
28         if not os.path.isfile(conf.linux_sources + '/.config'):
29                 raise MissingFile(conf.linux_sources + '/.config',
30                                 'Generate initial configuration. Execute make defconfig in linux folder. Or use make menuconfig and change configuration.')
31
32         utils.build_symbol_map() # Ensure smap existence
33         srmap = {value:key for key, value in utils.smap.items()}
34
35         try:
36                 os.remove(conf.required_file)
37                 os.remove(conf.dot_config_fragment_file)
38         except OSError:
39                 pass
40
41         shutil.copy(conf.linux_dot_config, conf.dot_config_back_file)
42
43         with open(conf.linux_sources + '/.config', 'r') as f:
44                 with open(conf.required_file, 'w') as freq:
45                         with open(conf.dot_config_fragment_file, 'w') as fconf:
46                                 for line in f:
47                                         if (line[0] == '#') or (not '=' in line):
48                                                 continue
49                                         indx = line.index('=')
50                                         if (line[indx + 1] == 'y' or line[indx + 1] == 'm'):
51                                                 freq.write(srmap[line[7:indx]] + "\n")
52                                         elif (line[indx + 1] == 'n'):
53                                                 freq.write("-" + srmap[line[7:indx]] + "\n")
54                                         else:
55                                                 fconf.write(line);