def __init__(self, filepath): """ :param filepath: Path to the root directory of the app being installed self.navigator: Navigator() onject self.app_name: Name of the actual app directory. self.path_to_app: Path to the actual app directory self.wf_config_file: Path to the app's wf_config file self.urls_inclusions: List of ursl that need o be included in main urls.py self.mandatory_fields: Mandatory fields necessary in wf_config.json self.wapp_data: All data in the wf_config.json file self.django_based: True indicates that this app uses new Katana API. False indicates that app still uses the old Katana API """ self.navigator = Navigator() self.app_name = get_sub_folders( join_path(filepath, "warriorframework_py3", "katana", "katana.wapps"))[0] self.path_to_app = join_path(filepath, "warriorframework_py3", "katana", "katana.wapps", self.app_name) self.wf_config_file = join_path(self.path_to_app, "wf_config.json") self.urls_inclusions = [] self.mandatory_fields = [ "app", "version", "warrior-compatibility", "warrior-incompatibility" ] self.wapp_data = read_json_data(self.wf_config_file) self.django_based = False if "pure_django" not in self.wapp_data or not self.wapp_data[ "pure_django"] else True
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))
def read_config_file(request): nav_obj = Navigator() config_file_path = join_path(nav_obj.get_katana_dir(), "config.json") data = read_json_data(config_file_path) if data is None: data = False return JsonResponse(data)
class CliDataFileClass(View): nav_obj = Navigator() app_directory = join_path(nav_obj.get_katana_dir(), "wapps", "cli_data") app_static_dir = join_path(app_directory, "static") def get(self, request): filepath = request.GET.get('path') # filepath = join_path(CliDataFileClass.app_static_dir, "base_templates", "test.xml") base_filepath = join_path(CliDataFileClass.app_static_dir, "base_templates", "empty.xml") if filepath == "false": filepath = base_filepath name = "Untitled" else: name, _ = os.path.splitext(get_dir_from_path(filepath)) vcdc_obj = VerifyCliDataClass(filepath, base_filepath) json_data = vcdc_obj.verify_contents() return JsonResponse({"contents": json_data, "name": name}) def post(self, request): json_data = json.loads(request.POST.get('json_data')) data = xmltodict.unparse(json_data) directory = request.POST.get('directory') filepath = os.path.join(directory, request.POST.get('filename') + ".xml") message = "" saved = True try: with open(filepath, 'w') as f: f.write(data) except Exception as e: saved = False message = e return JsonResponse({"saved": saved, "message": message})
def get(self, request): """ This is a get request for getting the file explorer data. It internally calls the get_dir_tree_json() in navigator_utils.py to get a list of directories. THIS VIEW EXISTS ONLY BECAUSE JSTREE DOES NOT HAVE SUPPORT FOR POST IN LAZY LOADING. params sent via the request: start_dir: Absolute path to the start directory. If not given, defaulted to "Warriorspace". path: Absolute path to the current directory. Send a path via this argument indicates that information for current directory's parent needs to be obtained. If not False, it is prioritized over start_dir lazy_loading: Indicates that jsTree lazy_loading is being used and only direct sub-children's information needs to be obtained. """ nav_obj = Navigator() start_dir = "false" lazy_loading = True if "lazy_loading" in request.GET and request.GET["lazy_loading"].lower() == "true" else False config_data = read_config_file_data() get_children_only = False if "start_dir" in request.GET: get_children_only = True start_dir = request.GET["start_dir"] if os.environ["pipmode"] == 'True': if config_data["pythonsrcdir"] != "" and start_dir == "false": get_children_only = False if config_data["xmldir"].split("/")[-2] == "warriorspace" or config_data["xmldir"].split("/")[-2] == "Warriorspace": start_dir = config_data["pythonsrcdir"] + "/" +config_data["xmldir"].split("/")[-2] elif config_data["xmldir"].split("/")[-3] == "warriorspace" or config_data["xmldir"].split("/")[-3] == "Warriorspace": start_dir = config_data["pythonsrcdir"] + "/" +config_data["xmldir"].split("/")[-3] else: start_dir = config_data["pythonsrcdir"] elif config_data["pythonsrcdir"] == "" and start_dir == "false": get_children_only = False start_dir = nav_obj.get_katana_dir() else: if config_data["pythonsrcdir"] != "" and start_dir == "false": get_children_only = False if config_data["xmldir"].split("/")[-2] == "warriorspace" or config_data["xmldir"].split("/")[-2] == "Warriorspace": start_dir = config_data["pythonsrcdir"] + "/" +config_data["xmldir"].split("/")[-2] elif config_data["xmldir"].split("/")[-3] == "warriorspace" or config_data["xmldir"].split("/")[-3] == "Warriorspace": start_dir = config_data["pythonsrcdir"] + "/" +config_data["xmldir"].split("/")[-3] else: start_dir = config_data["pythonsrcdir"] elif config_data["pythonsrcdir"] == "" and start_dir == "false": get_children_only = False start_dir = nav_obj.get_katana_dir() if "path" in request.GET: get_children_only = False start_dir = request.GET["path"] output = nav_obj.get_dir_tree_json(start_dir_path=start_dir, lazy_loading=lazy_loading) if get_children_only: output = output["children"] return JsonResponse(output, safe=False)
def __init__(self, template, file_path): self.navigator = Navigator() self.template = template self.file_path = file_path self.template_data = read_xml_get_json(template, ordered_dict=True) self.data = read_xml_get_json(file_path, ordered_dict=True) self.output = {"status": True, "message": ""} self.root = "Project"
def get_jstree_dir(request): """ Prepare the json for jstree to use """ config = read_json_data(JSON_CONFIG) data = Navigator().get_dir_tree_json(config["idfdir"]) data["text"] = config["idfdir"] # print json.dumps(data, indent=4) return JsonResponse(data)
def get_user_data(self): """ function is still used for backward compatibility, can be deprecated once completely handled by client server model """ userdata = {} json_file = Navigator().get_katana_dir() + '/user_profile.json' with open(json_file, 'r') as f: userdata = json.load(f) return userdata
def __init__(self, template, file_path): """ Constructor of the VerifyCaseFile class """ self.navigator = Navigator() self.template = template self.file_path = file_path self.template_data = read_xml_get_json(template, ordered_dict=True) self.data = read_xml_get_json(file_path, ordered_dict=True) self.output = {"status": True, "message": ""} self.root = "TestWrapper" self.major = ("Details", "Requirements", "Steps")
def __init__(self, data_file, ref_data_file): self.data_file = data_file self.data = read_xml_get_json(data_file) self.ref_data_file = ref_data_file self.nav_obj = Navigator() self.dependency_template = join_path(self.nav_obj.get_katana_dir(), "native", "settings", "static", "settings", "base_templates", "empty.xml") self.ref_data = self._get_ref_data() self.dependency_dict = self.__get_dependency_dict()
def get_jstree_dir(request): """ Prepare the json for jstree to use """ config = read_json_data(JSON_CONFIG) if os.path.exists(config["idfdir"]): data = Navigator().get_dir_tree_json(config["idfdir"]) data["text"] = config["idfdir"] else: data="invalid_path" # print json.dumps(data, indent=4) return JsonResponse(data, safe=False)
def save_warhorn_config_file(request): nav_obj = Navigator() directory = request.POST.get('directory') if directory == "default": directory = os.path.join(nav_obj.get_katana_dir(), "katana.wapps", "assembler", ".data") filepath = os.path.join(directory, request.POST.get('filename') + ".xml") json_data = json.loads(request.POST.get('json_data')) json_data["data"]["warriorframework"] = "Test" data = xmltodict.unparse(json_data) response = _save_file(filepath, data) return JsonResponse(response)
def save_and_run_warhorn_config_file(request): nav_obj = Navigator() directory = request.POST.get('directory') if directory == "default": directory = os.path.join(nav_obj.get_katana_dir(), "katana.wapps", "assembler", ".data") filepath = os.path.join(directory, request.POST.get('filename') + ".xml") json_data = json.loads(request.POST.get('json_data')) json_data["data"]["warriorframework"] = "Test" data = xmltodict.unparse(json_data) response = _save_file(filepath, data) nav_obj = Navigator() warhorn_dir = nav_obj.get_warhorn_dir() current_dir = os.getcwd() output = "" if response["saved"]: os.chdir(warhorn_dir) output = subprocess.Popen(["python", "warhorn.py", filepath], stdout=subprocess.PIPE).communicate()[0] os.chdir(current_dir) os.remove(filepath) return JsonResponse({"output": output})
def __init__(self): """ Constructor for execution app """ self.nav = Navigator() self.config_data = "" self.katana_dir = os.path.dirname(katana.native.__path__[0]) self.config_json = os.path.join(self.katana_dir, 'config.json') self.config_json_dict = "" self.warrior_dir = "" self.warrior = "" self.default_ws = "" self.templates_dir = os.path.join(templates_dir, 'execution') self.jira_settings_file = "" self.execution_settings_json = os.path.join(templates_dir, 'execution', 'execution_settings.json')
def __init__(self): """ Constructor for execution app """ self.nav = Navigator() self.config_data = read_config_file_data() self.katana_dir = os.path.dirname(native.__path__[0]) self.wf_dir = os.path.dirname(self.katana_dir) self.warrior = os.path.join(self.wf_dir, 'warrior', 'Warrior') if os.environ["pipmode"] == 'True': self.default_ws = self.config_data["pythonsrcdir"] else: self.default_ws = os.path.join(self.wf_dir, 'warrior', 'Warriorspace') self.templates_dir = os.path.join(templates_dir, 'execution') self.jira_settings_file = os.path.join(self.wf_dir, 'warrior', 'Tools', 'jira', 'jira_config.xml') self.execution_settings_json = os.path.join(templates_dir, 'execution', 'execution_settings.json') self.config_json = os.path.join(self.katana_dir, 'config.json')
def post(self, request): """ This is a post request for getting the file explorer data. It internally calls the get_dir_tree_json() in navigator_utils.py to get a list of directories. params sent via the request: start_dir: Absolute path to the start directory. If not given, defaulted to "Warriorspace". path: Absolute path to the current directory. Send a path via this argument indicates that information for current directory's parent needs to be obtained. If not False, it is prioritized over start_dir lazy_loading: Indicates that jsTree lazy_loading is being used and only direct sub-children's information needs to be obtained. """ nav_obj = Navigator() lazy_loading = True if "data[lazy_loading]" in request.POST and request.POST["data[lazy_loading]"].lower() == "true" else False start_dir = "false" config_data = read_config_file_data() if "data[start_dir]" in request.POST: start_dir = request.POST["data[start_dir]"] if os.environ["pipmode"] == 'True': if config_data["pythonsrcdir"] != "" and start_dir == "false": start_dir = config_data["pythonsrcdir"] elif config_data["pythonsrcdir"] == "" and start_dir == "false": start_dir = nav_obj.get_katana_dir() else: if config_data["pythonsrcdir"] != "" and start_dir == "false": get_children_only = False start_dir = config_data["pythonsrcdir"] elif config_data["pythonsrcdir"] == "" and start_dir == "false": get_children_only = False start_dir = nav_obj.get_katana_dir() if "data[path]" in request.POST and request.POST["data[path]"] != "false": start_dir = get_parent_directory(request.POST["data[path]"]) output = nav_obj.get_dir_tree_json(start_dir_path=start_dir, lazy_loading=lazy_loading) return JsonResponse(output)
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
def read_config_file_data(): nav_obj = Navigator() data = read_json_data(app_config_json_path) return data
def read_config_file_data(): nav_obj = Navigator() config_file_path = join_path(nav_obj.get_katana_dir(), "config.json") data = read_json_data(config_file_path) return data
# -*- coding: utf-8 -*- import json, xmltodict, os, copy from katana.utils.navigator_util import Navigator from katana.utils.json_utils import read_json_data from collections import OrderedDict from django.template.defaulttags import register from django.shortcuts import render from django.http import JsonResponse JSON_CONFIG = Navigator().get_katana_dir() + os.sep + "config.json" # Create your views here. def process_xml(data): # The first and only key in xml file should be the only root tag root = list(data.keys())[0] if not isinstance(data[root]["system"], list): # The whole xml only has one system data[root]["system"] = [data[root]["system"]] for sys in data[root]["system"]: if "subsystem" in sys: if isinstance(sys["subsystem"], list): # Multiple subsystems for subsys in sys["subsystem"]: for k, v in list(subsys.items()): subsys[k] = "" if subsys[k] is None else subsys[k] if k.startswith( "@") and k != "@name" and k != "@default":
def __init__(self): self.settings_file = os.path.join(Navigator().get_katana_dir(), 'wui', 'settings.py') print(self.settings_file)
os.environ["pipmode"] = "True" # except ModuleNotFoundError as error: except: WARRIORDIR = dirname(dirname(abspath(__file__))) sys.path.append(WARRIORDIR) try: import katana os.environ["pipmode"] = "False" except: raise from katana.utils.navigator_util import Navigator nav_obj = Navigator() BASE_DIR = nav_obj.get_katana_dir() appmanage_py = os.path.join(BASE_DIR, "appmanage.py") data = requests.get('https://pypi.python.org/pypi/katanaframework/json') data = data.json() ord_dict = OrderedDict() ord_dict = data['releases'].keys() versn_list = list(ord_dict) if (os.path.exists(os.path.join(BASE_DIR, 'wapps')) or os.path.exists(os.path.join(BASE_DIR, 'native'))): print( colored( "Please manually backup and then delete the following dirs before performing the upgrade operation", "red"))
from django.shortcuts import render from django.views import View import collections import json import os import xmltodict from django.http import JsonResponse from django.template.loader import render_to_string from katana.utils.directory_traversal_utils import join_path, get_parent_dir_path, get_dir_from_path from katana.utils.json_utils import read_json_data, read_xml_get_json from katana.utils.navigator_util import Navigator from katana.wapps.projects.project_utils.defaults import on_errors, impacts, contexts, runmodes, \ executiontypes, runtypes from katana.wapps.projects.project_utils.verify_project_file import VerifyProjectFile navigator = Navigator() CONFIG_FILE = join_path(navigator.get_katana_dir(), "config.json") APP_DIR = join_path(navigator.get_katana_dir(), "wapps", "projects") STATIC_DIR = join_path(APP_DIR, "static", "projects") TEMPLATE = join_path(STATIC_DIR, "base_templates", "Project_Template.xml") DROPDOWN_DEFAULTS = read_json_data( join_path(STATIC_DIR, "base_templates", "dropdowns_data.json")) class projectsView(View): def get(self, request): """ Get Request Method """ return render(request, 'projects/projects.html')
def get_data_directory(request): nav_obj = Navigator() directory = os.path.join(nav_obj.get_katana_dir(), "katana.wapps", "assembler", ".data") return JsonResponse({"data_directory": directory})
"address": "localhost", "port": "22", "username": "", "password": "", "end_prompt": "$", "deployment_environment": "docker", }, "registry": { "address": "index.docker.io", "image": "", "image_name": "", "image_tag": "", } } WARRIOR_DIR = Navigator().get_warrior_dir() PLUGINSPACE_DIR = os.path.join(WARRIOR_DIR, "plugins", "microservice_store_plugin", "pluginspace") PLUGINSPACE_WDF_DIR = os.path.join(PLUGINSPACE_DIR, "data") PLUGINSPACE_TC_DIR = os.path.join(PLUGINSPACE_DIR, "testcases") PLUGINSPACE_TS_DIR = os.path.join(PLUGINSPACE_DIR, "suites") PLUGINSPACE_TD_VC_DIR = os.path.join(PLUGINSPACE_DIR, "config_files") WARRIOR_EXE = os.path.join(WARRIOR_DIR, 'Warrior') TEMPLATE_WDF = "xml_templates/WDF_microservices_host_system_data_template.xml" TEMPLATE_VC = "xml_templates/VC_microservices_registry_operations_template.xml" FILENAME_WDF = "WDF_microservices_host_system_data.xml" FILENAME_VC = "VC_microservices_registry_operations.xml"
def __init__(self): self.navigator = Navigator() self.static_dir = join_path(self.navigator.get_katana_dir(), "native", "settings", "static", "settings")