Пример #1
0
def after_prompt_install(request):
    app_path = request.POST.get("app_paths")
    app_name = get_dir_from_path(app_path)
    dot_data_dir = join_path(nav_obj.get_katana_dir(), "native",
                             "wapp_management", ".data")
    temp_dir_path = join_path(dot_data_dir, "temp")
    output_data = {"status": True, "message": ""}

    if os.path.exists(temp_dir_path):
        shutil.rmtree(temp_dir_path)
    create_dir(temp_dir_path)

    if app_path.endswith(".git"):
        repo_name = get_repository_name(app_path)
        os.system("git clone {0} {1}".format(
            app_path, join_path(temp_dir_path, repo_name)))
        app_path = join_path(temp_dir_path, repo_name)
    elif app_path.endswith(".zip"):
        if os.path.exists(app_path):
            temp = app_path.split(os.sep)
            temp = temp[len(temp) - 1]
            shutil.copyfile(app_path, join_path(temp_dir_path, temp))
            zip_ref = zipfile.ZipFile(join_path(temp_dir_path, temp), 'r')
            zip_ref.extractall(temp_dir_path)
            zip_ref.close()
            app_path = join_path(temp_dir_path, temp[:-4])
        else:
            output_data["status"] = False
            output_data[
                "message"] = "-- An Error Occurred -- {0} does not exist".format(
                    app_path)
            print(output_data["message"])
    else:
        if os.path.isdir(app_path):
            filename = get_dir_from_path(app_path)
            copy_dir(app_path, join_path(temp_dir_path, filename))
            app_path = join_path(temp_dir_path, filename)
        else:
            output_data["status"] = False
            output_data[
                "message"] = "-- An Error Occurred -- {0} does not exist".format(
                    app_path)
            print(output_data["message"])
    if os.path.exists(
            join_path(get_parent_directory(nav_obj.get_katana_dir()), "katana",
                      "wapps", app_name)):
        output_data["status"] = True
        output_data["message"] = "{0} app installed succesfully.".format(
            app_name)
        remove_appurl_from_urls_custom(app_name, "wapps")
        remove_app_from_settings_custom(app_name, "wapps")
        remove_cust_app_source(app_name, "wapps")
    #ping thread
    install_custom_app(app_name, app_path)
    return JsonResponse(output_data)
Пример #2
0
def install_an_app(request):
    app_path = request.POST.get("app_paths")
    dot_data_dir = join_path(nav_obj.get_katana_dir(), "native",
                             "wapp_management", ".data")
    temp_dir_path = join_path(dot_data_dir, "temp")
    output_data = {"status": True, "message": ""}

    if os.path.exists(temp_dir_path):
        shutil.rmtree(temp_dir_path)
    create_dir(temp_dir_path)

    if app_path.endswith(".git"):
        repo_name = get_repository_name(app_path)
        os.system("git clone {0} {1}".format(
            app_path, join_path(temp_dir_path, repo_name)))
        app_path = join_path(temp_dir_path, repo_name)
    elif app_path.endswith(".zip"):
        if os.path.exists(app_path):
            temp = app_path.split(os.sep)
            temp = temp[len(temp) - 1]
            shutil.copyfile(app_path, join_path(temp_dir_path, temp))
            zip_ref = zipfile.ZipFile(join_path(temp_dir_path, temp), 'r')
            zip_ref.extractall(temp_dir_path)
            zip_ref.close()
            app_path = join_path(temp_dir_path, temp[:-4])
        else:
            output_data["status"] = False
            output_data[
                "message"] = "-- An Error Occurred -- {0} does not exist".format(
                    app_path)
            print(output_data["message"])
    else:
        if os.path.isdir(app_path):
            filename = get_dir_from_path(app_path)
            copy_dir(app_path, join_path(temp_dir_path, filename))
            app_path = join_path(temp_dir_path, filename)
        else:
            output_data["status"] = False
            output_data[
                "message"] = "-- An Error Occurred -- {0} does not exist".format(
                    app_path)
            print(output_data["message"])
    installer_obj = Installer(get_parent_directory(nav_obj.get_katana_dir()),
                              app_path)
    installer_output = installer_obj.install()
    if installer_obj.message != "" and installer_output != "Prompt":
        output_data["status"] = False
        output_data["message"] += "\n" + installer_obj.message
    elif installer_obj.message != "" and installer_output == "Prompt":
        output_data["status"] = "Prompt"
        output_data["message"] += "\n" + installer_obj.message
    return JsonResponse(output_data)
Пример #3
0
def validate_app_path(request):
    output = {"status": True, "message": ""}
    detail_type = request.POST.get("type", None)
    detail_info = request.POST.get("value", None)
    dot_data_dir = join_path(nav_obj.get_katana_dir(), "katana.native",
                             "wapp_management", ".data")
    temp_dir_path = join_path(dot_data_dir, "temp")
    app_path = False

    if os.path.exists(temp_dir_path):
        shutil.rmtree(temp_dir_path)
    if create_dir(temp_dir_path):
        if detail_type == "repository":
            repo_name = get_repository_name(detail_info)
            os.system("git clone {0} {1}".format(
                detail_info, join_path(temp_dir_path, repo_name)))
            app_path = join_path(temp_dir_path, repo_name)
        elif detail_type == "zip":
            if os.path.exists(detail_info):
                temp = detail_info.split(os.sep)
                temp = temp[len(temp) - 1]
                shutil.copyfile(detail_info, join_path(temp_dir_path, temp))
                zip_ref = zipfile.ZipFile(join_path(temp_dir_path, temp), 'r')
                zip_ref.extractall(temp_dir_path)
                zip_ref.close()
                app_path = join_path(temp_dir_path, temp[:-4])
            else:
                output["status"] = False
                output["message"] = "{0} does not exist".format(detail_info)
                print("-- An Error Occurred -- ".format(output["message"]))
        elif detail_type == "filepath":
            if os.path.isdir(detail_info):
                filename = get_dir_from_path(detail_info)
                copy_dir(detail_info, join_path(temp_dir_path, filename))
                app_path = join_path(temp_dir_path, filename)
            else:
                output["status"] = False
                output[
                    "message"] = "{0} does not exist or is not a directory".format(
                        detail_info)
                print("-- An Error Occurred -- {0}".format(output["message"]))
        else:
            print("-- An Error Occurred -- Type of validation not given.")
        if app_path:
            app_validator_obj = AppValidator(app_path)
            output = app_validator_obj.is_valid()
    else:
        print("-- An Error Occurred -- Could not create temporary directory.")
    return JsonResponse(output)