示例#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 __add_app_directory(self):
     temp_app_path = join_path(self.app_directory, self.app_name)
     if os.path.exists(temp_app_path):
         wf_config_extng = os.path.join(temp_app_path, "wf_config.json")
         wf_config_new = os.path.join(self.path_to_app, "wf_config.json")
         data_extng = read_json_data(wf_config_extng)
         data_new = read_json_data(wf_config_new)
         existing_version = data_extng["version"]
         new_version = data_new["version"]
         if existing_version == new_version:
             app_status = "Reinstall"
         elif existing_version < new_version:
             app_status = "Upgrade"
         else:
             app_status = "Downgrade"
         output = "Prompt"
         if app_status == "Reinstall":
             message = "{0} app with the same version {1} already exists. Do you want to {2}?".format(
                 self.app_name, new_version, app_status)
         else:
             message = "{0} app with the version {1} already exists. Do you want to {2} to {3}?".format(
                 self.app_name, existing_version, app_status, new_version)
         print(message)
         self.message += message
     else:
         output = copy_dir(self.path_to_app, temp_app_path)
         self.delete_app_dir.append(self.path_to_app)
     return output
示例#3
0
def check_app_version(existing_app, new_app):
    """This function will compare the versions of the existing app and the new app"""
    wf_config_extng = os.path.join(existing_app, "wf_config.json")
    wf_config_new = os.path.join(new_app, "wf_config.json")
    data_extng = read_json_data(wf_config_extng)
    data_new = read_json_data(wf_config_new)
    existing_version = data_extng["version"]
    new_version = data_new["version"]
    if existing_version == new_version:
        message = "Reinstall"
    elif existing_version < new_version:
        message = "Upgrade"
    else:
        message = "Downgrade"
    return existing_version, new_version, message
示例#4
0
    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
示例#5
0
def configure_urls_file_custom(app, category):
    """this function configure the url for custom apps"""
    app_main_folder = os.path.join(BASE_DIR, category)
    app_folder = os.path.join(app_main_folder, app)
    wf_config_file = os.path.join(app_folder, "wf_config.json")
    data = read_json_data(wf_config_file)
    if data["app"]["url"].startswith("/"):
        app_url = data["app"]["url"][1:]
    else:
        app_url = data["app"]["url"]
    with open(urls_file, "r") as f:
        url_file_content = f.readlines()
    with open(urls_file, "w") as f:
        if "    url(r'^"+app_url+"', include('katana.wapps."+app+".urls')),\n" \
            not in url_file_content:
            for line in url_file_content:
                if line == "    url(r'^$', RedirectView.as_view(url='/katana/')),\n":
                    f.writelines(line)
                    f.writelines("    url(r'^" + app_url +
                                 "', include('katana.wapps." + app +
                                 ".urls')),\n")
                else:
                    f.writelines(line)
        else:
            for line in url_file_content:
                f.writelines(line)
示例#6
0
def index(request):
    """
        Read an xml file and return the editor page with xml content in it
    """
    config = read_json_data(JSON_CONFIG)
    wdfdir = config["idfdir"]

    # Check to open new/existing file
    if request.method == "POST":
        data = request.POST
        if os.path.isfile(data["path"]):
            xml_data = xmltodict.parse(open(data["path"]).read())

            # Generate the filepath to use on webpage
            filepath = data["path"]
            filepath = filepath.replace(wdfdir, "")
            filepath = filepath[1:] if filepath.startswith(os.sep) else filepath

            # xml should only has 1 root
            root = list(xml_data.keys())[0]

            data, ref_dict = process_xml(xml_data)
            return render(request, 'wdf_edit/index.html', 
                          {"data": xml_data[root], "data_read": ref_dict, "filepath": filepath,
                           "desc":xml_data[root].get("description", "")})
        else:
            return render(request, 'wdf_edit/failure.html')
    else:
        sample_data = {"system": [{"@name": "Example system", "Example key": "Example value"}]}
        ref_dict = copy.deepcopy(sample_data)
        return render(request, 'wdf_edit/index.html', {"data": sample_data, "data_read": ref_dict, "filepath": ""})
示例#7
0
    def __edit_urls_py(self):
        checker = "RedirectView.as_view(url='/katana/')"
        data = read_json_data(self.wf_config_file)

        if data["app"]["url"].startswith("/"):
            app_url = data["app"]["url"][1:]
        else:
            app_url = data["app"]["url"]
        self.urls_inclusions.append("url(r'^" + app_url + "', include('" +
                                    data["app"]["include"] + "')),")

        data = readlines_from_file(self.urls_file)
        self.urls_backup = data
        index = -1
        for i in range(0, len(data)):
            if checker in data[i]:
                index = i + 1
                break
        white_space = data[index].split("url")
        for i in range(0, len(self.urls_inclusions)):
            self.urls_inclusions[
                i] = white_space[0] + self.urls_inclusions[i] + "\n"

        u_data = data[:index]
        u_data.extend(self.urls_inclusions)
        u_data.extend(data[index:])

        urls_data = ""
        for line in u_data:
            urls_data += line
        output = write_to_file(self.urls_file, urls_data)
        return output
示例#8
0
def get_list_of_suites(request):
    """
    Returns a list of suites
    """
    config = read_json_data(CONFIG_FILE)
    return JsonResponse(
        {"data": navigator.get_dir_tree_json(config["projdir"])})
示例#9
0
 def get(self, request):
     user_data = self.get_user_data()
     fname_file = os.path.join(BASE_DIR, "wui/core/static/core/framework_name.json")
     data = read_json_data(fname_file)
     framename = data["fr_name"]
     print(AppInformation.information.apps)
     return render(request, self.index_page, {"apps": AppInformation.information.apps, "userData": user_data, "frame_name": framename})
示例#10
0
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)
示例#11
0
def get_file(request):
    """
    Reads a file, validates it, computes the HTML and returns it as a JSON response
    """
    try:

            file_path = request.GET.get('path',)
            if file_path == "false":
                file_path = TEMPLATE
            vcf_obj = VerifySuiteFile(TEMPLATE, file_path)
            output, data = vcf_obj.verify_file()
            if output["status"]:
                mid_req = (len(data["TestSuite"]["Requirements"]["Requirement"]) + 1) / 2
                if file_path == TEMPLATE:
                    output["filepath"] = read_json_data(CONFIG_FILE)["testsuitedir"]
                else:
                    output["filepath"] = get_parent_dir_path(file_path)
                output["filename"] = os.path.splitext(get_dir_from_path(file_path))[0]
                output["html_data"] = render_to_string('suites/display_suite.html',
                                                       {"data": data, "mid_req": mid_req,
                                                        "defaults": DROPDOWN_DEFAULTS})
                return JsonResponse(output)
            else:
                JsonResponse({"status": output["status"], "message": output["message"]})
    except Exception as e:
        return JsonResponse({"status": 0,"message":"Exception opening the file"})
示例#12
0
def update_fname(fname):
    """this function update the framework name """
    fname_file = os.path.join(BASE_DIR,
                              "wui/core/static/core/framework_name.json")
    data = read_json_data(fname_file)
    data["fr_name"] = fname
    with open(fname_file, "w") as f:
        f.write(json.dumps(data, indent=4))
示例#13
0
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)
示例#14
0
    def general_setting_handler(self, request):
        json_file = self.navigator.get_katana_dir() + os.sep + 'config.json'
        if os.path.exists(self.navigator.get_warrior_dir() + os.sep + 'Tools' +
                          os.sep + 'w_settings.xml'):
            w_settings = self.navigator.get_warrior_dir(
            ) + os.sep + 'Tools' + os.sep + 'w_settings.xml'
        else:
            w_settings = self.navigator.get_katana_dir(
            ) + os.sep + 'native' + os.sep + 'settings' + os.sep + 'Tools' + os.sep + 'w_settings.xml'
        elem_file = xml_controler.parse(w_settings)
        elem_file = elem_file.getroot()
        elem = self.search_by_name('def_dir', elem_file)
        def_dir_string = xml_controler.tostring(elem)
        def_dir_xml_obj = elem

        if request.method == 'POST':
            w_settings_data = {
                'Setting': {
                    'Logsdir': '',
                    'Resultsdir': '',
                    '@name': ''
                }
            }
            returned_json = json.loads(request.POST.get('data'))

            for k, v in list(w_settings_data['Setting'].items()):
                w_settings_data['Setting'][k] = returned_json[0][k]
                del returned_json[0][k]

            elem_file.remove(def_dir_xml_obj)
            val = xmltodict.unparse(w_settings_data, pretty=True)
            elem_file.insert(0, xml_controler.fromstring(val))
            with open(w_settings, 'wb') as f:
                f.write(xml_controler.tostring(elem_file))
            with open(json_file, 'w') as f:
                f.write(
                    json.dumps(returned_json[0],
                               indent=4,
                               separators=(',', ': ')))
        else:
            with open(json_file, 'r') as f:
                json_data = json.load(f)
            if os.environ["pipmode"] == 'True':
                pythonsrcdir = read_json_data(json_file)['pythonsrcdir']
            else:
                pythonsrcdir = self.navigator.get_warrior_dir()
            data = {
                'fromXml':
                xmltodict.parse(def_dir_string).get('Setting'),
                'fromJson':
                validate_config_json(json_data,
                                     self.navigator.get_warrior_dir())
            }

            return data
示例#15
0
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)
示例#16
0
 def get_engineer_name(self):
     """
     This function returns the full name (if given in the user_profile.json) of the user.
     :return:
     """
     user_profile = join_path(self.get_katana_dir(), "user_profile.json")
     profile_data = read_json_data(user_profile)
     name = ""
     if profile_data is not None:
         name = (profile_data["firstName"] + " " +
                 profile_data["lastName"]).strip()
     return name
示例#17
0
def get_file(request):
    """
    Reads a case file and returns it's contents in JSOn format
    """
    try:
        file_path = request.GET.get('path')
        if file_path == "false":
            file_path = TEMPLATE
        vcf_obj = VerifyCaseFile(TEMPLATE, file_path)
        output, data = vcf_obj.verify_file()
        if output["status"]:
            mid_req = (len(data["Testcase"]["Requirements"]["Requirement"]) +
                       1) / 2
            repo_dirs = navigator.get_user_repos_dir()
            repo_dict = {}

            for repo in repo_dirs:
                repo_dict[repo] = {}

                repo_path = repo_dirs[str(repo)]
                da_obj = GetDriversActions(repo_path)
                if file_path == TEMPLATE:
                    output["filepath"] = read_json_data(CONFIG_FILE)["xmldir"]
                else:
                    output["filepath"] = get_parent_dir_path(file_path)
                output["filename"] = os.path.splitext(
                    get_dir_from_path(file_path))[0]
                output["user_repos"] = repo_dirs

                repo_dict[repo] = da_obj.get_all_actions()
            output["drivers"] = repo_dict
            output["html_data"] = render_to_string(
                'cases/display_case.html', {
                    "data": data,
                    "mid_req": mid_req,
                    "defaults": DROPDOWN_DEFAULTS,
                    "user_repos": repo_dirs
                })

            return JsonResponse(output)
        else:
            JsonResponse({
                "status": output["status"],
                "message": output["message"]
            })
    except Exception as e:
        return JsonResponse({
            "status": 0,
            "message": "Exception opening the file"
        })
示例#18
0
 def set_apps(self, data):
     """ call this to build Apps array and make app objects """
     self.get_config_paths(data)
     for url in self.paths:
         json_data = read_json_data(url)
         if json_data is not None:
             app_path = get_parent_directory(url)
             app = App(json_data, app_path, data["base_directory"])
             js_urls = get_paths_of_subfiles(
                 join_path(app_path, app.static_file_dir, "js"),
                 extension=compile_regex("^\.js$"))
             for i in range(0, len(js_urls)):
                 js_urls[i] = get_relative_path(js_urls[i], app_path)
             app.data["js_urls"] = js_urls
             self.apps.append(app)
     return self.apps
示例#19
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 = []
示例#20
0
def on_post(request):
    """
        Main function that handles a post request with edited xml data
    """
    data = json.loads(request.body.decode("utf-8"))
    filepath = data.get("filepath", None)
    desc = data.get("description", "")
    systems = build_xml_dict(data["systems"])
    result = {"credentials":OrderedDict()}
    if desc:
        result["credentials"]["description"] = desc
    result["credentials"]["system"] = systems

    from xml.dom.minidom import parseString as miniparse

    config = read_json_data(JSON_CONFIG)
    wdfdir = config["idfdir"]
    filepath = os.path.join(wdfdir, filepath)
    f = open(filepath, "w")
    f.write(miniparse(xmltodict.unparse(result)).toprettyxml())
    return render(request, 'wdf_edit/file_list.html')
示例#21
0
def remove_appurl_from_urls_custom(app, category):
    """this function reverts urls for custom app"""
    app_main_folder = os.path.join(BASE_DIR, category)
    app_folder = os.path.join(app_main_folder, app)
    wf_config_file = os.path.join(app_folder, "wf_config.json")
    data = read_json_data(wf_config_file)
    if data["app"]["url"].startswith("/"):
        app_url = data["app"]["url"][1:]
    else:
        app_url = data["app"]["url"]
    with open(urls_file, "r") as f:
        url_file_content = f.readlines()
    if category == "wapps":
        with open(urls_file, "r") as f:
            url_file_content = f.readlines()
        with open(urls_file, "w") as f:
            if "    url(r'^"+app_url+"', include('katana.wapps."+app+".urls')),\n" \
                in url_file_content:
                for line in url_file_content:
                    if line != "    url(r'^" + app_url + "', include('katana.wapps." + app + ".urls')),\n":
                        f.writelines(line)
            else:
                for line in url_file_content:
                    f.writelines(line)
    elif category == "native":
        with open(urls_file, "r") as f:
            url_file_content = f.readlines()
        with open(urls_file, "w") as f:
            if "    url(r'^katana/"+app+"/', include('katana.native."+app+".urls')),\n" \
                in url_file_content:
                for line in url_file_content:
                    if line != "    url(r'^katana/" + app + "/', include('katana.native." + app + ".urls')),\n":
                        f.writelines(line)
            else:
                for line in url_file_content:
                    f.writelines(line)
示例#22
0
    def general_setting_handler(self, request):
        json_file = self.navigator.get_katana_dir() + os.sep + 'config.json'
        w_settings = self.navigator.get_warrior_dir(
        ) + 'Tools' + os.sep + 'w_settings.xml'
        elem_file = xml_controler.parse(w_settings)
        elem_file = elem_file.getroot()
        elem = self.search_by_name('def_dir', elem_file)
        def_dir_string = xml_controler.tostring(elem)
        def_dir_xml_obj = elem

        if request.method == 'POST':
            w_settings_data = {
                'Setting': {
                    'Logsdir': '',
                    'Resultsdir': '',
                    '@name': ''
                }
            }
            returned_json = json.loads(request.POST.get('data'))
            if os.environ["pipmode"] == 'True':
                if os.path.isdir(returned_json[0]['pythonsrcdir']):
                    if os.path.split(returned_json[0]['pythonsrcdir']
                                     )[-1] == 'Warriorspace' or os.path.split(
                                         returned_json[0]['pythonsrcdir']
                                     )[-2] == 'Warriorspace':
                        returned_json[0]['pythonsrcdir'] = returned_json[0][
                            'pythonsrcdir']
                    else:
                        try:
                            os.mkdir(returned_json[0]['pythonsrcdir'] +
                                     '/Warriorspace')
                            returned_json[0]['pythonsrcdir'] = returned_json[
                                0]['pythonsrcdir'] + '/Warriorspace'
                        except FileExistsError:
                            returned_json[0]['pythonsrcdir'] = returned_json[
                                0]['pythonsrcdir'] + '/Warriorspace'
                else:
                    return
                ref = {
                    'xmldir': "Testcases",
                    'testsuitedir': 'Suites',
                    'projdir': 'Projects',
                    'idfdir': 'Data',
                    'testdata': 'Config_files',
                    'testwrapper': 'wrapper_files'
                }
            for k, v in list(w_settings_data['Setting'].items()):
                w_settings_data['Setting'][k] = returned_json[0][k]
                del returned_json[0][k]
            if os.environ["pipmode"] == 'True':
                for key, value in returned_json[0].items():
                    if key in ref.keys() and returned_json[0][
                            'pythonsrcdir'] != "" and returned_json[0][
                                key] == "":
                        returned_json[0][key] = returned_json[0][
                            'pythonsrcdir'] + '/' + ref[key]
                        if not os.path.isdir(returned_json[0][key]):
                            os.mkdir(returned_json[0][key])
            elem_file.remove(def_dir_xml_obj)
            val = xmltodict.unparse(w_settings_data, pretty=True)
            elem_file.insert(0, xml_controler.fromstring(val))
            with open(w_settings, 'wb') as f:
                f.write(xml_controler.tostring(elem_file))
            with open(json_file, 'w') as f:
                f.write(
                    json.dumps(returned_json[0],
                               indent=4,
                               separators=(',', ': ')))
        else:
            with open(json_file, 'r') as f:
                json_data = json.load(f)
            if os.environ["pipmode"] == 'True':
                pythonsrcdir = read_json_data(json_file)['pythonsrcdir']
            else:
                pythonsrcdir = self.navigator.get_warrior_dir()
            data = {
                'fromXml':
                xmltodict.parse(def_dir_string).get('Setting'),
                'fromJson':
                validate_config_json(json_data,
                                     self.navigator.get_warrior_dir())
            }

            return data
示例#23
0
 def read_config_file_data():
     nav_obj = Navigator()
     data = read_json_data(app_config_json_path)
     return data
示例#24
0
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_list_of_suites(request):
    """
    Returns a list of suites
    """
    config = read_json_data(CONFIG_FILE)
示例#25
0
def populate_paths(request):
    test_case_folder = "Testcases"
    suites_folder = "Suites"
    project_folder = "Projects"
    data_folder = "Data"
    config_folder = "Config_files"
    wrapper_folder = "wrapper_files"
    returned_json = read_json_data(config_json_path)
    list_of_files = os.listdir(returned_json["pythonsrcdir"])
    if list_of_files:

        if ("warriorspace" not in list_of_files
                and "Warriorspace" not in list_of_files
                and "Projects" not in list_of_files
                and "projects" not in list_of_files
                and "Suites" not in list_of_files
                and "suites" not in list_of_files
                and "Testcases" not in list_of_files
                and "testcases" not in list_of_files
                and "Data" not in list_of_files and "data" not in list_of_files
                and "Wrapper_files" not in list_of_files
                and "wrapper_files" not in list_of_files
                and "Config_files" not in list_of_files
                and "config_files" not in list_of_files):
            os.mkdir(returned_json["pythonsrcdir"] + "/Warriorspace")
            sub_folders = {
                "Testcases": "xmldir",
                "Suites": "testsuitedir",
                "Projects": "projdir",
                "Data": "idfdir",
                "Config_files": "testdata",
                "wrapper_files": "testwrapper",
            }
            for folder in [
                    "Testcases",
                    "Suites",
                    "Data",
                    "wrapper_files",
                    "Config_files",
                    "Projects",
            ]:
                os.mkdir(returned_json["pythonsrcdir"] + "/Warriorspace/" +
                         folder)
                returned_json[sub_folders[folder]] = (
                    returned_json["pythonsrcdir"] + "/Warriorspace/" + folder)
            with open(config_json_path, "w") as f:
                f.write(json.dumps(returned_json, indent=4))
            return HttpResponse(request)

    if os.path.isdir(returned_json["pythonsrcdir"]):
        if (returned_json["pythonsrcdir"].split("/")[-1].lower()
                == "warriorspace"
                or returned_json["pythonsrcdir"].split("/")[-2].lower()
                == "warriorspace"):
            child_dirs = os.listdir(returned_json["pythonsrcdir"])
            if "Testcases" in child_dirs:
                test_case_folder = "Testcases"
                returned_json[
                    "xmldir"] = returned_json["pythonsrcdir"] + "/Testcases"

            elif "testcases" in child_dirs:
                test_case_folder = "testcases"
                returned_json[
                    "xmldir"] = returned_json["pythonsrcdir"] + "/testcases"
            else:
                test_case_folder = "Testcases"
                os.mkdir(returned_json["pythonsrcdir"] + "/Testcases")
                returned_json[
                    "xmldir"] = returned_json["pythonsrcdir"] + "/Testcases"

            if "Suites" in child_dirs:
                suites_folder = "Suites"
                returned_json["testsuitedir"] = (
                    returned_json["pythonsrcdir"] + "/Suites")
            elif "suites" in child_dirs:
                suites_folder = "suites"
                returned_json["testsuitedir"] = (
                    returned_json["pythonsrcdir"] + "/suites")
            else:
                suites_folder = "Suites"
                os.mkdir(returned_json["pythonsrcdir"] + "/Suites")
                returned_json["testsuitedir"] = (
                    returned_json["pythonsrcdir"] + "/Suites")

            if "Projects" in child_dirs:
                project_folder = "Projects"
                returned_json[
                    "projdir"] = returned_json["pythonsrcdir"] + "/Projects"
            elif "projects" in child_dirs:
                project_folder = "projects"
                returned_json[
                    "projdir"] = returned_json["pythonsrcdir"] + "/projects"
            else:
                project_folder = "Projects"
                os.mkdir(returned_json["pythonsrcdir"] + "/Projects")
                returned_json[
                    "projdir"] = returned_json["pythonsrcdir"] + "/Projects"

            if "Data" in child_dirs:
                data_folder = "Data"
                returned_json[
                    "idfdir"] = returned_json["pythonsrcdir"] + "/Data"
            elif "data" in child_dirs:
                data_folder = "data"
                returned_json[
                    "idfdir"] = returned_json["pythonsrcdir"] + "/data"
            else:
                data_folder = "Data"
                os.mkdir(returned_json["pythonsrcdir"] + "/Data")
                returned_json[
                    "idfdir"] = returned_json["pythonsrcdir"] + "/Data"

            if "Config_files" in child_dirs:
                config_folder = "Config_files"
                returned_json["testdata"] = (returned_json["pythonsrcdir"] +
                                             "/Config_files")
            elif "config_files" in child_dirs:
                config_folder = "config_files"
                returned_json["testdata"] = (returned_json["pythonsrcdir"] +
                                             "/config_files")
            else:
                config_folder = "Config_files"
                os.mkdir(returned_json["pythonsrcdir"] + "/Config_files")
                returned_json["testdata"] = (returned_json["pythonsrcdir"] +
                                             "/Config_files")

            if "wrapper_files" in child_dirs:
                wrapper_folder = "wrapper_files"
                returned_json["testwrapper"] = (returned_json["pythonsrcdir"] +
                                                "/wrapper_files")
            elif "Wrapper_files" in child_dirs:
                wrapper_folder = "Wrapper_files"
                returned_json["testwrapper"] = (returned_json["pythonsrcdir"] +
                                                "/Wrapper_files")
            else:
                wrapper_folder = "wrapper_files"
                os.mkdir(returned_json["pythonsrcdir"] + "/wrapper_files")
                returned_json["testwrapper"] = (returned_json["pythonsrcdir"] +
                                                "/wrapper_files")
        elif os.listdir(returned_json["pythonsrcdir"]):

            base_tree = os.listdir(returned_json["pythonsrcdir"])
            for element in base_tree:
                if element == "warriorspace":
                    warrior_path = "/warriorspace"
                elif element == "Warriorspace":
                    warrior_path = "/Warriorspace"
            if "warriorspace" in [x.lower() for x in base_tree]:
                child_dirs = os.listdir(returned_json["pythonsrcdir"] + "/" +
                                        warrior_path)

                if "Testcases" in child_dirs:
                    test_case_folder = "Testcases"
                    returned_json["xmldir"] = (returned_json["pythonsrcdir"] +
                                               warrior_path + "/Testcases")

                elif "testcases" in child_dirs:
                    test_case_folder = "testcases"
                    returned_json["xmldir"] = (returned_json["pythonsrcdir"] +
                                               warrior_path + "/testcases")
                else:
                    test_case_folder = "Testcases"
                    if not os.path.exists(returned_json["pythonsrcdir"] +
                                          warrior_path + "/Testcases"):
                        os.mkdir(returned_json["pythonsrcdir"] + warrior_path +
                                 "/Testcases")
                    returned_json["xmldir"] = (returned_json["pythonsrcdir"] +
                                               warrior_path + "/Testcases")

                if "Suites" in child_dirs:
                    suites_folder = "Suites"
                    returned_json["testsuitedir"] = (
                        returned_json["pythonsrcdir"] + warrior_path +
                        "/Suites")
                elif "suites" in child_dirs:
                    suites_folder = "suites"
                    returned_json["testsuitedir"] = (
                        returned_json["pythonsrcdir"] + warrior_path +
                        "/suites")
                else:
                    suites_folder = "Suites"
                    if not os.path.exists(returned_json["pythonsrcdir"] +
                                          warrior_path + "/Suites"):
                        os.mkdir(returned_json["pythonsrcdir"] + warrior_path +
                                 "/Suites")
                    returned_json["testsuitedir"] = (
                        returned_json["pythonsrcdir"] + warrior_path +
                        "/Suites")

                if "Projects" in child_dirs:
                    project_folder = "Projects"
                    returned_json["projdir"] = (returned_json["pythonsrcdir"] +
                                                warrior_path + "/Projects")
                elif "projects" in child_dirs:
                    project_folder = "projects"
                    returned_json["projdir"] = (returned_json["pythonsrcdir"] +
                                                warrior_path + "/projects")
                else:
                    project_folder = "Projects"
                    if not os.path.exists(returned_json["pythonsrcdir"] +
                                          warrior_path + "/Projects"):
                        os.mkdir(returned_json["pythonsrcdir"] + warrior_path +
                                 "/Projects")
                    returned_json["projdir"] = (returned_json["pythonsrcdir"] +
                                                warrior_path + "/Projects")

                if "Data" in child_dirs:
                    data_folder = "Data"
                    returned_json["idfdir"] = (returned_json["pythonsrcdir"] +
                                               warrior_path + "/Data")
                elif "data" in child_dirs:
                    data_folder = "data"
                    returned_json["idfdir"] = (returned_json["pythonsrcdir"] +
                                               warrior_path + "/data")
                else:
                    data_folder = "Data"
                    if not os.path.exists(returned_json["pythonsrcdir"] +
                                          warrior_path + "/Data"):
                        os.mkdir(returned_json["pythonsrcdir"] + warrior_path +
                                 "/Data")
                    returned_json["idfdir"] = (returned_json["pythonsrcdir"] +
                                               warrior_path + "/Data")

                if "Config_files" in child_dirs:
                    config_folder = "Config_files"
                    returned_json["testdata"] = (
                        returned_json["pythonsrcdir"] + warrior_path +
                        "/Config_files")
                elif "config_files" in child_dirs:
                    config_folder = "config_files"
                    returned_json["testdata"] = (
                        returned_json["pythonsrcdir"] + warrior_path +
                        "/config_files")
                else:
                    config_folder = "Config_files"
                    if not os.path.exists(returned_json["pythonsrcdir"] +
                                          warrior_path + "/Config_files"):
                        os.mkdir(returned_json["pythonsrcdir"] + warrior_path +
                                 "/Config_files")
                    returned_json["testdata"] = (
                        returned_json["pythonsrcdir"] + warrior_path +
                        "/Config_files")

                if "wrapper_files" in child_dirs:
                    wrapper_folder = "wrapper_files"
                    returned_json["testwrapper"] = (
                        returned_json["pythonsrcdir"] + warrior_path +
                        "/wrapper_files")
                elif "Wrapper_files" in child_dirs:
                    wrapper_folder = "Wrapper_files"
                    returned_json["testwrapper"] = (
                        returned_json["pythonsrcdir"] + warrior_path +
                        "/Wrapper_files")
                else:
                    wrapper_folder = "wrapper_files"
                    if not os.path.exists(returned_json["pythonsrcdir"] +
                                          warrior_path + "/wrapper_files"):
                        os.mkdir(returned_json["pythonsrcdir"] + warrior_path +
                                 "/wrapper_files")
                    returned_json["testwrapper"] = (
                        returned_json["pythonsrcdir"] + warrior_path +
                        "/wrapper_files")
            else:

                if "Testcases" in base_tree:
                    test_case_folder = "Testcases"

                elif "testcases" in base_tree:
                    test_case_folder = "testcases"

                if "Suites" in base_tree:
                    suites_folder = "Suites"

                elif "suites" in base_tree:
                    suites_folder = "suites"

                if "Projects" in base_tree:
                    project_folder = "Projects"

                elif "projects" in base_tree:
                    project_folder = "projects"

                if "Data" in base_tree:
                    data_folder = "Data"

                elif "data" in base_tree:
                    data_folder = "data"

                if "Config_files" in base_tree:
                    config_folder = "Config_files"

                elif "config_files" in base_tree:
                    config_folder = "config_files"

                if "wrapper_files" in base_tree:
                    wrapper_folder = "wrapper_files"

                elif "Wrapper_files" in base_tree:
                    wrapper_folder = "Wrapper_files"

                sub_folders = {
                    test_case_folder: "xmldir",
                    suites_folder: "testsuitedir",
                    project_folder: "projdir",
                    data_folder: "idfdir",
                    config_folder: "testdata",
                    wrapper_folder: "testwrapper",
                }
                list_of_keys = list(sub_folders.keys())
                for folder in list_of_keys:
                    try:
                        os.mkdir(returned_json["pythonsrcdir"] + "/" + folder)
                        returned_json[sub_folders[folder]] = (
                            returned_json["pythonsrcdir"] + "/" + folder)
                    except FileExistsError:
                        returned_json[sub_folders[folder]] = (
                            returned_json["pythonsrcdir"] + "/" + folder)
        else:
            os.mkdir(returned_json["pythonsrcdir"] + "/Warriorspace")
            sub_folders = {
                "Testcases": "xmldir",
                "Suites": "testsuitedir",
                "Projects": "projdir",
                "Data": "idfdir",
                "Config_files": "testdata",
                "wrapper_files": "testwrapper",
            }
            for folder in [
                    "Testcases",
                    "Suites",
                    "Data",
                    "wrapper_files",
                    "Config_files",
                    "Projects",
            ]:
                os.mkdir(returned_json["pythonsrcdir"] + "/Warriorspace/" +
                         folder)
                returned_json[sub_folders[folder]] = (
                    returned_json["pythonsrcdir"] + "/Warriorspace/" + folder)

    with open(config_json_path, "w") as f:
        f.write(json.dumps(returned_json, indent=4))
    return HttpResponse(request)
示例#26
0
文件: views.py 项目: terrakom/wapps
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
示例#27
0
def read_config_file_data():
        """this function reads the data from appconfig.json file"""
        data = read_json_data(app_config_file)
        return data