Example #1
0
 def get_project(cls, issue):
     project = issue.fields.project
     if project and hasattr(project, 'name') and project.name:
         project_in_tc = Project.query.filter(Project.name == project.name).first()
         if project_in_tc:
             return project_in_tc.id
         else:
             raise CannotFindObjectException(f'project {project} not found in system!')
     else:
         raise CannotFindObjectException(f'project {project} not have name property!')
Example #2
0
    def requirement_handler(cls, key):
        jira_result = None
        requirement_id = None
        user_id = request.args.get('user_id', '')
        user_key = request.args.get('user_key', '')
        try:
            issues = jira.search_issues(f'key={key}')
            if issues:
                issue = issues[0]
                requirement = Requirement.query.filter(Requirement.jira_id == str(issue)).first()
                if requirement:
                    cls.requirement_update_handler(requirement, issue, user_key)
                    requirement_id = requirement.id
                else:
                    cls.requirement_create_handler(issue)
                    requirement = Requirement.query.filter(Requirement.jira_id == str(issue)).first()
                    requirement_id = requirement.id
            else:
                jira_result = f'{user_id} {user_key} - jira cannot found issue with key : {key}'
                raise CannotFindObjectException(jira_result)

            jira_result = f"{user_id} {user_key} - {key} success"
            return 0
        except Exception as e:
            raise e
        finally:
            cls.create(key, jira_result, requirement_id, Jira.KEY_MAP.get('requirement'))
Example #3
0
    def update(cls, id, params):
        (data_source, phone_model, apk_version, kernel_version, system_version, thesaurus_version, corpus_version,
         key_9_and_26, first_word_correct_rate, first_page_correct_rate, comment, show_in_chart) = params

        cls.disable_others(apk_version, show_in_chart)
        data_show = DataShowFirstPageFirstWordCorrectRate.query.get(id)

        if not data_show:
            raise CannotFindObjectException('数据不存在!')
        data_show.data_source = data_source
        data_show.phone_model = phone_model
        data_show.apk_version = apk_version
        data_show.kernel_version = kernel_version
        data_show.system_version = system_version
        data_show.thesaurus_version = thesaurus_version
        data_show.corpus_version = corpus_version
        data_show.key_9_and_26 = key_9_and_26
        data_show.first_word_correct_rate = first_word_correct_rate
        data_show.first_page_correct_rate = first_page_correct_rate
        data_show.comment = comment
        data_show.show_in_chart = show_in_chart
        try:
            db.session.add(data_show)
            db.session.commit()
        except Exception:
            raise CreateObjectException('更新数据失败!')
        return 0
Example #4
0
    def update(cls, id, params):
        (data_source, phone_model, apk_version, kernel_version, system_version, thesaurus_version, corpus_version,
         key_9_kernel_click_time_average, key_26_kernel_click_time_average, key_9_kernel_response_time,
         key_26_kernel_response_time, cpu_average, ram_average, battery_use, comment, show_in_chart) = params

        data_show = DataShowResponseLog.query.get(id)
        cls.disable_others(apk_version, show_in_chart)
        if not data_show:
            raise CannotFindObjectException('数据不存在!')

        data_show.data_source = data_source
        data_show.phone_model = phone_model
        data_show.apk_version = apk_version
        data_show.kernel_version = kernel_version
        data_show.system_version = system_version
        data_show.thesaurus_version = thesaurus_version
        data_show.corpus_version = corpus_version
        data_show.key_9_kernel_click_time_average = key_9_kernel_click_time_average
        data_show.key_26_kernel_click_time_average = key_26_kernel_click_time_average
        data_show.key_9_kernel_response_time = key_9_kernel_response_time
        data_show.key_26_kernel_response_time = key_26_kernel_response_time
        data_show.ram_average = ram_average
        data_show.cpu_average = cpu_average
        data_show.battery_use = battery_use
        data_show.comment = comment
        data_show.show_in_chart = show_in_chart

        try:
            db.session.add(data_show)
            db.session.commit()
        except Exception:
            raise CreateObjectException('更新数据失败!')
        return 0
Example #5
0
    def update(cls, id, params):
        (data_source, phone_model, apk_version, kernel_version, system_version, thesaurus_version, corpus_version,
         key_9_and_26, average, line_90_percent, line_95_percent, comment, show_in_chart) = params

        cls.disable_others(apk_version, show_in_chart)
        data_show_response = DataShowResponseKernelRecord.query.get(id)

        if not data_show_response:
            raise CannotFindObjectException('数据不存在!')
        data_show_response.data_source = data_source
        data_show_response.phone_model = phone_model
        data_show_response.apk_version = apk_version
        data_show_response.kernel_version = kernel_version
        data_show_response.system_version = system_version
        data_show_response.thesaurus_version = thesaurus_version
        data_show_response.corpus_version = corpus_version
        data_show_response.key_9_and_26 = key_9_and_26
        data_show_response.average = average
        data_show_response.line_90_percent = line_90_percent
        data_show_response.line_95_percent = line_95_percent
        data_show_response.comment = comment
        data_show_response.show_in_chart = show_in_chart
        try:
            db.session.add(data_show_response)
            db.session.commit()
        except Exception:
            raise CreateObjectException('更新数据失败!')
        return 0
Example #6
0
def get_config(module, module_type, is_all, project_id=None):
    _query = Config.query.add_columns(
        Config.content.label('content'),
        func.date_format(Config.modified_time,
                         "%Y-%m-%d %H:%i:%s").label('modified_time'),
        Config.id.label('id')).filter(Config.module == module)

    if module_type:
        _query = _query.filter(Config.module_type == int(module_type))

    query = _query.first()

    if project_id:
        query = _query.filter(Config.projectid == int(project_id)).first()

        if not query:
            query = _query.filter(Config.projectid == 0).first()

    if not query:
        raise CannotFindObjectException(
            f'config {module}-{module_type}-{project_id} not found in system!')

    data = query.content

    if not is_all:
        return 0, data
    else:
        return 0, {
            'content': data,
            'modified_time': query.modified_time,
            'id': query.id
        }
Example #7
0
def update_config(config_id, module, module_type, content, description, project_id):
    config = Config.query.get(config_id)
    if not config:
        raise CannotFindObjectException(f'config {config_id} not found in system!')

    module = module if module else config.module
    module_type = module_type if module_type else config.module_type

    if config.projectid in ['0', 0, None, 'null']:
        config_check = Config.query.filter(Config.module == module,
                                           Config.module_type == module_type,
                                           Config.projectid == project_id).first()
        if not config_check:
            current_app.logger.info('should create a new config with this project!')
            return create_config(
                module=module if module is not None else config.module,
                module_type=module_type if module_type is not None else config.module_type,
                content=content if content is not None else config.content,
                description=description if description is not None else config.description,
                project_id=project_id)
        else:
            config = config_check

    with db.auto_commit():
        config.module = module if module is not None else config.module
        config.module_type = module_type if module_type is not None else config.module_type
        config.content = json.dumps(content) if content is not None else config.content
        config.description = description if description is not None else config.description
        db.session.add(config)
    return 0
Example #8
0
    def flow_handler(cls, key):
        requirement = cls.get_requirement_by_jira_key(key)
        if not requirement:
            cls.requirement_handler(key)
            requirement = cls.get_requirement_by_jira_key(key)

        jira_result = None
        user_id = request.args.get('user_id', '')
        user_key = request.args.get('user_key', '')
        try:
            issues = jira.search_issues(f'key={key}')
            if issues:
                issue = issues[0]
                assmble_type = cls.get_assemble_type(issue)
                handler = cls.get_handler(issue)
                creator = cls.get_creator(issue)
                if assmble_type == 1:
                    jira_result = f'{user_id} {user_key} - flow would not create because of assmble_type is 1: {key}'
                    return
                data = {
                    "name": f'{key} - {issue.fields.summary}',
                    "flow_type": 1,
                    "user_test": [cls.get_user("*****@*****.**")],
                    "requirement_list": str(requirement.id),
                    "flow_assemble_id": cls.get_assemble_type(issue),
                    "project_id": cls.get_project(issue),
                    "user_dev": [handler] if handler else [],
                    "user_owner": [handler] if handler else [],
                    "user_prod": [creator] if creator else [],
                    "platform": cls.get_platform(issue),
                    "dependence": cls.get_dependence(issue),
                    "comment": cls.make_comment(requirement),
                    "jira_id": key,
                    "creator": cls.get_creator(issue)
                }
            else:
                jira_result = f'{user_id} {user_key} - jira cannot found issue with key : {key}'
                raise CannotFindObjectException(jira_result)
            response = cls.flow_trpc.requests('post', '/flow/', body=data)
            if isinstance(response, dict):
                if response.get('code') == 0:
                    jira_result = f"{user_id} {user_key} - {key} success"
                else:
                    jira_result = f"{user_id} {user_key} - {key} {response.get('message', 'nothing in message')}"
            else:
                jira_result = f"{user_id} {user_key} - {key} unknown!"
            return 0
        except Exception as e:
            current_app.logger.error(e)
            current_app.logger.error(traceback.format_exc())
            jira_result = f'{user_id} {user_key} - {key} - {str(e)}'
            raise e
        finally:
            cls.create(key, jira_result, requirement.id,
                       Jira.KEY_MAP.get('flow'))
Example #9
0
 def cancel_task(cls, task_id):
     try:
         device_status = MonkeyDeviceStatus.query.get(task_id)
         if device_status:
             device_status.cancel_status = MonkeyDeviceStatus.ACTIVE
             db.session.add(device_status)
             db.session.commit()
         else:
             raise CannotFindObjectException(f'task id: {task_id} not exist')
         return 0, None
     except Exception as e:
         current_app.logger.error(e)
         current_app.logger.error(traceback.format_exc())
         raise RemoveObjectException(f'cancel monkey task : {task_id} failed')
Example #10
0
 def project_detach_user(cls, project_id, user_id):
     user_bind_project = UserBindProject.query.filter_by(
         project_id=project_id, user_id=user_id).first()
     if user_bind_project:
         with db.auto_commit():
             db.session.delete(user_bind_project)
             list_user_bind_role = UserBindRole.query.filter_by(
                 project_id=project_id, user_id=user_id).all()
             [
                 db.session.delete(user_bind_role)
                 for user_bind_role in list_user_bind_role
             ]
         return 0, None
     raise CannotFindObjectException()
Example #11
0
 def get_version_by_title(cls, issue, project_id):
     version_title = issue.fields.fixVersions[0].name if issue.fields.fixVersions else None
     if version_title is None:
         raise CannotFindObjectException(f'issue {issue} does not have fixVersion ! please check the issue !')
     version = Version.query.filter(Version.title == version_title,
                                    Version.project_id == project_id).first()
     if version:
         version_id = version.id
     else:
         VersionBusiness.version_create(title=version_title,
                                        project_id=project_id,
                                        start_time=None,
                                        end_time=None,
                                        description="jira create",
                                        creator=1,)  # 默认的 版本创建人 1
         version_id = cls.get_version_by_title(issue, project_id)
     return version_id