예제 #1
0
    def ready(self):
        """
        The ready function is trigger only on events like server start up and server reload
        """
        # print "***************You are in Core Katana App Config Class***************"
        nav_obj = Navigator()

        base_directory = nav_obj.get_katana_dir()
        warrior_dir = nav_obj.get_warrior_dir()
        config_file_name = "wf_config.json"
        config_json_file = join_path(base_directory, "config.json")
        settings_file_path = get_abs_path(join_path("wui", "settings.py"),
                                          base_directory)
        core_index_obj = CoreIndex(base_directory,
                                   settings_file_path=settings_file_path)

        available_apps = core_index_obj.get_available_apps()
        settings_apps = core_index_obj.get_apps_from_settings_file()

        AppInformation.information = Apps()

        AppInformation.information.set_apps({
            'base_directory': base_directory,
            'config_file_name': config_file_name,
            'available_apps': available_apps,
            'settings_apps': settings_apps
        })
        if os.environ["pipmode"] == "True":
            pythonsrcdir = read_json_data(config_json_file)['pythonsrcdir']
        else:
            pythonsrcdir = warrior_dir
        ordered_json = validate_config_json(read_json_data(config_json_file),
                                            pythonsrcdir)
        with open(config_json_file, "w") as f:
            f.write(json.dumps(ordered_json, indent=4))
예제 #2
0
def get_app_path_from_name(app_name, config_file, base_directory):
    """
    This function gets the path to the wf_config_file in the app directory

    Args:
        app_name: Name of the app (eg: default.configuration)
        config_file: Name of the config file
        base_directory: Absolute path to the base directory (/warriorframework/katana/)

    Returns:
        app_config_file_path

    """
    temp = app_name.split(".")
    app_config_file_rel_path = ""
    for el in temp:
        app_config_file_rel_path += el
        app_config_file_rel_path += os.sep

    app_config_file_rel_path += config_file

    app_config_file_path = get_abs_path(app_config_file_rel_path,
                                        base_directory)

    return app_config_file_path
예제 #3
0
    def __copy_app_to_cache(self):
        output = True
        for plugin in self.related_plugins:
            if output:
                output = output and copy_dir(
                    plugin,
                    get_abs_path(get_dir_from_path(plugin),
                                 self.cache_dir,
                                 silence_error=True))
            else:
                print("-- An Error Occurred -- Could not backup the plugins. Uninstallation " \
                      "suspended.")
        if output:
            output = output and copy_dir(
                self.app_path,
                get_abs_path(self.app_name, self.cache_dir,
                             silence_error=True))
        else:
            print(
                "-- An Error Occurred -- Could not backup the app. Uninstallation suspended."
            )

        return output
예제 #4
0
    def __extract_plugin_names(self):
        plugins = []
        temp = []
        default_plugin = "{0}_plugin".format(self.app_name)

        if "plugins" in self.config_file_data:
            temp = self.config_file_data[plugins]
        if default_plugin not in temp:
            temp.append(default_plugin)

        for plugin in temp:
            temp_path = get_abs_path(plugin,
                                     base_path=self.plugin_dir,
                                     silence_error=True)
            if path.exists(temp_path):
                plugins.append(temp_path)

        return plugins
예제 #5
0
 def __init__(self, base_directory, app_path, app_type):
     self.app_name = get_dir_from_path(app_path)
     self.base_directory = base_directory
     self.plugin_dir = join_path(self.base_directory, "warrior", "plugins")
     self.app_dir = join_path(self.base_directory, "katana", app_type)
     self.settings_file = join_path(self.base_directory, "katana", "wui",
                                    "settings.py")
     self.urls_file = join_path(self.base_directory, "katana", "wui",
                                "urls.py")
     self.app_path = get_abs_path(self.app_name, self.app_dir)
     self.app_type = app_type
     self.config_file = join_path(self.app_path, "wf_config.json")
     self.config_file_data = read_json_data(self.config_file)
     self.related_plugins = self.__extract_plugin_names()
     self.pkg_in_settings = self.__get_setting_file_info()
     self.include_urls = self.__get_urls_info()
     self.valid_app_types = {"katana.wapps"}
     self.cache_dir = create_dir(
         join_path(self.base_directory, "katana", ".data", self.app_name))
     self.settings_backup = []
     self.urls_backup = []
예제 #6
0
def validate_config_json(json_data, warrior_dir):
    """
    This function validates the config.json file and returns an ordered dictionary

    :param json_data: original unordered contents of config.json
    :param warrior_dir: path to warrior directory

    :return: Ordered Dictionary containing validated config.json data
    """
    userobj = Navigator()
    if json_data["userreposdir"] == "":
        default_userrepo = ""
    else:
        default_userrepo = json_data["userreposdir"]

    ordered_json = OrderedDict()
    if "engineer" not in json_data:
        ordered_json["engineer"] = ""
    else:
        ordered_json["engineer"] = ""

    for key in json_data:
        pattern = r'userreposdir*[0-9a-zA-Z]*'
        result = re.match(pattern, str(key))
        if result:
            path = json_data[key]
            reponame = key
            if reponame:
                if reponame == "userreposdir":
                    if reponame not in json_data:
                        ordered_json[reponame] = ""
                    else:
                        ordered_json[reponame] = warrior_dir[:-1]
                else:
                    ordered_json[reponame] = json_data[reponame]
                    ordered_json[reponame] = path

            else:
                ordered_json[reponame] = ""
    if os.environ["pipmode"] == 'True':
        ordered_json["pythonsrcdir"] = warrior_dir
    else:
        ordered_json["pythonsrcdir"] = warrior_dir[:-1] \
            if "pythonsrcdir" not in json_data or json_data["pythonsrcdir"] == "" \
            else json_data["pythonsrcdir"]

    warrior_dir = ordered_json["pythonsrcdir"]

    ref = OrderedDict([
        ("xmldir", "Testcases"),
        ('testsuitedir', 'Suites'),
        ('projdir', 'Projects'),
        ('idfdir', 'Data'),
        ('testdata', 'Config_files'),
        ('testwrapper', 'wrapper_files'),
    ])
    ref.update(ordered_json)
    if os.environ["pipmode"] == 'True':
        if warrior_dir == "":
            for key, value in list(ref.items()):
                ordered_json[key] = ""
        else:
            for key, value in list(ref.items()):
                ordered_json[key] = json_data[key]
        ordered_json['userreposdir'] = default_userrepo
    else:
        for key, value in list(ref.items()):
            if key not in json_data or json_data[key] == "":
                if key == "engineer" and value == "":
                    pass
                else:
                    path = get_abs_path(join_path("Warriorspace", value),
                                        warrior_dir)
                    if path is not None:
                        ordered_json[key] = path
                    else:
                        ordered_json[key] = ""
                        print(
                            "-- An Error Occurred -- Path to {0} directory could not be located"
                            .format(value))
            else:
                ordered_json[key] = json_data[key]

    if "pythonpath" not in json_data:
        ordered_json["pythonpath"] = ""
    else:
        ordered_json["pythonpath"] = json_data["pythonpath"]

    return ordered_json