1#!/usr/bin/env python 2# -*- coding: utf-8 -*- 3 4# 5# Copyright (c) 2021 Huawei Device Co., Ltd. 6# Licensed under the Apache License, Version 2.0 (the "License"); 7# you may not use this file except in compliance with the License. 8# You may obtain a copy of the License at 9# 10# http://www.apache.org/licenses/LICENSE-2.0 11# 12# Unless required by applicable law or agreed to in writing, software 13# distributed under the License is distributed on an "AS IS" BASIS, 14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15# See the License for the specific language governing permissions and 16# limitations under the License. 17# 18 19import os 20import sys 21import subprocess 22from PyInquirer import prompt 23 24 25def enable_option(file_name): 26 option_list = [] 27 try: 28 with open('.config', 'r') as config_file: 29 for line in config_file: 30 if line.startswith('CONFIG_'): 31 str1 = line.split('=') 32 option_list.append(str1[0][7:]) 33 except IOError: 34 print('No config file') 35 return 36 37 if os.path.exists('.config'): 38 os.remove('.config') 39 40 file_data = '' 41 with open(file_name, 'r') as gni_file: 42 for line in gni_file: 43 if '=' in line: 44 str1 = line.split('=') 45 if str1[0].strip() in option_list: 46 line = str1[0] + '= true\n' 47 else: 48 line = str1[0] + '= false\n' 49 file_data += line 50 51 with open(file_name, 'w') as gni_file: 52 gni_file.write(file_data) 53 54 55def ask_option(): 56 options_prompt = { 57 'type': 'list', 58 'name': 'option', 59 'message': 'Which platform do you want to config?', 60 'default': 'standard', 61 'choices': ['standard', 'small', 'mini'] 62 } 63 answers = prompt(options_prompt) 64 return answers['option'] 65 66 67def main(): 68 print('##### Welcome to Dsoftbus #####') 69 option = ask_option() 70 subprocess.call(['menuconfig']) 71 file_gni = './adapter/default_config/feature_config/platform/config.gni' 72 if (option == 'standard'): 73 file_gni = file_gni.replace('platform', 'standard') 74 elif (option == 'small'): 75 file_gni = file_gni.replace('platform', 'small') 76 else: 77 file_gni = file_gni.replace('platform', 'mini') 78 enable_option(file_gni) 79 80 81if __name__ == '__main__': 82 sys.exit(main())