From f9ddca42e9e2133299a3ab3986872d52c8fc766b Mon Sep 17 00:00:00 2001 From: vky Date: Wed, 26 Jan 2022 17:29:54 +0100 Subject: [PATCH] created a module for absolute path conversion --- src/bootstraparse/modules/pathresolver.py | 30 +++++++++++++++++++++++ src/bootstraparse/modules/sitecreator.py | 4 +-- src/bootstraparse/testrun.py | 12 +++------ 3 files changed, 36 insertions(+), 10 deletions(-) create mode 100644 src/bootstraparse/modules/pathresolver.py diff --git a/src/bootstraparse/modules/pathresolver.py b/src/bootstraparse/modules/pathresolver.py new file mode 100644 index 0000000..6c75b53 --- /dev/null +++ b/src/bootstraparse/modules/pathresolver.py @@ -0,0 +1,30 @@ +# Module for resolving relative path problems + +import os + + +class pathresolver(): + """ + Intialised with a relative path and returns the translated absolute path + """ + + def __init__(self, basepath): + self.basepath = os.path.normpath(basepath) + + def __call__(self, relativepath='.'): + return self.giveabsolute(relativepath) + + def giveabsolute(self, relativepath='.'): + return os.path.normpath(os.path.join(self.basepath, relativepath)) + + +class boostrapath(pathresolver): + """ + Initialises pathresolver with the path of the bootstraparse installation folder + """ + def __init__(self): + calculatedpath = os.path.join(__file__, "../../") + super().__init__(calculatedpath) + + +bpath = boostrapath() diff --git a/src/bootstraparse/modules/sitecreator.py b/src/bootstraparse/modules/sitecreator.py index 2296957..03e5362 100644 --- a/src/bootstraparse/modules/sitecreator.py +++ b/src/bootstraparse/modules/sitecreator.py @@ -1,7 +1,7 @@ # Module sequencing the successive actions necessary for website building import bootstraparse.modules.config as config - +from bootstraparse.modules.pathresolver import bpath def create_website(): @@ -24,7 +24,7 @@ def create_config(): """ Returns globalConfig as an object from parser_config.yml settings. """ - return config.GlobalConfig("configs/parser_config.yml") + return config.GlobalConfig(bpath("configs/parser_config.yml")) def create_crawler(): diff --git a/src/bootstraparse/testrun.py b/src/bootstraparse/testrun.py index f68940e..c66e6f0 100644 --- a/src/bootstraparse/testrun.py +++ b/src/bootstraparse/testrun.py @@ -1,10 +1,6 @@ -import modules.sitecreator as sitecreator -from rich import print, pretty, inspect +from bootstraparse.modules.pathresolver import bpath +import bootstraparse.modules.sitecreator -pretty.install() - - -conf = sitecreator.create_config() -print("[red]test",conf) -inspect(conf) \ No newline at end of file +print(bpath()) +print(bootstraparse.modules.sitecreator.create_config())