Skip to content
parsevariablesfile.py 773 B
Newer Older
from os.path import dirname


class ParseVariablesFile:
    def __init__(self):
        folder = dirname(dirname(dirname(__file__)))
        filename = f'{folder}/resources/variables.py'
        self.variables = dict()

        with open(filename, 'r') as file:
            # Read the contents of the file
            file_content = file.read()

        file_content = file_content.split('\n')
        file_content = [x.split('=') for x in file_content if x is not '']

        self.variables = {x[0].strip(): x[1].replace("'", "").strip() for x in file_content}

    def get_variable(self, variable: str) -> str:
        # We request the variable in the form '${...}'
        variable = variable.strip('${}')
        value = self.variables[variable]

        return value