1"""
2Create lv_conf.h in same directory as this file
3from ../lv_conf_template.h that has:
4
51.  all its #define LV_USE... 0-or-1 options set to 1
6     (except for LV_USER_PROFILER),
72.  all its #define LV_FONT... 0-or-1 options set to 1,
83.  its #if 0 directive set to #if 1.
9"""
10import os
11
12base_path = os.path.dirname(__file__)
13dst_config = os.path.join(base_path, 'lv_conf.h')
14src_config = os.path.abspath(os.path.join(
15    base_path,
16    '..',
17    'lv_conf_template.h'
18))
19
20
21def run(c_path=None):
22    global dst_config
23
24    if c_path is not None:
25        dst_config = c_path
26
27    with open(src_config, 'r') as f:
28        data = f.read()
29
30    data = data.split('\n')
31
32    for i, line in enumerate(data):
33        if 'LV_USE_PROFILER' in line:
34            continue
35
36        if 'LV_USE' in line or ('LV_FONT' in line and '#define' in line):
37            line = [item for item in line.split(' ') if item]
38
39            for j, item in enumerate(line):
40                if item == '0':
41                    line[j] = '1'
42
43            line = ' '.join(line)
44            data[i] = line
45        elif line.startswith('#if 0'):
46            line = line.replace('#if 0', '#if 1')
47            data[i] = line
48
49    data = '\n'.join(data)
50
51    with open(dst_config, 'w') as f:
52        f.write(data)
53
54
55def cleanup():
56    if os.path.exists(dst_config):
57        os.remove(dst_config)