diff --git a/CMake/generate.py b/CMake/generate.py index 2c8262714d55a7ebbf6f6e7a15ed49344e1dcc7f..1c83a3f69594df616b71c295c8812f6403bc1094 100755 --- a/CMake/generate.py +++ b/CMake/generate.py @@ -56,9 +56,9 @@ class ConfigException(Exception): pass -class ConfigHelpers: +class Config: @staticmethod - def c_get(c, section, key, fallback=None): + def get(c, section, key, fallback=None): try: return c.get(section, key) except (configparser.NoOptionError, configparser.NoSectionError): @@ -67,7 +67,7 @@ class ConfigHelpers: raise ConfigException("[{}][{}] not defined".format(section, key)) @staticmethod - def c_get_array(c, section, key, fallback=None): + def get_array(c, section, key, fallback=None): try: return c.get(section, key).strip().split() except (configparser.NoOptionError, configparser.NoSectionError): @@ -76,7 +76,7 @@ class ConfigHelpers: raise ConfigException("[{}][{}] not defined".format(section, key)) @staticmethod - def c_section(c, section, fallback=None): + def get_section(c, section, fallback=None): try: return {k: v for k, v in c[section].items()} except (configparser.NoSectionError, KeyError): @@ -100,46 +100,46 @@ class Project: @property def category(self): - ctg = ConfigHelpers.c_get(self._config, 'General', 'category') + ctg = Config.get(self._config, 'General', 'category') if ctg not in CATEGORIES.keys(): raise ProjectException("Invalid category ({})".format(ctg)) return ctg @property def cmake_additional_set(self): - return ConfigHelpers.c_section(self._config, 'CMake', fallback={}).items() + return Config.get_section(self._config, 'CMake', fallback={}).items() @property def dependencies(self): - return ConfigHelpers.c_get_array(self._config, 'Dependencies', 'project', fallback=[]) + return Config.get_array(self._config, 'Dependencies', 'project', fallback=[]) @property def dependencies_test(self): - return ConfigHelpers.c_get_array(self._config, 'TestDependencies', 'project', fallback=[]) + return Config.get_array(self._config, 'TestDependencies', 'project', fallback=[]) @property def system_deps(self): - return ConfigHelpers.c_get_array(self._config, 'Dependencies', 'system', fallback=[]) + return Config.get_array(self._config, 'Dependencies', 'system', fallback=[]) @property def system_deps_test(self): - return ConfigHelpers.c_get_array(self._config, 'Dependencies', 'system', fallback=[]) + return Config.get_array(self._config, 'Dependencies', 'system', fallback=[]) def find_sources(self): return self._find_sources( - ConfigHelpers.c_get(CONFIG, 'CMake:Sources', 'SourcesDir'), - ConfigHelpers.c_get_array(CONFIG, 'CMake:Sources', 'ExcludeSources')) + Config.get(CONFIG, 'CMake:Sources', 'SourcesDir'), + Config.get_array(CONFIG, 'CMake:Sources', 'ExcludeSources')) def find_sources_test(self): return self._find_sources( - ConfigHelpers.c_get(CONFIG, 'CMake:Sources', 'TestSourcesDir'), - ConfigHelpers.c_get_array(CONFIG, 'CMake:Sources', 'ExcludeSources')) + Config.get(CONFIG, 'CMake:Sources', 'TestSourcesDir'), + Config.get_array(CONFIG, 'CMake:Sources', 'ExcludeSources')) def find_install_sources(self): return self._find_sources( - ConfigHelpers.c_get(CONFIG, 'CMake:Sources', 'SourcesDir'), + Config.get(CONFIG, 'CMake:Sources', 'SourcesDir'), [], - ConfigHelpers.c_get_array(CONFIG, 'CMake:Sources', 'InstallSources')) + Config.get_array(CONFIG, 'CMake:Sources', 'InstallSources')) def _find_sources(self, directory, exclude=None, include=None): # Recursively find all source file(s) and directories, return their names relatively to alib/{project}/ @@ -153,8 +153,7 @@ class Project: include = tuple(include) def excluded(filename): return len(exclude) != 0 and filename.endswith(tuple(exclude)) - def included(filename): return len(include) == 0 or (len(include) > 0 and filename.endswith(tuple(include))) or \ - ('EMPTY' in include and '.' not in filename) + def included(filename): return len(include) == 0 or (len(include) > 0 and filename.endswith(tuple(include))) or ('EMPTY' in include and '.' not in filename) source_files = [] for dp, dn, fn in os.walk(Helpers.path(self.path, directory)): @@ -193,9 +192,9 @@ class Generator: f.write(CATEGORIES['root'].format( alib_modules_lib=Helpers.join([p.name for p in projects if p.category == "library"]), alib_modules_exe=Helpers.join([p.name for p in projects if p.category == "executable"]), - alib_versioning_major=ConfigHelpers.c_get(CONFIG, 'Versioning', 'major'), - alib_versioning_minor=ConfigHelpers.c_get(CONFIG, 'Versioning', 'minor'), - alib_versioning_patch=ConfigHelpers.c_get(CONFIG, 'Versioning', 'patch'), + alib_versioning_major=Config.get(CONFIG, 'Versioning', 'major'), + alib_versioning_minor=Config.get(CONFIG, 'Versioning', 'minor'), + alib_versioning_patch=Config.get(CONFIG, 'Versioning', 'patch'), )) @classmethod @@ -236,8 +235,8 @@ class Generator: def _handle_system_deps(system_deps): libs, incl = [], [] for dep in system_deps: - incl = incl + ConfigHelpers.c_get_array(CONFIG, 'CMake:Deps:{}'.format(dep), 'include', fallback=[]) - libs = libs + ConfigHelpers.c_get_array(CONFIG, 'CMake:Deps:{}'.format(dep), 'link', fallback=[]) + incl = incl + Config.get_array(CONFIG, 'CMake:Deps:{}'.format(dep), 'include', fallback=[]) + libs = libs + Config.get_array(CONFIG, 'CMake:Deps:{}'.format(dep), 'link', fallback=[]) return incl, libs @@ -247,14 +246,14 @@ class Generator: SCRIPT_DIRECTORY = Helpers.path(os.path.dirname(__file__)) CONFIG = configparser.ConfigParser(allow_no_value=True) CONFIG.read(Helpers.path(SCRIPT_DIRECTORY, 'generate.conf')) -ALIB_DIRECTORY = Helpers.path(SCRIPT_DIRECTORY, ConfigHelpers.c_get(CONFIG, 'General', 'PathToSources')) +ALIB_DIRECTORY = Helpers.path(SCRIPT_DIRECTORY, Config.get(CONFIG, 'General', 'PathToSources')) PROJECTS = { - project: Project(project, ConfigHelpers.c_get(CONFIG, 'General', 'ProjectConfFile')) - for project in Helpers.find_dirs_with_file(ALIB_DIRECTORY, ConfigHelpers.c_get(CONFIG, 'General', 'ProjectConfFile')) + project: Project(project, Config.get(CONFIG, 'General', 'ProjectConfFile')) + for project in Helpers.find_dirs_with_file(ALIB_DIRECTORY, Config.get(CONFIG, 'General', 'ProjectConfFile')) } CATEGORIES = { category: SmartOpen(template, directory=SCRIPT_DIRECTORY, mode='r').read() - for category, template in ConfigHelpers.c_section(CONFIG, 'CMake:Categories').items() + for category, template in Config.get_section(CONFIG, 'CMake:Categories').items() }