Ejemplo n.º 1
0
def get_api_all_version(id):
    api = models.Api.objects.get(id=id)
    slave_api = api.slave_api
    ret = []
    if not slave_api:
        slave_api = api.id
        source_api = api
    else:
        source_api = models.Api.objects.get(id=slave_api)
    tmp = {}
    tmp["id"] = source_api.id
    tmp["name"] = source_api.name
    tmp["url_param"] = source_api.url_param
    tmp["user"] = source_api.user
    tmp["version"] = source_api.version
    tmp["create"] = public.datetime2str(source_api.create)
    ret.append(tmp)
    api_list = models.Api.objects.filter(slave_api=slave_api)
    for a in api_list:
        tmp = {}
        tmp["id"] = a.id
        tmp["name"] = a.name
        tmp["url_param"] = a.url_param
        tmp["user"] = a.user
        tmp["version"] = a.version
        tmp["create"] = public.datetime2str(a.create)
        ret.append(tmp)
    return ret
Ejemplo n.º 2
0
def get_latest_task_record(task_id):
    task_record = models.TaskRecord.objects.filter(task_id=task_id)
    ret = {}
    if task_record:
        task_record = task_record.latest("id")
        ret = model_to_dict(task_record)
        ret["start_time"] = public.datetime2str(task_record.start_time)
        ret["end_time"] = public.datetime2str(task_record.end_time)
        ret["options"] = json.loads(ret.get("options", "{}"))
        if "trigger_job" in ret["options"]:
            del ret["options"]["trigger_job"]
    return ret
Ejemplo n.º 3
0
def get_latest_task_record(task_id):
    task_record = models.TaskRecord.objects.filter(task_id=task_id)
    ret = {}
    if task_record:
        task_record = task_record.latest("id")
        ret = model_to_dict(task_record)
        ret["start_time"] = public.datetime2str(task_record.start_time)
        ret["end_time"] = public.datetime2str(task_record.end_time)
        ret["options"] = json.loads(ret.get("options", "{}"))
        if "trigger_job" in ret["options"]:
            del ret["options"]["trigger_job"]
    return ret
Ejemplo n.º 4
0
def get_branch_svn_log(request):
    """
    :author: yechengzhou
    :param request: request should contains branch name and module name
    :return: json format branch svn log
    """
    if request.method != "GET":
        return public.fail_result_http(u"该接口只支持GET")
    else:

        module = request.GET.get('module')
        branch = request.GET.get('branch')
        type = request.GET.get('type')  # 0 -- one day  1 -- last 10

        if not (module and branch):
            return public.fail_result_http(u"参数错误")

        else:
            if type == '0' or type == None:
                if branch != "trunk":
                    start = branch.split('_')[-2]
                    start_time = public.str2datetime(start, "%Y%m%d")
                    end_time = start_time + datetime.timedelta(days=1)
                    end = public.datetime2str(end_time, "%Y%m%d")
                    ret = utils.get_branch_svn_log(module, branch, start, end)
                else:
                    ret = utils.get_branch_svn_log(module, branch)

            elif type == '1':
                ret = utils.get_branch_svn_log(module, branch)

            return public.success_result_http(ret)
Ejemplo n.º 5
0
def get_branch_svn_log(request):
    """
    :author: yechengzhou
    :param request: request should contains branch name and module name
    :return: json format branch svn log
    """
    if request.method != "GET":
        return public.fail_result_http(u"该接口只支持GET")
    else:

        module = request.GET.get('module')
        branch = request.GET.get('branch')
        type = request.GET.get('type') # 0 -- one day  1 -- last 10

        if not (module and branch):
            return public.fail_result_http(u"参数错误")

        else:
            if type == '0' or type == None:
                if branch != "trunk":
                    start = branch.split('_')[-2]
                    start_time = public.str2datetime(start, "%Y%m%d")
                    end_time = start_time + datetime.timedelta(days=1)
                    end = public.datetime2str(end_time, "%Y%m%d")
                    ret = utils.get_branch_svn_log(module,branch, start, end)
                else:
                    ret = utils.get_branch_svn_log(module,branch)


            elif type == '1':
                ret = utils.get_branch_svn_log(module,branch )


            return public.success_result_http(ret)
Ejemplo n.º 6
0
def get_module_job_list(module_id):
    ret = []
    jobs = models.Job.objects.filter(module_id=module_id)
    for job in jobs:
        tmp = model_to_dict(job)
        tmp["createTime"] = public.datetime2str(job.createTime)
        tmp["job_detail"] = json.loads(job.job_detail)
        ret.append(tmp)
    return ret
Ejemplo n.º 7
0
def get_module_job(id):
    job = models.Job.objects.filter(id=id)
    ret = {}
    if job:
        job = job[0]
        ret = model_to_dict(job)
        ret["createTime"] = public.datetime2str(job.createTime)
        ret["job_detail"] = json.loads(job.job_detail)
    return ret
Ejemplo n.º 8
0
def get_module_job_list(module_id):
    ret = []
    jobs = models.Job.objects.filter(module_id=module_id)
    for job in jobs:
        tmp = model_to_dict(job)
        tmp["createTime"] = public.datetime2str(job.createTime)
        tmp["job_detail"] = json.loads(job.job_detail)
        ret.append(tmp)
    return ret
Ejemplo n.º 9
0
def get_scene_record(module_id, scene_id):
    records = models.SceneRecord.objects.filter(module_id=module_id, scene_id=scene_id)
    ret = []
    for record in records:
        tmp = model_to_dict(record)
        tmp['update_time'] = public.datetime2str(record.update_time)
        tmp["data"] = json.loads(record.data)
        ret.append(tmp)
    return ret
Ejemplo n.º 10
0
def get_module_job(id):
    job = models.Job.objects.filter(id=id)
    ret = {}
    if job:
        job = job[0]
        ret = model_to_dict(job)
        ret["createTime"] = public.datetime2str(job.createTime)
        ret["job_detail"] = json.loads(job.job_detail)
    return ret
Ejemplo n.º 11
0
def get_scene_record(module_id, scene_id):
    records = models.SceneRecord.objects.filter(module_id=module_id,
                                                scene_id=scene_id)
    ret = []
    for record in records:
        tmp = model_to_dict(record)
        tmp['update_time'] = public.datetime2str(record.update_time)
        tmp["data"] = json.loads(record.data)
        ret.append(tmp)
    return ret
Ejemplo n.º 12
0
def svn_history_only(request):
    module = request.GET.get('module')
    branch = request.GET.get('branch')
    sn = request.GET.get('sn')

    start = branch.split('_')[-2]
    start_time = public.str2datetime(start, "%Y%m%d")
    end_time = start_time + datetime.timedelta(days=1)
    end = public.datetime2str(end_time, "%Y%m%d")

    #start = request.GET.get("start")
    #end = request.GET.get("end")
    import re

    ret = []
    sn_dict = {}
    sn_dict['no_sn'] = []
    if not (module and branch):
        return public.fail_result_http(u"参数错误")
    else:
        tmp_ret = data_utils.get_branch_svn_log(module, branch, start, end)
        #get all sn
        sn_list = []
        for r in tmp_ret:
            tmp = r.get('comment')
            this_sn = tmp[tmp.find('sn=') + 3:tmp.find(';')].strip()
            if this_sn in sn_list:
                continue
            else:
                if re.match('^\d+$', this_sn):
                    sn_list.append(this_sn)
                else:
                    continue
        for r in tmp_ret:
            comment = r.get('comment')
            if comment.find('sn=') != -1:
                sn_no = comment[comment.find('sn=') +
                                3:comment.find(';')].strip()
                if re.match('^\d+$', sn_no):
                    if sn_dict.has_key(sn_no):
                        sn_dict[sn_no].append(r)
                    else:
                        sn_dict[sn_no] = [r]
            else:
                sn_dict['no_sn'].append(r)

        return render(request, 'commitlist.html', {
            'data': sn_dict,
            'sns': sn_list,
        })
Ejemplo n.º 13
0
def online_info(request):
    name = "agile"
    view = data_utils.JenkinsInfo(name)
    ret = []

    online_info_dict = data_utils.get_online_info()

    for i in view.get_ret():
        if i['name'].startswith("newlabs_"):
            i['jobname'] = i['name']
            i['name'] = i['name'][8:]
            ###
            if online_info_dict:
                online_info = online_info_dict.get(i['name'].capitalize())
            else:
                online_info = None

            if online_info != None:
                i['has_online_version'] = True
                i['online_version'] = online_info.get('version')

                # get online version svn info
                branch = online_info.get('version')
                start = branch.split('_')[-2]
                start_time = public.str2datetime(start, "%Y%m%d")
                end_time = start_time + datetime.timedelta(days=1)
                end = public.datetime2str(end_time, "%Y%m%d")
                this_svn = data_utils.get_branch_svn_log(
                    i['name'], branch, start, end)

                sn_dict = {}
                sn_dict['no_sn'] = []
                if this_svn:
                    for r in this_svn:  # get sn and group by sn
                        comment = r.get('comment')
                        if comment.find('sn=') != -1:
                            sn_no = comment[comment.find('sn=') +
                                            3:comment.find(';')].strip()
                            if re.match('^\d+$', sn_no):
                                if sn_dict.has_key(sn_no):
                                    sn_dict[sn_no].append(r)
                                else:
                                    sn_dict[sn_no] = [r]
                        else:
                            sn_dict['no_sn'].append(r)

                i['svn_info'] = sn_dict
                ret.append(i)
    return render(request, 'online.html', {'data': ret})
Ejemplo n.º 14
0
def svn_history_only(request):
    module = request.GET.get('module')
    branch = request.GET.get('branch')
    sn = request.GET.get('sn')

    start = branch.split('_')[-2]
    start_time = public.str2datetime(start, "%Y%m%d")
    end_time = start_time + datetime.timedelta(days=1)
    end = public.datetime2str(end_time, "%Y%m%d")

    #start = request.GET.get("start")
    #end = request.GET.get("end")
    import re

    ret = []
    sn_dict = {}
    sn_dict['no_sn'] = []
    if not (module and branch):
        return public.fail_result_http(u"参数错误")
    else:
        tmp_ret = data_utils.get_branch_svn_log(module,branch, start, end)
        #get all sn
        sn_list = []
        for r in tmp_ret:
            tmp = r.get('comment')
            this_sn = tmp[tmp.find('sn=') + 3: tmp.find(';')].strip()
            if this_sn in sn_list:
                continue
            else:
                if re.match('^\d+$',this_sn):
                    sn_list.append(this_sn)
                else:
                    continue
        for r in tmp_ret:
            comment = r.get('comment')
            if comment.find('sn=') != -1:
                sn_no = comment[comment.find('sn=') + 3: comment.find(';')].strip()
                if re.match('^\d+$',sn_no):
                    if sn_dict.has_key(sn_no):
                        sn_dict[sn_no].append(r)
                    else:
                        sn_dict[sn_no] = [r]
            else:
                sn_dict['no_sn'].append(r)


        return render(request, 'commitlist.html',{'data':sn_dict, 'sns': sn_list, })
Ejemplo n.º 15
0
def online_info(request):
    name = "agile"
    view = data_utils.JenkinsInfo(name)
    ret = []

    online_info_dict =  data_utils.get_online_info()

    for i in view.get_ret():
        if i['name'].startswith("newlabs_"):
            i['jobname'] = i['name']
            i['name'] = i['name'][8:]
            ###
            if online_info_dict:
                online_info = online_info_dict.get(i['name'].capitalize())
            else:
                online_info = None

            if online_info != None:
                i['has_online_version'] = True
                i['online_version'] = online_info.get('version')

                # get online version svn info
                branch = online_info.get('version')
                start = branch.split('_')[-2]
                start_time = public.str2datetime(start, "%Y%m%d")
                end_time = start_time + datetime.timedelta(days=1)
                end = public.datetime2str(end_time, "%Y%m%d")
                this_svn = data_utils.get_branch_svn_log(i['name'],branch, start, end)

                sn_dict = {}
                sn_dict['no_sn'] = []
                if this_svn:
                    for r in this_svn: # get sn and group by sn
                        comment = r.get('comment')
                        if comment.find('sn=') != -1:
                            sn_no = comment[comment.find('sn=') + 3: comment.find(';')].strip()
                            if re.match('^\d+$',sn_no):
                                if sn_dict.has_key(sn_no):
                                    sn_dict[sn_no].append(r)
                                else:
                                    sn_dict[sn_no] = [r]
                        else:
                            sn_dict['no_sn'].append(r)

                i['svn_info'] = sn_dict
                ret.append(i)
    return render(request, 'online.html', {'data': ret})
Ejemplo n.º 16
0
def get_sub_task_info(id):
    sub_task = models.SubTask.objects.get(id=id)
    ret = model_to_dict(sub_task)
    ret["is_start"] = int(sub_task.is_start)
    ret["createTime"] = public.datetime2str(sub_task.createTime)
    return ret
Ejemplo n.º 17
0
def timeline(request):
    if request.method != "GET":
        return public.fail_result_http("Only support GET")

    module = request.REQUEST['module']
    job_name = "newlabs_" + module
    print job_name

    # get online info
    content = data_utils.get_online_package()

    if len(content) != 0:
        online_version = data_utils.get_latest_online_version(content, job_name)
    else:
        return "no online version"
    # get ctime of online version
    online_time = data_utils.get_version_ctime(online_version)

    # get last 2 job record
    job_record_list = data_utils.get_job_record_by_type_job_name(job_name,3,2)
    job_record_list.reverse()


    time1 = job_record_list[0]['time']
    time2 = public.datetime2str(online_time)
    #time2 = job_record_list[1]['time']

    # get svn record between time1 and time2
    svn_list = data_utils.get_branch_svn_log(module, "trunk", start=time1, end=time2)


    # get last trigger record
    trigger_record = data_utils.get_job_record_by_type_job_name(job_name,2,1)[0]

    # merge 2 list sort by time

    if svn_list != None:
        for i in svn_list:
            i['time'] = i['time'][:19]
    else:
        svn_list = []

    ret = [job_record_list[0]] + svn_list + [job_record_list[1]]

    # get trunk svn commit after last sealed

    start =  job_record_list[1]['time']
    end = time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time()))

    after_seal = data_utils.get_branch_svn_log(module, "trunk", start=start, end=end)

    if after_seal != None:
        for j in after_seal:
            j['time'] = j['time'][:19]
    else:
        after_seal = []


    ret.extend(after_seal)

    trigger_record['time'] = trigger_record['time'][:19]
    trigger_record['comment'] = 'publish'

    inserted = False
    for i in range(len(ret)):
        if ret[i]['time'] < trigger_record['time']:
            continue
        else:
            ret.insert(i, trigger_record)
            inserted = True
            break

    if inserted == False:
        ret.append(trigger_record)

    ret.reverse()
    return render(request,'timeline.html', {'data': ret})
Ejemplo n.º 18
0
def timeline(request):
    if request.method != "GET":
        return public.fail_result_http("Only support GET")

    module = request.REQUEST['module']
    job_name = "newlabs_" + module
    print job_name

    # get online info
    content = data_utils.get_online_package()

    if len(content) != 0:
        online_version = data_utils.get_latest_online_version(
            content, job_name)
    else:
        return "no online version"
    # get ctime of online version
    online_time = data_utils.get_version_ctime(online_version)

    # get last 2 job record
    job_record_list = data_utils.get_job_record_by_type_job_name(
        job_name, 3, 2)
    job_record_list.reverse()

    time1 = job_record_list[0]['time']
    time2 = public.datetime2str(online_time)
    #time2 = job_record_list[1]['time']

    # get svn record between time1 and time2
    svn_list = data_utils.get_branch_svn_log(module,
                                             "trunk",
                                             start=time1,
                                             end=time2)

    # get last trigger record
    trigger_record = data_utils.get_job_record_by_type_job_name(
        job_name, 2, 1)[0]

    # merge 2 list sort by time

    if svn_list != None:
        for i in svn_list:
            i['time'] = i['time'][:19]
    else:
        svn_list = []

    ret = [job_record_list[0]] + svn_list + [job_record_list[1]]

    # get trunk svn commit after last sealed

    start = job_record_list[1]['time']
    end = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))

    after_seal = data_utils.get_branch_svn_log(module,
                                               "trunk",
                                               start=start,
                                               end=end)

    if after_seal != None:
        for j in after_seal:
            j['time'] = j['time'][:19]
    else:
        after_seal = []

    ret.extend(after_seal)

    trigger_record['time'] = trigger_record['time'][:19]
    trigger_record['comment'] = 'publish'

    inserted = False
    for i in range(len(ret)):
        if ret[i]['time'] < trigger_record['time']:
            continue
        else:
            ret.insert(i, trigger_record)
            inserted = True
            break

    if inserted == False:
        ret.append(trigger_record)

    ret.reverse()
    return render(request, 'timeline.html', {'data': ret})
Ejemplo n.º 19
0
def get_sub_task_info(id):
    sub_task = models.SubTask.objects.get(id=id)
    ret = model_to_dict(sub_task)
    ret["is_start"] = int(sub_task.is_start)
    ret["createTime"] = public.datetime2str(sub_task.createTime)
    return ret