Exemplo n.º 1
0
def index(request):
    navigator = Navigator()
    path_to_config = navigator.get_katana_dir() + os.sep + "config.json"
    config = json.loads(open(path_to_config).read())
    fpath = config['projdir']
    template = loader.get_template("./listAllProjects.html")
    files = glob.glob(fpath + "*/*.xml")

    tt = navigator.get_dir_tree_json(fpath)
    tt['state'] = {
        'opened': True
    }
    print(tt)

    fulljsonstring = str(json.loads(json.dumps(tt)))
    fulljsonstring = fulljsonstring.replace('u"', "'").replace("u'",
                                                               '"').replace(
                                                                   "'", '"')
    fulljsonstring = fulljsonstring.replace('None', '""')

    context = {
        'title': 'List of Projects',
        'docSpec': 'projectSpec',
        'treejs': fulljsonstring,
        'listOfFiles': files
    }
    context.update(csrf(request))
    return HttpResponse(template.render(context, request))
Exemplo n.º 2
0
def get_file_explorer_data(request):
    nav_obj = Navigator()
    if "data[start_dir]" in request.POST and request.POST["data[start_dir]"] != "false":
        start_dir = request.POST["data[start_dir]"]
    elif "data[path]" in request.POST and request.POST["data[path]"] != "false":
        start_dir = get_parent_directory(request.POST["data[path]"])
    else:
        start_dir = join_path(nav_obj.get_warrior_dir(), "Warriorspace")
    output = nav_obj.get_dir_tree_json(start_dir_path=start_dir)
    return JsonResponse(output)
Exemplo n.º 3
0
class Execution(object):
    """
    Execution app class
    """
    def __init__(self):
        """
        Constructor for execution app
        """
        self.nav = Navigator()
        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')
        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']

        return StreamingHttpResponse(
            stream_warrior_output(self.warrior, cmd_string,
                                  execution_file_list, live_html_res_file,
                                  python_path))