Permalink
Browse files

SectionFilling: Allow custom fill_section method

Adds a param `fill_section_method` to `fill_settings`
mehtod, making it possible to allow usage of custom
section filling method as well.

Closes #4539
  • Loading branch information...
satwikkansal committed Jul 23, 2017
1 parent 0c270ac commit ed283f77ccf8fbeb5f41ea23092c5cd221b73a34
Showing with 54 additions and 41 deletions.
  1. +54 −41 coalib/settings/SectionFilling.py
@@ -6,47 +6,6 @@
from coalib.settings.Setting import Setting
def fill_settings(sections, acquire_settings, log_printer):
"""
Retrieves all bears and requests missing settings via the given
acquire_settings method.
This will retrieve all bears and their dependencies.
:param sections: The sections to fill up, modified in place.
:param acquire_settings: The method to use for requesting settings. It will
get a parameter which is a dictionary with the
settings name as key and a list containing a
description in [0] and the names of the bears
who need this setting in all following indexes.
:param log_printer: The log printer to use for logging.
:return: A tuple containing (local_bears, global_bears),
each of them being a dictionary with the section
name as key and as value the bears as a list.
"""
local_bears = {}
global_bears = {}
for section_name, section in sections.items():
bear_dirs = section.bear_dirs()
bears = list(section.get('bears', ''))
section_local_bears, section_global_bears = collect_bears(
bear_dirs,
bears,
[BEAR_KIND.LOCAL, BEAR_KIND.GLOBAL],
log_printer)
section_local_bears = Dependencies.resolve(section_local_bears)
section_global_bears = Dependencies.resolve(section_global_bears)
all_bears = copy.deepcopy(section_local_bears)
all_bears.extend(section_global_bears)
fill_section(section, acquire_settings, log_printer, all_bears)
local_bears[section_name] = section_local_bears
global_bears[section_name] = section_global_bears
return local_bears, global_bears
def fill_section(section, acquire_settings, log_printer, bears):
"""
Retrieves needed settings from given bears and asks the user for
@@ -90,3 +49,57 @@ def fill_section(section, acquire_settings, log_printer, bears):
section.append(Setting(setting, help_text))
return section
def fill_settings(sections,
acquire_settings,
log_printer,
fill_section_method=fill_section,
**kwargs):
"""
Retrieves all bears and requests missing settings via the given
acquire_settings method.
This will retrieve all bears and their dependencies.
:param sections: The sections to fill up, modified in place.
:param acquire_settings: The method to use for requesting settings. It
will get a parameter which is a dictionary with
the settings name as key and a list containing
a description in [0] and the names of the bears
who need this setting in all following indexes.
:param log_printer: The log printer to use for logging.
:param fill_section_method: Method to be used to fill the section settings.
:param kwargs: Any other arguments for the fill_section_method
can be supplied via kwargs, which are passed
directly to the fill_section_method.
:return: A tuple containing (local_bears, global_bears),
each of them being a dictionary with the
section name as key and as value the bears as a
list.
"""
local_bears = {}
global_bears = {}
for section_name, section in sections.items():
bear_dirs = section.bear_dirs()
bears = list(section.get('bears', ''))
section_local_bears, section_global_bears = collect_bears(
bear_dirs,
bears,
[BEAR_KIND.LOCAL, BEAR_KIND.GLOBAL],
log_printer)
section_local_bears = Dependencies.resolve(section_local_bears)
section_global_bears = Dependencies.resolve(section_global_bears)
all_bears = copy.deepcopy(section_local_bears)
all_bears.extend(section_global_bears)
fill_section_method(section,
acquire_settings,
log_printer,
all_bears,
**kwargs)
local_bears[section_name] = section_local_bears
global_bears[section_name] = section_global_bears
return local_bears, global_bears

0 comments on commit ed283f7

Please sign in to comment.