Exemple #1
0
def project_select(auth_info,**kwargs):
    if auth_info['code'] == 1:
        return json.dumps(auth_info)
    username = auth_info['username']
    try:
        output = ['id','name','path','principal','p_user','p_group','is_lock','comment']
        data = request.get_json()['params']
        fields = data.get('output', output)
          
        #查询用户表,生成id2name的字典
        users=util.getinfo('user',['id', 'name'])

        #查询角色表,生成id2name的字典
        roles=util.getinfo('role',['id', 'name'])

        #查询项目表,把项目表中p_uesr,p_group,principal的ID 转为name
        projects = app.config['cursor'].get_results('project', fields)
        for p  in projects:  #循环项目列表,判断项目表中的p_user的id是否存在,如果存在则id2name
            p['principal'] = ','.join([users[x] for x in  p['principal'].split(',') if x in users])
            p['p_user'] =  '******'.join([users[u] for u in p['p_user'].split(',') if u in users])
            p['p_group'] =  ','.join([roles[r] for r in p['p_group'].split(',')  if r in roles])
        
        #普通用户只能查看其有权限的项目
        if '1' not in  auth_info['r_id']:  
            p=util.user_projects(username)  #调用公共函数,查出用户的项目id2name{'1':'devops','2':'test'}
            projects = [pro for pro in projects for pid in p.keys() if pid==pro['id']] #获取对应项目的详情 
        util.write_log('api').info(username, 'select project list success')
        return json.dumps({'code':0,'result':projects,'count':len(projects)})
    except:
        util.write_log('api').error("select project list error: %s"  %  traceback.format_exc())
        return json.dumps({ 'code':1,'errmsg':'get projectlist failed'})
Exemple #2
0
def apply_list(auth_info,**kwargs):
    if auth_info['code'] == 1:
        return json.dumps(auth_info)
    username = auth_info['username']
    try:
        output = ['id','project_id','info','applicant','version','apply_date','commit','status','detail']
        data = request.get_json()['params']  
        fields = data.get('output', output)
        applyer = app.config['cursor'].get_results('project_apply',fields)   #申请人看到的项目列表
        for res in applyer:
            res['apply_date']=str(res['apply_date'])

        where = {'status':['1','2']}
        result = app.config['cursor'].get_results('project_apply',fields,where) #只列出申请中和审核中的项目给发布者
        #id转换成名字
        id2name_project=util.getinfo('project',['id','name'])
        for res in result:
            res['project_name'] = id2name_project[str(res['project_id'])]           
            res['apply_date']=str(res['apply_date'])

        util.write_log('api').info(username, 'get apply list success!')
        return  json.dumps({'code':0,'data': applyer, 'result':result,'count':len(result)})
    except:
        util.write_log('api').error("select apply list error:%s" % traceback.format_exc())
        return json.dumps({'code':1,'errmsg':'任务列表获取失败!'})
Exemple #3
0
def apply_list(auth_info,**kwargs):
    if auth_info['code'] == 1:
        return json.dumps(auth_info)
    username = auth_info['username']
    try:
        output = ['id','project_id','info','applicant','version','apply_date','commit','status','detail']
        data = request.get_json()['params']  
        fields = data.get('output', output)
        # 申请者看到的项目列表
        applylist = app.config['cursor'].get_results('project_apply',fields)     
        
        # 审核者看到的申请列表,只显示申请中和审核中的项目
        where = {'status':['1','2']}
        result = app.config['cursor'].get_results('project_apply',fields,where) 

        # id转换成名字
        id2name_project=util.getinfo('project',['id','name'])
        for res in applylist:
            res['project_name'] = id2name_project[str(res['project_id'])]           
            res['apply_date']=str(res['apply_date'])
        for res in result:
            res['project_name'] = id2name_project[str(res['project_id'])]           
            res['apply_date']=str(res['apply_date'])

        util.write_log('api').info('%s:get apply list success!' % username)
        return  json.dumps({'code':0,'data': applylist, 'result':result,'count':len(result)})
    except:
        util.write_log('api').error("select apply list error:%s" % traceback.format_exc())
        return json.dumps({'code':1,'errmsg':'任务列表获取失败!'})
Exemple #4
0
def deploy_get(auth_info, **kwargs):
    if auth_info['code'] == 1:
        return json.dumps(auth_info)
    username = auth_info['username']
    try:
         data = request.get_json()['params']
         where = data.get('where',None)
         fields = ['id', 'project_id','info','applicant','version','commit','apply_date','status','detail']
         result = app.config['cursor'].get_one_result('project_deploy', fields, where)
         # id转换成名字
         id2name_project=util.getinfo('project',['id','name'])
         result['project_name'] = id2name_project[str(result['project_id'])]           
         result['apply_date']=str(result['apply_date'])
         util.write_log('api').info("%s:get deploy  success!" % username)
         return json.dumps({'code':0, 'result':result})
    except:
        util.write_log('api').error("get deploy error:%s" % traceback.format_exc())
        return json.dumps({'code': 1, 'errmsg': "获取版本上线历史记录失败"})
Exemple #5
0
def deploy_list(auth_info,**kwargs):
    if auth_info['code'] == 1:
        return json.dumps(auth_info)
    username = auth_info['username']
    try:
        fields = ['id','project_id','applicant','version','commit','apply_date','status']
        result = app.config['cursor'].get_results('project_deploy',fields) 
        # id转换成名字
        id2name_project=util.getinfo('project',['id','name'])
        for res in result:
            res['project_name'] = id2name_project[str(res['project_id'])]           
            res['apply_date']=str(res['apply_date'])
       
        util.write_log('api').info('%s:get deploy list success!' % username)
        return  json.dumps({'code':0, 'result':result, 'count':len(result)})
    except:
        util.write_log('api').error("select deploy list error:%s" % traceback.format_exc())
        return json.dumps({'code': 1, 'errmsg': '获取上线历史记录失败'})
Exemple #6
0
def deploy_list(auth_info,**kwargs):
    if auth_info['code'] == 1:
        return json.dumps(auth_info)
    username = auth_info['username']
    try:
        fields = ['id','project_id','applicant','version','commit','apply_date','status']
        result = app.config['cursor'].get_results('project_deploy',fields) 
        #id转换成名字
        id2name_project=util.getinfo('project',['id','name'])
        for res in result:
            res['project_name'] = id2name_project[str(res['project_id'])]           
            res['apply_date']=str(res['apply_date'])
       
        util.write_log('api').info(username, 'get deploy list success!')
        return  json.dumps({'code':0, 'result':result, 'count':len(result)})
    except:
        util.write_log('api').error("select deploy list error:%s" % traceback.format_exc())
        return json.dumps({'code': 1, 'errmsg': '获取上线历史记录失败'})
Exemple #7
0
def deploy_get(auth_info, **kwargs):
    if auth_info['code'] == 1:
        return json.dumps(auth_info)
    username = auth_info['username']
    try:
         data = request.get_json()['params']
         where = data.get('where',None)
         fields = ['id', 'project_id','info','applicant','version','commit','apply_date','status','detail']
         result = app.config['cursor'].get_one_result('project_deploy', fields, where)
         #id转换成名字
         id2name_project=util.getinfo('project',['id','name'])
         result['project_name'] = id2name_project[str(result['project_id'])]           
         result['apply_date']=str(result['apply_date'])
         util.write_log('api').info(username, "get deploy  success!")
         util.write_log('api').info(result)
         return json.dumps({'code':0, 'result':result,})
    except:
        util.write_log('api').error("get deploy error:%s" % traceback.format_exc())
        return json.dumps({'code': 1, 'errmsg': "获取版本上线历史记录失败"})
Exemple #8
0
def apply_one(auth_info,**kwargs):
    if auth_info['code'] == 1:
        return json.dumps(auth_info)
    username = auth_info['username']
    try:
        data = request.get_json()['params']
        output = ['id','project_id','info','applicant','version','commit','apply_date','status','detail']
        fields = data.get('output', output)
        where = data.get('where',None)
        result = app.config['cursor'].get_one_result('project_apply',fields,where)
        # id转换成名字
        id2name_project=util.getinfo('project',['id','name'])
        result['project_name'] = id2name_project[str(result['project_id'])] 
        result['apply_date']=str(result['apply_date'])

        util.write_log('api').info('%s:get one apply detail success' % username)
        return json.dumps({'code':0,'result':result})
    except:
        util.write_log('api').error("get apply detail faild : %s" % traceback.format_exc())
        return json.dumps({'code':1,'errmsg':'任务详情获取失败!'})
Exemple #9
0
def apply_one(auth_info,**kwargs):
    if auth_info['code'] == 1:
        return json.dumps(auth_info)
    username = auth_info['username']
    try:
        data = request.get_json()['params']
        output = ['id','project_id','info','applicant','version','commit','apply_date','status','detail']
        fields = data.get('output', output)
        where = data.get('where',None)
        result = app.config['cursor'].get_one_result('project_apply',fields,where)
        #id转换成名字
        id2name_project=util.getinfo('project',['id','name'])
        result['project_name'] = id2name_project[str(result['project_id'])] 
        result['apply_date']=str(result['apply_date'])

        util.write_log('api').info(username, 'get one apply detail success')
        return json.dumps({'code':0,'result':result})
    except:
        util.write_log('api').error("get  apply detail faild : %s"  %  traceback.format_exc())
        return json.dumps({'code':1,'errmsg':'任务详情获取失败!'})