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 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)
class Execution(object): """ Execution app class """ 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 index(self, request): """ Index page for exeution app """ execution_settings_dict = update_jira_proj_list( self.jira_settings_file, self.execution_settings_json) #json.loads(open(self.execution_settings_json).read()) start_dir = self.default_ws if execution_settings_dict['defaults']['start_dir'] == 'default' \ else execution_settings_dict['defaults']['start_dir'] execution_settings_dict['defaults']['start_dir'] = start_dir index_template = os.path.join(self.templates_dir, 'execution.html') return render(request, index_template, execution_settings_dict) def get_results_index(self, request): """ Render the results index html to the client """ fname = 'live_html_results' path = data_live_dir fpath = file_utils.get_new_filepath(fname, path, '.html') html_file = open(fpath, 'w') html_file.write('<div data-currentTable="1"> </div> ') html_file.close() result_setting = {'fpath': fpath} results_template = os.path.join(self.templates_dir, 'execution_results.html') return render(request, results_template, result_setting) def get_html_results(self, request): """ Update the html results by reading the live html results file sent in the request """ data_dict = json.loads(request.GET.get('data')) fpath = data_dict['liveHtmlFpath'] with open(fpath) as htmlfile: data = htmlfile.readlines() return HttpResponse(data) def delete_live_html_file(self, request): """ delete the live html file created """ status = 'success' try: data_dict = json.loads(request.GET.get('data')) fpath = data_dict['liveHtmlFpath'] os.remove(fpath) except Exception as err: status = 'failure' return HttpResponse(status) def get_logfile_contents(self, request): """ Update the html results by reading the live html results file sent in the request """ data_dict = json.loads(request.GET.get('data')) logpath = data_dict['logpath'] logtype = data_dict['logtype'] op_data = {} logfile_name = logpath.split(os.sep)[-1] if str(logtype.lower()) == 'defects': contents = json.loads(open(logpath).read()) if str(logtype.lower()) == 'console_logs': contents = open(logpath).read() contents = contents.replace('\n', '<br>') op_data['logfile_name'] = logfile_name op_data['contents'] = contents return JsonResponse(op_data) def cleanup_data_live_dir(self, request): """ Update the html results by reading the live html results file sent in the request """ status = 'success' try: for item in os.listdir(data_live_dir): path = os.path.join(data_live_dir, item) if os.path.isfile( path) and not path.endswith('donotdeletethisfile.txt'): os.remove(path) elif os.path.isdir(path): shutil.rmtree(path, 'ignore_errors') except Exception as err: print("error ceaning up dir {0}".format(data_live_dir)) print(err) status = 'failure' return HttpResponse(status) def get_ws(self, request): """ return the dir tree json for warriorspace """ data_dict = json.loads(request.GET.get('data')) ws_dir = data_dict['start_dir'] layout = self.nav.get_dir_tree_json(ws_dir) return JsonResponse(layout) def execute_warrior(self, request): """ Execute warrior command and send console logs to the client in a streaming fashion. """ data_dict = json.loads(request.GET.get('data')) execution_file_list = data_dict['execution_file_list'] cmd_string = data_dict['cmd_string'] live_html_res_file = data_dict['liveHtmlFpath'] config_json_dict = json.loads(open(self.config_json).read()) python_path = config_json_dict['pythonpath'] katana_dir = os.path.dirname(katana.native.__path__[0]) config_json = os.path.join(katana_dir, 'config.json') config_json_dict = json.loads(open(config_json).read()) pythonpaths = [] for key in config_json_dict.keys(): if key.startswith('userreposdir'): repo = config_json_dict[key].split('/') repo = "/".join(repo[:-1]) pythonpaths.append(repo) pythonpath = ':'.join(pythonpaths) cmd_string = cmd_string + ' -pythonpath {0}'.format(pythonpath) return StreamingHttpResponse( stream_warrior_output(self.warrior, cmd_string, execution_file_list, live_html_res_file, python_path))