Added minimal doc to most functions & methods

This commit is contained in:
Maximilien Rigaut 2022-02-04 05:07:08 +01:00
parent e781ec68a7
commit bc28c78a48
3 changed files with 30 additions and 2 deletions

View File

@ -23,11 +23,17 @@ class ConfigLoader:
class UserConfig(ConfigLoader):
"""
Reads user config file.
"""
def __init__(self, configfile):
super().__init__(configfile)
class GlobalConfig(ConfigLoader):
"""
Reads global config file.
"""
def __init__(self, configfile):
super().__init__(configfile)

View File

@ -30,12 +30,18 @@ class Environment:
self._wasInitialised = {p: False for p in self._mParams}
def integrity_check(self):
"""
Checks if all mandatory parameters are set.
"""
for value in self._wasInitialised.values():
if value is False:
return False
return True
def __getattr__(self, attribute):
"""
Getter for all parameters.
"""
if attribute[0] == "_":
super().__getattribute__(attribute)
elif attribute in self._mParams:
@ -46,6 +52,9 @@ class Environment:
raise AttributeError(attribute)
def __setattr__(self, attribute, value):
"""
Setter for all parameters.
"""
if attribute[0] == "_":
super().__setattr__(attribute, value)
elif attribute in self._mParams:

View File

@ -13,12 +13,17 @@ class PreParser:
def __init__(self, path, __env):
self.path = path
self.__env = __env
self.path_resolved = pr.pathresolver(path)
self.path_resolved = pr.PathResolver(path)
def open(self):
pass
def make_import_list(self):
"""
Creates a list of all files to be imported.
Makes sure that the files are not already imported through a previous import statement.
Recursively build a list of PreParser object for each file to be imported.
"""
import_list = self.parse_import_list()
for e in import_list:
pp = PreParser(e, self.__env)
@ -27,14 +32,23 @@ class PreParser:
# todo: check for recursion errors
def parse_import_list(self):
"""
Parses the import list of the file.
"""
import_list = []
# parsing the file
return [self.path_resolved(p) for p in import_list] # converts relative paths to absolute and returns a table
def close(self):
"""
Closes the file.
"""
pass
def __del__(self):
"""
Destructor.
"""
self.close()
@ -42,4 +56,3 @@ if __name__ == "__main__":
site_path = "../../../example_userfiles/index.bpr"
__env = environment.Environment()
# rich.inspect(__env)