コード例 #1
0
 def get(self, args=None):
     '''获取project信息'''
     ret = dict(status=True, msg=None, data=None)
     try:
         with DBContext('readonly') as session:
             if args:
                 obj = session.query(App).filter(Project.id == args).first()
                 if not obj:
                     ret['msg'] = '资源不存在'
                     raise Exception
                 data = model_to_dict(obj)
                 data['cuser'] = obj.cuser.name
             else:
                 obj = session.query(App).all()
                 data = []
                 for line in obj:
                     new_line = model_to_dict(line)
                     new_line['cuser'] = line.cuser.name
                     data.append(new_line)
             ret['data'] = data
             ret['msg'] = '获取资源成功'
     except Exception as e:
         print(e)
         ret['status'] = False
         if not ret['msg']: ret['msg'] = str(e)
     self.write(ret)
コード例 #2
0
    def put(self, args=None):
        '''更新project'''
        ret = dict(status=True, msg=None, data=None)
        try:
            if not args:
                ret['msg'] = 'arg缺少必要参数'
                raise Exception
            data = json.loads(self.request.body.decode("utf-8"))
            name = data.get("name")
            port = data.get("port")
            desc = data.get("desc")
            git_url = data.get("git_url")

            check = [name, port, git_url]
            if not all(check):
                ret['msg'] = '必要字段不能为空'
                raise Exception

            with DBContext('default') as session:
                obj = session.query(App).filter(App.id == args).first()
                if not obj:
                    ret['msg'] = '资源不存在'
                    raise Exception
                obj.name = name
                obj.port = port
                obj.desc = desc
                obj.git_url = git_url
                session.commit()
                ret['data'] = model_to_dict(obj)
                ret['msg'] = '更新资源成功'
        except Exception as e:
            print(e)
            ret['status'] = False
            if not ret['msg']: ret['msg'] = str(e)
        self.write(ret)
コード例 #3
0
    def post(self, *args, **kwargs):
        '''新增project'''
        ret = dict(status=True, msg=None, data=None)
        try:
            data = json.loads(self.request.body.decode("utf-8"))
            name = data.get("name")
            port = data.get("port")
            desc = data.get("desc")
            git_url = data.get("git_url")
            cuser_id = data.get("cuser_id")

            check = [name, port, git_url, cuser_id]
            if not all(check):
                ret['msg'] = '必要字段不能为空'
                raise Exception

            with DBContext('default') as session:
                obj = App(name=name,
                          port=port,
                          desc=desc,
                          git_url=git_url,
                          cuser_id=cuser_id)
                session.add(obj)
                session.commit()
                ret['data'] = model_to_dict(obj)
                ret['msg'] = '新增资源成功'
        except Exception as e:
            print(e)
            ret['status'] = False
            if not ret['msg']: ret['msg'] = str(e)
        self.write(ret)
コード例 #4
0
    def get(self, *args, **kwargs):
        '''获取task信息'''
        ret = dict(status=True, msg=None, data=None)
        try:
            publish_id = self.get_argument('publish_id', None)
            app_id = self.get_argument('app_id', None)
            env_id = self.get_argument('env_id', None)
            if not publish_id or not app_id or not env_id:
                ret['msg'] = '缺少参数'
                raise Exception
            with DBContext('readonly') as session:
                res = session.query(Task).filter(
                    Task.publish_id == publish_id, Task.app_id == app_id,
                    Task.env_id == env_id).first()
                if not res:
                    ret['msg'] = '资源不存在'
                    raise Exception
                print(res.name)
                print(res.status)
                ret['data'] = model_to_dict(res)
                ret['msg'] = '获取资源成功'

        except Exception as e:
            print(e)
            ret['status'] = False
            if not ret['msg']: ret['msg'] = str(e)
        self.write(ret)
コード例 #5
0
    def post(self, *args, **kwargs):
        '''提交publish任务'''
        ret = dict(status=True, msg=None, data=None)
        try:
            data = json.loads(self.request.body.decode("utf-8"))
            project_id = data.get("project_id")
            #project_name = data.get("project_name", None)
            submit_user_id = data.get("submit_user_id")
            review_user_id = data.get("review_user_id")
            desc = data.get("desc")
            app_list = data.get("app")
            print(app_list)

            check = [project_id, submit_user_id, review_user_id, app_list]
            if not all(check):
                ret['msg'] = '必要字段不能为空'
                raise Exception
            with DBContext('default') as session:
                obj = Publish(project_id=project_id,
                              submit_user_id=submit_user_id,
                              review_user_id=review_user_id,
                              desc=desc)
                obj.app = session.query(App).filter(App.id.in_(app_list)).all()
                session.add(obj)
                session.commit()
                ret['data'] = model_to_dict(obj)
                ret['msg'] = '发布任务提交成功'

        except Exception as e:
            print(e)
            ret['status'] = False
            if not ret['msg']: ret['msg'] = str(e)
        self.write(ret)
コード例 #6
0
    def post(self, *args, **kwargs):
        '''新增project'''
        ret = dict(status=True, msg=None, data=None)
        try:
            data = json.loads(self.request.body.decode("utf-8"))
            name = data.get("name")
            desc = data.get("desc")
            app_list = data.get("app")
            #env_list = data.get("env")
            owner_list = data.get("owner")
            cuser_id = data.get("cuser_id")

            print(app_list)
            check = [name, app_list, owner_list, cuser_id]
            if not all(check):
                ret['msg'] = '必要字段不能为空'
                return self.write(ret)
                #raise Exception

            with DBContext('default') as session:
                obj = Project(name=name, desc=desc, cuser_id=cuser_id)
                obj.app = session.query(App).filter(App.id.in_(app_list)).all()
                #obj.env = session.query(Env).filter(Env.id.in_(env_list)).all()
                obj.owner = session.query(User).filter(
                    User.id.in_(owner_list)).all()
                session.add(obj)
                session.commit()
                ret['data'] = model_to_dict(obj)
                ret['msg'] = '新增资源成功'
        except Exception as e:
            print(e)
            ret['status'] = False
            if not ret['msg']: ret['msg'] = str(e)
        self.write(ret)
コード例 #7
0
 def get(self):
     ret = dict(status=True, msg=None, data=None)
     try:
         with DBContext('readonly') as session:
             res = session.query(Env).all()
             ret['data'] = [model_to_dict(item) for item in res]
             ret['msg'] = '获取资源成功'
     except Exception as e:
         print(e)
         ret['status'] = False
         if not ret['msg']: ret['msg'] = str(e)
     self.write(ret)
コード例 #8
0
 def get(self, args=None):
     '''获取发布列表'''
     ret = dict(status=True, msg=None, data=None)
     try:
         with DBContext('readonly') as session:
             if args:
                 res = session.query(Publish).filter(
                     Publish.id == args).first()
                 if not res:
                     ret['msg'] = '资源不存在'
                     raise Exception
                 res_list = model_to_dict(res)
                 res_list['project'] = res.project.name
                 res_list['review_user'] = res.review_user.name
                 res_list['submit_user'] = res.submit_user.name
                 res_list['app_list'] = [
                     model_to_dict(item) for item in res.app
                 ]
             else:
                 res_list = []
                 res = session.query(Publish).all()
                 for line in res:
                     new_item = model_to_dict(line)
                     new_item['project'] = line.project.name
                     new_item['review_user'] = line.review_user.name
                     new_item['submit_user'] = line.submit_user.name
                     new_item['app_list'] = [
                         model_to_dict(item) for item in line.app
                     ]
                     res_list.append(new_item)
         ret['data'] = res_list
         ret['msg'] = '获取资源成功'
     except Exception as e:
         print(e)
         ret['status'] = False
         if not ret['msg']: ret['msg'] = str(e)
     self.write(ret)
コード例 #9
0
 def patch(self, args=None):
     '''更新任务状态'''
     ret = dict(status=True, msg=None, data=None)
     try:
         data = json.loads(self.request.body.decode("utf-8"))
         status = data.get('status')
         with DBContext('default') as session:
             res = session.query(Publish).filter(Publish.id == args).first()
             res.status = status
             res.review_time = datetime.now()
             session.commit()
             ret['data'] = model_to_dict(res)
             ret['msg'] = '任务状态更新成功'
     except Exception as e:
         print(e)
         ret['status'] = False
         if not ret['msg']: ret['msg'] = str(e)
     self.write(ret)
コード例 #10
0
 def delete(self, args=None):
     ret = dict(status=True, msg=None, data=None)
     try:
         if not args:
             ret['msg'] = 'arg缺少必要参数'
             raise Exception
         with DBContext('default') as session:
             project = session.query(Project).filter(
                 Project.id == args).first()
             if not project:
                 ret['msg'] = '资源不存在'
                 raise
             session.delete(project)
             session.commit()
             ret['data'] = model_to_dict(project)
             ret['msg'] = '删除资源成功'
     except Exception as e:
         print(e)
         ret['status'] = False
         if not ret['msg']: ret['msg'] = str(e)
     self.write(ret)
コード例 #11
0
    def put(self, args=None):
        '''更新project'''
        ret = dict(status=True, msg=None, data=None)
        try:
            if not args:
                ret['msg'] = 'arg缺少必要参数'
                raise Exception
            data = json.loads(self.request.body.decode("utf-8"))

            name = data.get("name")
            desc = data.get("desc")
            app_list = data.get("app")
            #env_list = data.get("env")
            owner_list = data.get("owner")

            check = [name, app_list, env_list, owner_list]
            if not all(check):
                ret['msg'] = '必要字段不能为空'
                raise Exception

            with DBContext('default') as session:
                obj = session.query(Project).filter(Project.id == args).first()
                if not obj:
                    ret['msg'] = '资源不存在'
                    raise Exception
                obj.name = name
                obj.desc = desc
                obj.app = session.query(App).filter(App.id.in_(app_list)).all()
                #obj.env = session.query(Env).filter(Env.id.in_(env_list)).all()
                obj.owner = session.query(User).filter(
                    User.id.in_(owner_list)).all()

                session.commit()
                ret['data'] = model_to_dict(obj)
                ret['msg'] = '更新资源成功'
        except Exception as e:
            print(e)
            ret['status'] = False
            if not ret['msg']: ret['msg'] = str(e)
        self.write(ret)