def load_user_settings(ctx): """ Apply all loaded options if they are different that the default value, and no cmd line value is presented """ global user_settings _load_default_settings_file(ctx) write_user_settings = False user_settings = ConfigParser.ConfigParser() user_setting_file = ctx.get_user_settings_node().abspath() new_options = {} # Load existing user settings if not os.path.exists( user_setting_file ): write_user_settings = True # No file, hence we need to write it else: user_settings.read( [user_setting_file] ) # Load settings and check for newly set ones for section_name, settings_list in ctx.default_settings.items(): # Add not already present sections if not user_settings.has_section(section_name): user_settings.add_section(section_name) write_user_settings = True # Iterate over all options in this group for settings in settings_list: option_name = settings['attribute'] default_value = settings.get('default_value', '') # Load the value from user settings if it is already present if user_settings.has_option(section_name, option_name): value = user_settings.get(section_name, settings['attribute']) LOADED_OPTIONS[ option_name ] = value else: # Add info about newly added option if not new_options.has_key(section_name): new_options[section_name] = [] new_options[section_name].append(option_name) # Load value for current option and stringify it value = settings.get('default_value', '') if getattr(ctx.options, option_name) != value: value = getattr(ctx.options, option_name) if not isinstance(value, str): value = str(value) if ATTRIBUTE_CALLBACKS.get(option_name, None): value = ATTRIBUTE_CALLBACKS[option_name](ctx, section_name, settings['attribute'], value) (isValid, warning, error) = ctx.verify_settings_option(option_name, value) # Add option if isValid: user_settings.set( section_name, settings['attribute'], str(value) ) LOADED_OPTIONS[ option_name ] = value write_user_settings = True # Check for settings provided by the cmd line long_form = settings['long_form'] short_form = settings.get('short_form', None) # Settings on cmdline should have priority, do a sub string match to batch both --option=<SomeThing> and --option <Something> bOptionSetOnCmdLine = False for arg in sys.argv: if long_form in arg: bOptionSetOnCmdLine = True value = getattr(ctx.options, option_name) break for arg in sys.argv: if short_form and short_form in arg: bOptionSetOnCmdLine = True value = getattr(ctx.options, option_name) break # Remember option for internal processing if bOptionSetOnCmdLine: LOADED_OPTIONS[ option_name ] = value elif user_settings.has_option(section_name, option_name): # Load all settings not coming form the cmd line from the config file setattr(ctx.options, option_name, user_settings.get(section_name, option_name)) # Write user settings if write_user_settings: ctx.save_user_settings(user_settings) # If use_incredibuild option was set but did not pass the ib validation, turn it off if ctx.is_option_true('use_incredibuild') and not internal_validate_incredibuild_registry_settings(ctx): setattr(ctx.options, 'use_incredibuild', 'False') # If max_cores option was set to < 0, default it to a good hardware value if int(ctx.options.max_cores) <= 0: max_cores = 8 # fallback value try: max_cores = multiprocessing.cpu_count() except: Logs.warn('unable to query hardware for number of hw threads, using "%d"' % max_cores) setattr(ctx.options, 'max_cores', max_cores) return user_settings, new_options
def load_user_settings(ctx): """ Apply all loaded options if they are different that the default value, and no cmd line value is presented """ global user_settings _load_default_settings_file(ctx) write_user_settings = False user_settings = ConfigParser.ConfigParser() user_setting_file = ctx.get_user_settings_node().abspath() new_options = {} # Load existing user settings if not os.path.exists(user_setting_file): write_user_settings = True # No file, hence we need to write it else: user_settings.read([user_setting_file]) Logs.debug('default_settings: sys.argv = {}'.format(sys.argv)) # Load settings and check for newly set ones for section_name, settings_list in ctx.default_settings.items(): # Add not already present sections if not user_settings.has_section(section_name): user_settings.add_section(section_name) write_user_settings = True # Iterate over all options in this group for settings in settings_list: option_name = settings['attribute'] default_value = settings.get('default_value', '') # Load the value from user settings if it is already present if user_settings.has_option(section_name, option_name): value = user_settings.get(section_name, settings['attribute']) LOADED_OPTIONS[option_name] = value else: # Add info about newly added option if not new_options.has_key(section_name): new_options[section_name] = [] new_options[section_name].append(option_name) # Load value for current option and stringify it value = settings.get('default_value', '') if getattr(ctx.options, option_name) != value: value = getattr(ctx.options, option_name) if not isinstance(value, str): value = str(value) if ATTRIBUTE_CALLBACKS.get(option_name, None): value = ATTRIBUTE_CALLBACKS[option_name]( ctx, section_name, settings['attribute'], value) (isValid, warning, error) = ctx.verify_settings_option(option_name, value) # Add option if isValid: user_settings.set(section_name, settings['attribute'], str(value)) LOADED_OPTIONS[option_name] = value write_user_settings = True # Check for settings provided by the cmd line long_form = settings['long_form'] short_form = settings.get('short_form', None) # Settings on cmdline should have priority # explicitly search for either the long form or short form argument, make sure to handle both --option=<SomeThing> and --option <Something> cases bOptionSetOnCmdLine = False for arg in sys.argv: arg_tokens = arg.split('=') if (arg_tokens[0] == long_form) or (short_form and arg_tokens[0] == short_form): Logs.debug( 'default_settings: found either long_form, "{}", or short_form, "{}", argument in command line param {}' .format(long_form, short_form, arg)) bOptionSetOnCmdLine = True value = getattr(ctx.options, option_name) break # Remember option for internal processing if bOptionSetOnCmdLine: LOADED_OPTIONS[option_name] = value elif user_settings.has_option( section_name, option_name ): # Load all settings not coming form the cmd line from the config file setattr(ctx.options, option_name, user_settings.get(section_name, option_name)) # Write user settings if write_user_settings: ctx.save_user_settings(user_settings) # If use_incredibuild option was set but did not pass the ib validation, turn it off if ctx.is_option_true( 'use_incredibuild' ) and not internal_validate_incredibuild_registry_settings(ctx): setattr(ctx.options, 'use_incredibuild', 'False') # If max_cores option was set to < 0, default it to a good hardware value if int(ctx.options.max_cores) <= 0: max_cores = 8 # fallback value try: max_cores = multiprocessing.cpu_count() except: Logs.warn( 'unable to query hardware for number of hw threads, using "%d"' % max_cores) setattr(ctx.options, 'max_cores', max_cores) # removing temporarily while we refactor how code scrubbing works. Do not re-enable without talking with JM Albertson. setattr(ctx.options, 'disable_orbis', 'True') # really. I'm not kidding. ACCEPTED_USE return user_settings, new_options
def load_user_settings(ctx): """ Apply all loaded options if they are different that the default value, and no cmd line value is presented """ global user_settings _load_default_settings_file(ctx) write_user_settings = False user_settings = ConfigParser.ConfigParser() user_setting_file = ctx.get_user_settings_node().abspath() new_options = {} # Load existing user settings if not os.path.exists(user_setting_file): write_user_settings = True # No file, hence we need to write it else: user_settings.read([user_setting_file]) Logs.debug('default_settings: sys.argv = {}'.format(sys.argv)) # 'Misc Options' must be evaluated first because the values in 'Game Projects' relies on its values section_name_and_settings_tuple_list = [] for section_name, settings_list in ctx.default_settings.items(): if section_name == 'Misc Options': section_name_and_settings_tuple_list.insert( 0, (section_name, settings_list)) else: section_name_and_settings_tuple_list.append( (section_name, settings_list)) # Load settings and check for newly set ones for section_name, settings_list in section_name_and_settings_tuple_list: # Add not already present sections if not user_settings.has_section(section_name): user_settings.add_section(section_name) write_user_settings = True # Iterate over all options in this group for settings in settings_list: option_name = settings['attribute'] # Start with the default value for current option stringified default_value = settings.get('default_value', '') value = default_value hasUserSettingsOption = False if user_settings.has_option(section_name, option_name): # Load the value from user settings if it is already present hasUserSettingsOption = True value = user_settings.get(section_name, option_name) LOADED_OPTIONS[option_name] = value else: # Add info about newly added option if not new_options.has_key(section_name): new_options[section_name] = [] new_options[section_name].append(option_name) if getattr(ctx.options, option_name) != value: value = getattr(ctx.options, option_name) if not isinstance(value, str): value = str(value) if ATTRIBUTE_CALLBACKS.get(option_name, None): value = ATTRIBUTE_CALLBACKS[option_name](ctx, section_name, option_name, value) (isValid, warning, error) = ctx.verify_settings_option(option_name, value) # Add option if isValid: user_settings.set(section_name, option_name, str(value)) LOADED_OPTIONS[option_name] = value write_user_settings = True # Check for settings provided by the cmd line long_form = settings['long_form'] short_form = settings.get('short_form', None) # Settings on cmdline should have priority # explicitly search for either the long form or short form argument, make sure to handle both --option=<SomeThing> and --option <Something> cases bOptionSetOnCmdLine = False for arg in sys.argv: arg_tokens = arg.split('=') if (arg_tokens[0] == long_form) or (short_form and arg_tokens[0] == short_form): Logs.debug( 'default_settings: found either long_form, "{}", or short_form, "{}", argument in command line param {}' .format(long_form, short_form, arg)) bOptionSetOnCmdLine = True value = getattr(ctx.options, option_name) break # Provide some information to the command line if default_value != value: from_location = "_WAF_/user_settings.options" if bOptionSetOnCmdLine: from_location = "command line args" Logs.info( 'default_settings: using option {}: "{}" from {} (default: "{}")' .format(option_name, value, from_location, default_value)) else: Logs.debug('default_settings: options default {}: "{}"'.format( option_name, default_value)) # Remember option for internal processing if bOptionSetOnCmdLine: LOADED_OPTIONS[option_name] = value elif hasUserSettingsOption: setattr(ctx.options, option_name, value) # Write user settings if write_user_settings: ctx.save_user_settings(user_settings) # If use_incredibuild option was set but did not pass the ib validation, turn it off if ctx.is_option_true( 'use_incredibuild' ) and not internal_validate_incredibuild_registry_settings(ctx): setattr(ctx.options, 'use_incredibuild', 'False') # If max_cores option was set to < 0, default it to a good hardware value if int(ctx.options.max_cores) <= 0: max_cores = 8 # fallback value try: max_cores = multiprocessing.cpu_count() except: Logs.warn( 'unable to query hardware for number of hw threads, using "%d"' % max_cores) setattr(ctx.options, 'max_cores', max_cores) return user_settings, new_options