Esempio n. 1
0
    def get(self, workspace):
        #
        # @TODO potential LFI here
        #
        # get specific module
        module = request.args.get('module')
        ws_name = os.path.basename(os.path.normpath(workspace))

        if ws_name in os.listdir(self.options['WORKSPACES']):

            ws_json = self.options['WORKSPACES'] + \
                "/{0}/log.json".format(ws_name)
            if os.path.isfile(ws_json):
                raw_logs = utils.reading_json(ws_json)

                log = raw_logs
                for key in raw_logs.keys():
                    for i in range(len(raw_logs[key])):
                        log[key][i]['std_path'] = utils.replace_argument(self.options, raw_logs[key][i].get(
                            'std_path')).replace(self.options['WORKSPACES'], '')

                        log[key][i]['output_path'] = utils.replace_argument(self.options, raw_logs[key][i].get(
                            'output_path')).replace(self.options['WORKSPACES'], '')

                if module:
                    cmds = log.get(module)
                    return {'commands': cmds}
                else:
                    return log

        return 'Custom 404 here', 404
Esempio n. 2
0
    def get(self, workspace):
        #
        # @TODO potential LFI here
        #
        # get specific module
        module = request.args.get('module')
        ws_name = os.path.basename(os.path.normpath(workspace))

        if ws_name in os.listdir(self.options['WORKSPACES']):

            ws_json = self.options['WORKSPACES'] + \
                "/{0}/log.json".format(ws_name)
            if os.path.isfile(ws_json):
                raw_logs = utils.reading_json(ws_json)

                log = raw_logs
                for key in raw_logs.keys():
                    for i in range(len(raw_logs[key])):
                        log[key][i]['std_path'] = utils.replace_argument(
                            self.options,
                            raw_logs[key][i].get('std_path')).replace(
                                self.options['WORKSPACES'], '')

                        log[key][i]['output_path'] = utils.replace_argument(
                            self.options,
                            raw_logs[key][i].get('output_path')).replace(
                                self.options['WORKSPACES'], '')

                if module:
                    cmds = log.get(module)
                    return {'commands': cmds}
                else:
                    return log

        return 'Custom 404 here', 404
Esempio n. 3
0
    def get_routine(self, workspace, profile):

        # get options depend on workspace
        options_path = current_path + \
            '/storages/{0}/options.json'.format(workspace)

        commands_path = current_path + '/storages/commands.json'
        self.options = utils.reading_json(options_path)

        if not self.options:
            return None

        self.commands = utils.reading_json(commands_path)

        raw_routine = {}
        for key, value in self.commands.items():
            raw_routine[key] = self.commands[key].get(profile)

        routines = {}
        for module, cmds in raw_routine.items():
            routines[module] = []
            if cmds:
                for item in cmds:
                    real_item = {}
                    for k, v in item.items():
                        real_item[k] = utils.replace_argument(self.options, v)
                    routines[module].append(real_item)

        return routines
Esempio n. 4
0
    def post(self, workspace):
        ws_name = utils.get_workspace(workspace=workspace)
        options_path = current_path + \
            '/storages/{0}/options.json'.format(ws_name)
        self.options = utils.reading_json(options_path)

        module = request.args.get('module')

        ws_name = os.path.basename(os.path.normpath(workspace))
        ws_name_encode = utils.url_encode(ws_name)

        utils.print_debug(ws_name)

        if ws_name in os.listdir(self.options['WORKSPACES']):
            ws_json = self.options['WORKSPACES'] + "/{0}/log.json".format(
                ws_name)
            raw_logs = utils.reading_json(ws_json)

        elif ws_name_encode in os.listdir(self.options['WORKSPACES']):
            ws_json = self.options['WORKSPACES'] + "/{0}/log.json".format(
                utils.url_encode(ws_name))
            # utils.print_debug(ws_json_encode)
            raw_logs = utils.reading_json(ws_json)

        if raw_logs:
            all_commands = []

            for k in raw_logs.keys():
                for item in raw_logs[k]:
                    cmd_item = item
                    cmd_item["module"] = k
                    cmd_item['std_path'] = utils.replace_argument(
                        self.options, item.get('std_path')).replace(
                            self.options['WORKSPACES'], '')
                    cmd_item['output_path'] = utils.replace_argument(
                        self.options, item.get('output_path')).replace(
                            self.options['WORKSPACES'], '')
                    cmd_item["module"] = k
                    all_commands.append(cmd_item)

            return {"commands": all_commands}
        else:
            return {
                "error":
                "Not found logs file for {0} workspace".format(ws_name)
            }
def get_new_command(command):
    broken_cmd = re.findall(r"Command \"([^']*)\" is not defined",
                            command.stderr)[0]
    new_cmd = re.findall(r'Did you mean this\?[^\n]*\n\s*([^\n]*)',
                         command.stderr)
    if not new_cmd:
        new_cmd = re.findall(r'Did you mean one of these\?[^\n]*\n\s*([^\n]*)',
                             command.stderr)
    return replace_argument(command.script, broken_cmd, new_cmd[0].strip())
Esempio n. 6
0
def get_new_command(command):
    stash_cmd = command.script_parts[2]
    fixed = utils.get_closest(stash_cmd, stash_commands, fallback_to_first=False)

    if fixed is not None:
        return replace_argument(command.script, stash_cmd, fixed)
    else:
        cmd = command.script_parts[:]
        cmd.insert(2, 'save')
        return ' '.join(cmd)
Esempio n. 7
0
def get_new_command(command):
    missing_file = re.findall(
        r"error: pathspec '([^']*)' "
        r"did not match any file\(s\) known to git.", command.stderr)[0]
    closest_branch = utils.get_closest(missing_file, get_branches(),
                                       fallback_to_first=False)
    if closest_branch:
        return replace_argument(command.script, missing_file, closest_branch)
    else:
        return shell.and_('git branch {}', '{}').format(
            missing_file, command.script)
Esempio n. 8
0
    def post(self, workspace):
        module = request.args.get('module')
        ws_name = os.path.basename(os.path.normpath(workspace))
        if ws_name in os.listdir(self.options['WORKSPACES']):
            ws_json = self.options['WORKSPACES'] + \
                "/{0}/log.json".format(ws_name)
            raw_logs = utils.reading_json(ws_json)
            all_commands = []

            for k in raw_logs.keys():
                for item in raw_logs[k]:
                    cmd_item = item
                    cmd_item["module"] = k
                    cmd_item['std_path'] = utils.replace_argument(
                        self.options, item.get('std_path')).replace(self.options['WORKSPACES'], '')
                    cmd_item['output_path'] = utils.replace_argument(
                        self.options, item.get('output_path')).replace(self.options['WORKSPACES'], '')
                    cmd_item["module"] = k
                    all_commands.append(cmd_item)

        return {"commands": all_commands}
Esempio n. 9
0
def get_new_command(command):
    missing_file = re.findall(
        r"error: pathspec '([^']*)' "
        r"did not match any file\(s\) known to git.", command.stderr)[0]
    closest_branch = utils.get_closest(missing_file,
                                       get_branches(),
                                       fallback_to_first=False)
    if closest_branch:
        return replace_argument(command.script, missing_file, closest_branch)
    else:
        return shell.and_('git branch {}',
                          '{}').format(missing_file, command.script)
Esempio n. 10
0
def get_new_command(command):
    stash_cmd = command.script_parts[2]
    fixed = utils.get_closest(stash_cmd,
                              stash_commands,
                              fallback_to_first=False)

    if fixed is not None:
        return replace_argument(command.script, stash_cmd, fixed)
    else:
        cmd = command.script_parts[:]
        cmd.insert(2, 'save')
        return ' '.join(cmd)
Esempio n. 11
0
    def post(self, workspace):
        module = request.args.get('module')
        ws_name = os.path.basename(os.path.normpath(workspace))
        if ws_name in os.listdir(self.options['WORKSPACES']):
            ws_json = self.options['WORKSPACES'] + \
                "/{0}/log.json".format(ws_name)
            raw_logs = utils.reading_json(ws_json)
            all_commands = []

            for k in raw_logs.keys():
                for item in raw_logs[k]:
                    cmd_item = item
                    cmd_item["module"] = k
                    cmd_item['std_path'] = utils.replace_argument(
                        self.options, item.get('std_path')).replace(
                            self.options['WORKSPACES'], '')
                    cmd_item['output_path'] = utils.replace_argument(
                        self.options, item.get('output_path')).replace(
                            self.options['WORKSPACES'], '')
                    cmd_item["module"] = k
                    all_commands.append(cmd_item)

        return {"commands": all_commands}
Esempio n. 12
0
    def get(self, workspace):
        # get options depend on workspace
        ws_name = utils.get_workspace(workspace=workspace)
        options_path = str(
            BASE_DIR.joinpath('storages/{0}/options.json'.format(ws_name)))

        self.options = utils.reading_json(options_path)

        module = request.args.get('module')
        ws_name = os.path.basename(os.path.normpath(workspace))

        if ws_name in os.listdir(self.options['WORKSPACES']):
            ws_json = self.options['WORKSPACES'] + \
                "/{0}/log.json".format(ws_name)
            if os.path.isfile(ws_json):
                raw_logs = utils.reading_json(ws_json)

                log = raw_logs
                for key in raw_logs.keys():
                    for i in range(len(raw_logs[key])):
                        log[key][i]['std_path'] = utils.replace_argument(
                            self.options,
                            raw_logs[key][i].get('std_path')).replace(
                                self.options['WORKSPACES'], '')

                        log[key][i]['output_path'] = utils.replace_argument(
                            self.options,
                            raw_logs[key][i].get('output_path')).replace(
                                self.options['WORKSPACES'], '')

                if module:
                    cmds = log.get(module)
                    return {'commands': cmds}
                else:
                    return log

        return 'Custom 404 here', 404
Esempio n. 13
0
    def get_routine(self, profile):
        raw_routine = {}
        for key, value in self.commands.items():
            raw_routine[key] = self.commands[key].get(profile)

        routines = {}
        for module, cmds in raw_routine.items():
            routines[module] = []
            if cmds:
                for item in cmds:
                    real_item = {}
                    for k, v in item.items():
                        real_item[k] = utils.replace_argument(self.options, v)
                    routines[module].append(real_item)

        return routines
Esempio n. 14
0
    def get_routine(self, profile):
        raw_routine = {}
        for key, value in self.commands.items():
            raw_routine[key] = self.commands[key].get(profile)

        routines = {}
        for module, cmds in raw_routine.items():
            routines[module] = []
            if cmds:
                for item in cmds:
                    real_item = {}
                    for k, v in item.items():
                        real_item[k] = utils.replace_argument(self.options, v)
                    routines[module].append(real_item)

        return routines
Esempio n. 15
0
    def get(self, workspace):
        # module = request.args.get('module')
        ws_name = os.path.basename(os.path.normpath(workspace))
        # print(ws_name)
        # change to current workspace instead of get from running target
        self.options['WORKSPACE'] = self.options['WORKSPACES'] + ws_name
        self.options['OUTPUT'] = ws_name

        reports = []

        for k in self.commands.keys():
            if "report" in self.commands[k].keys():
                report = utils.replace_argument(
                    self.options, self.commands[k].get("report"))

                report_item = {"module": k, "report": report}
                if utils.not_empty_file(report_item['report']):
                    report_item['report'] = report.replace(self.options['WORKSPACE'], ws_name)
                    reports.append(report_item)

        return {'reports': reports}
Esempio n. 16
0
    def get(self, workspace):
        # module = request.args.get('module')
        ws_name = os.path.basename(os.path.normpath(workspace))
        # print(ws_name)
        # change to current workspace instead of get from running target
        self.options['WORKSPACE'] = self.options['WORKSPACES'] + ws_name
        self.options['OUTPUT'] = ws_name

        reports = []

        for k in self.commands.keys():
            if "report" in self.commands[k].keys():
                report = utils.replace_argument(self.options,
                                                self.commands[k].get("report"))
                report_item = {
                    "module": k,
                    "report": report.replace(self.options['WORKSPACE'],
                                             ws_name)
                }
                reports.append(report_item)

        return {'reports': reports}
Esempio n. 17
0
    def get(self, workspace):
        module = request.args.get('module')
        ws_name = os.path.basename(os.path.normpath(workspace))
        # print(ws_name)
        # change to current workspace instead of get from running target
        self.options['WORKSPACE'] = self.options['WORKSPACES'] + ws_name
        self.options['OUTPUT'] = ws_name

        reports = {}
        for key, value in self.commands.items():
            raw_report = self.commands[key].get('report')
            reports[key] = "N/A"
            if raw_report:
                real_report = utils.replace_argument(
                    self.options, self.commands[key].get('report'))
                if utils.not_empty_file(real_report):
                    reports[key] = real_report.replace(
                        self.options['WORKSPACES'], '')

        if module is not None:
            reports = reports.get(module)

        return {'reports': reports}
Esempio n. 18
0
def get_new_command(command):
    not_exist_formula = re.findall(r'Error: No available formula for ([a-z]+)',
                                   command.stderr)[0]
    exist_formula = _get_similar_formula(not_exist_formula)

    return replace_argument(command.script, not_exist_formula, exist_formula)
Esempio n. 19
0
    def get(self, workspace):
        # module = request.args.get('module')
        ws_name = os.path.basename(os.path.normpath(workspace))
        options_path = str(BASE_DIR.joinpath('storages/{0}/options.json'.format(ws_name)))
        self.options = utils.reading_json(options_path)

        if not self.options:
            return {"error": "Workspace {0} not found".format(ws_name)}

        # get commands
        commands_path = str(BASE_DIR.joinpath('commands.json'))
        self.commands = utils.reading_json(commands_path)

        # change to current workspace instead of get from running target
        self.options['WORKSPACE'] = self.options['WORKSPACES'] + ws_name
        self.options['OUTPUT'] = ws_name

        final_reports = []

        # reports = {}
        for key in self.commands.keys():
            final_reports.append({
                "module": key,
                "reports": []
            })

        for k in self.commands.keys():
            if "report" in self.commands[k].keys():
                report = utils.replace_argument(self.options, self.commands[k].get("report"))
                # print(report)
                if type(report) == str:
                    if utils.not_empty_file(report):
                        report_path = report.replace(
                            self.options.get('WORKSPACE'), ws_name)

                        report_item = {
                            "path": report_path,
                            "type": "html",
                        }
                        for i in range(len(final_reports)):
                            if final_reports[i].get('module') == k:
                                final_reports[i]["reports"].append(
                                    report_item)
                        # final_reports[k]["reports"].append(report_item)
                elif type(report) == list:
                    for item in report:
                        report_path = utils.replace_argument(self.options, item.get("path"))
                        if utils.not_empty_file(report_path):
                            report_path = report_path.replace(
                                self.options.get('WORKSPACE'), ws_name)

                            report_item = {
                                "path": report_path,
                                "type": item.get("type"),
                            }
                            for i in range(len(final_reports)):
                                if final_reports[i].get('module') == k:
                                    final_reports[i]["reports"].append(report_item)

        # just clean up
        clean_reports = []
        for i in range(len(final_reports)):
            if final_reports[i].get('reports'):
                clean_reports.append(final_reports[i])

        return {'reports': clean_reports}
Esempio n. 20
0
def get_new_command(command):
    return replace_argument(command.script, '-d', '-D')
def get_new_command(command):
    return replace_argument(command.script, 'set-url', 'add')
Esempio n. 22
0
def get_new_command(command):
    return replace_argument(command.script, 'pull', 'clone')
def get_new_command(command):
    broken_cmd = re.findall(r"Command \"([^']*)\" is not defined", command.stderr)[0]
    new_cmd = re.findall(r'Did you mean this\?[^\n]*\n\s*([^\n]*)', command.stderr)
    if not new_cmd:
        new_cmd = re.findall(r'Did you mean one of these\?[^\n]*\n\s*([^\n]*)', command.stderr)
    return replace_argument(command.script, broken_cmd, new_cmd[0].strip())
Esempio n. 24
0
def get_new_command(command):
    npm_commands = _get_available_commands(command.stdout)
    wrong_command = _get_wrong_command(command.script_parts)
    fixed = get_closest(wrong_command, npm_commands)
    return replace_argument(command.script, wrong_command, fixed)
def get_new_command(command):
    broken_cmd = re.findall(r'ERROR: unknown command \"([a-z]+)\"',
                            command.stderr)[0]
    new_cmd = re.findall(r'maybe you meant \"([a-z]+)\"', command.stderr)[0]

    return replace_argument(command.script, broken_cmd, new_cmd)
Esempio n. 26
0
def get_new_command(command):
    not_exist_formula = re.findall(r'Error: No available formula for ([a-z]+)',
                                   command.stderr)[0]
    exist_formula = _get_similar_formula(not_exist_formula)

    return replace_argument(command.script, not_exist_formula, exist_formula)
Esempio n. 27
0
def get_new_command(command):
    return replace_argument(command.script, 'push', 'push --force-with-lease')
Esempio n. 28
0
def get_new_command(command):
    to = command.stderr.split('`')[1]
    return replace_argument(command.script, to[1:], to)
Esempio n. 29
0
def get_new_command(command):
    return replace_argument(command.script, 'pull', 'clone')
Esempio n. 30
0
def get_new_command(command):
    return replace_argument(command.script, 'diff', 'diff --staged')
Esempio n. 31
0
def get_new_command(command):
    return shell.and_(replace_argument(command.script, 'push', 'pull'),
                      command.script)
Esempio n. 32
0
def get_new_command(command):
    npm_commands = _get_available_commands(command.stdout)
    wrong_command = _get_wrong_command(command.script_parts)
    fixed = get_closest(wrong_command, npm_commands)
    return replace_argument(command.script, wrong_command, fixed)
def get_new_command(command):
    broken_cmd = re.findall(r'ERROR: unknown command \"([a-z]+)\"',
                            command.stderr)[0]
    new_cmd = re.findall(r'maybe you meant \"([a-z]+)\"', command.stderr)[0]

    return replace_argument(command.script, broken_cmd, new_cmd)
Esempio n. 34
0
def get_new_command(command):
    broken = command.script_parts[1]
    fix = re.findall(r'Did you mean `([^`]*)`', command.stderr)[0]

    return replace_argument(command.script, broken, fix)