Ejemplo n.º 1
0
    def read_configuration(self):
        ##################
        # Reading configuration

        default_file_path = helpers.current_dir(CONF_PATH)
        project_file_path = helpers.current_dir(CONF_PATH)
        self._configurations = configuration.read(
            default_file_path,
            project_path=project_file_path,
        )
Ejemplo n.º 2
0
def test():

    p = list_path(".")

    assert p is not None
    assert isinstance(p, list)
    assert len(p) > 0

    try:
        list_path("blabla")
    except FileNotFoundError:
        pass
    else:
        pytest.fail("This call should fail and raise a FileNotFoundError")

    p = last_dir("a/b/c")
    assert p == "c"
    p = last_dir("d")
    assert p == "d"
    p = last_dir("/")
    assert p == ""

    p = parent_dir("a/b/c/")
    assert p == "a/b/c"
    p = parent_dir("a/b/c")
    assert p == "a/b"
    p = parent_dir("d")
    assert p == ""
    p = parent_dir("/")
    assert p == "/"

    p = root_path("a", "b", "c")
    assert p == "/a/b/c"
    p = root_path()
    assert p == "/"
    p = root_path("a", "b", "/", "c")
    assert p == "/c"

    # FIXME: how to test?
    current_dir()

    # FIXME: how to test?
    script_abspath("test.txt", "a")

    m = module_from_package("a.b.c")
    assert m == "c"
    m = module_from_package("a")
    assert m == "a"
    m = module_from_package("")
    assert m == ""

    p = project_dir("test")
    assert p == "./projects/test"
Ejemplo n.º 3
0
    def get_models(self):
        """ Read models from base/custom yaml files """

        filename = SWAGGER_MODELS_FILE

        # BASE definitions
        path = helpers.script_abspath(__file__, SWAGGER_DIR)
        data = load_yaml_file(filename, path=path)

        # CUSTOM definitions
        path = helpers.current_dir(CUSTOM_PACKAGE, SWAGGER_DIR)
        override = load_yaml_file(filename, path=path, skip_error=True)

        return mix(data, override)
Ejemplo n.º 4
0
    def find_endpoints(self):

        ##################
        # Walk swagger directories looking for endpoints

        # FIXME: how to do this?
        # from utilities import helpers
        # custom_dir = helpers.current_dir(CUSTOM_PACKAGE)
        # base_dir = helpers.script_abspath(__file__)

        base_swagger_confdir = helpers.script_abspath(__file__)
        custom_swagger_confdir = helpers.current_dir(CUSTOM_PACKAGE)

        # for base_dir in [BACKEND_PACKAGE, CUSTOM_PACKAGE]:
        for base_dir in [base_swagger_confdir, custom_swagger_confdir]:

            swagger_dir = os.path.join(base_dir, 'swagger')
            log.verbose("Swagger dir: %s" % swagger_dir)

            for ep in os.listdir(swagger_dir):

                swagger_endpoint_dir = os.path.join(swagger_dir, ep)

                if os.path.isfile(swagger_endpoint_dir):
                    exception = '%s.yaml' % SWAGGER_MODELS_FILE
                    if not swagger_endpoint_dir.endswith('/' + exception):
                        log.debug(
                            "Found a file instead of a folder: %s",
                            swagger_endpoint_dir
                        )
                    continue

                # isbase = base_dir == BACKEND_PACKAGE
                isbase = base_dir.startswith('/usr/local')
                base_module = helpers.last_dir(base_dir)
                from utilities import ENDPOINTS_CODE_DIR
                if isbase:
                    apiclass_module = '%s.%s' % (base_module, 'resources')
                else:
                    apiclass_module = '%s.%s' % (
                        base_module, ENDPOINTS_CODE_DIR)

                current = self.lookup(
                    ep, apiclass_module, swagger_endpoint_dir, isbase)
                if current is not None and current.exists:
                    # Add endpoint to REST mapping
                    self._endpoints.append(current)
Ejemplo n.º 5
0
def get_html_template(template_file, replaces):
    path = helpers.current_dir(CUSTOM_PACKAGE, MODELS_DIR)
    template = os.path.join(path, "emails", template_file)

    html = None
    if os.path.isfile(template):
        with open(template, 'r') as f:
            html = f.read()

    if html is None:
        return html

    for r in replaces:
        val = replaces.get(r)
        key = "%%" + r + "%%"
        html = html.replace(key, val)

    return html
Ejemplo n.º 6
0
    def get_models(self):
        """ Read models from base/custom yaml files """

        filename = SWAGGER_MODELS_FILE

        # BASE definitions
        path = helpers.script_abspath(__file__, SWAGGER_DIR)
        data = load_yaml_file(filename, path=path)

        # CUSTOM definitions
        path = helpers.current_dir(CUSTOM_PACKAGE, SWAGGER_DIR)
        override = load_yaml_file(filename,
                                  path=path,
                                  skip_error=True,
                                  logger=False)
        # NOTE: with logger=False I skip the warning if this file doesn't exist

        return mix(data, override)