def __init__(self, json_data, path, base_directory): """Constructor of the App Class""" self.data = json_data self.path = get_relative_path(path, base_directory) self.static_file_dir = join_path("static", get_dir_from_path(path)) self.app_type = get_dir_from_path(get_parent_directory(path)) self.app_dir_name = get_dir_from_path(path)
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)
def get_actions(self, driver): """ This function gets all the keywords associated with a particular driver """ flag = True if driver not in self.information: flag = False all_drivers = self._get_drivers() for key, value in all_drivers.items(): if key not in self.information: self.information[key] = value if key == driver: flag = True if not flag: print( "-- An Error Occurred -- {0} does not exist in the {1} directory" .format(driver, self.pd_dir)) return False else: if self.information[driver]["actions"] is None: package_list = self._get_package_list( self.information[driver]["path"]) for package in package_list: actions_files = [ x for x in self._get_action_files(package) if get_dir_from_path(x) != "__init__.py" ] for actions_file in actions_files: if self.information[driver]["actions"] is None: self.information[driver][ "actions"] = self._get_actions(actions_file) else: self.information[driver]["actions"].update( self._get_actions(actions_file)) return self.information[driver]["actions"]
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"})
def get_pd_names(self): if len(self.driver_files_list) == 0: self.driver_files_list = self.get_pd_file_list() driver_names = [] for driver in self.driver_files_list: driver_names.append(get_dir_from_path(driver)) return driver_names
def get_pd_file_list(self): self.driver_files_list = [] temp = get_paths_of_subfiles(self.pd_dir, extension=re.compile("\.py$")) for driver_file in temp: if not get_dir_from_path(driver_file) == "__init__.py": self.driver_files_list.append(driver_file) return self.driver_files_list
def _get_drivers(self): """This function gets all the drivers in the ProductDrivers directory""" all_drivers = {} all_driver_files = get_direct_sub_files( self.pd_dir, abs_path=True, extension=compile_regex("^\.py$")) for file_path in all_driver_files: driver_name = get_dir_from_path(file_path).split(".")[0] if driver_name != "__init__": all_drivers[driver_name] = {"path": file_path, "actions": None} return all_drivers
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 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)
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" })
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)
def __add_plugins(self): output = True for plugin in self.plugins_paths: if output: plugin_name = get_dir_from_path(plugin) temp_pl_path = join_path(self.plugin_directory, plugin_name) if os.path.exists(temp_pl_path): output = False message = "-- An Error Occurred -- Directory already exists: {0}.".format( temp_pl_path) print(message) self.message += message else: output = copy_dir(plugin, temp_pl_path) self.delete_plugins_dir.append(plugin) return output
def __map_actions_to_driver(self): actions_for_driver_dict = self.__get_action_packages() for driver_file, actions_package_list in actions_for_driver_dict.items( ): actions_dir_paths = [] for actions_package in actions_package_list: actions_dir_paths.append( os.path.join(self.repo_directory, actions_package.replace(".", os.sep))) actions_file_paths = [] for actions_package in actions_dir_paths: temp = get_paths_of_subfiles(actions_package, extension=re.compile("\.py$")) for actions_file in temp: if not get_dir_from_path(actions_file) == "__init__.py": actions_file_paths.append(actions_file) actions_for_driver_dict[driver_file] = copy.copy( actions_file_paths) return actions_for_driver_dict
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 = []
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
def __init__(self, base_directory, path_to_app): self.base_directory = base_directory self.app_directory = join_path(self.base_directory, "katana", "wapps") self.plugin_directory = join_path(self.base_directory, "warrior", "plugins") 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.path_to_app = path_to_app self.app_name = get_dir_from_path(path_to_app) self.path_to_plugin_dir = join_path(path_to_app, "plugins") self.wf_config_file = join_path(self.path_to_app, "wf_config.json") self.plugins_paths = get_sub_folders(self.path_to_plugin_dir, abs_path=True) self.pkg_in_settings = "katana.wapps.{0}".format(self.app_name) self.urls_inclusions = [] self.settings_backup = [] self.urls_backup = [] self.delete_app_dir = [] self.delete_plugins_dir = [] self.config_data = None self.message = ""