예제 #1
0
파일: station.py 프로젝트: wncbb/trainWeb
    def delete_station2(inData):
        '''
        :param inData:
        :return:{
            2:'there is no id in inData',
            3:'there is no such id'
        }
        '''
        ret=0
        if(not inData.has_key('id')):
            ret=2
            return ret

        query=session.query(Station)
        tmpStation=query.filter(Station.id==inData['id']).first()
        if(tmpStation==None):
            ret=3
            return ret
        else:
            from sensor import Sensor
            tmpAllSensor=Sensor.select({'stationId': tmpStation.id})
            for tmpSensor in tmpAllSensor['pureData']:
                tmpSensor.stationId=0
            session.delete(tmpStation)
            session.commit()
            ret=1
            return ret
예제 #2
0
    def delete_station2(inData):
        '''
        :param inData:
        :return:{
            2:'there is no id in inData',
            3:'there is no such id'
        }
        '''
        ret = 0
        if('id' not in inData):
            ret = 2
            return ret

        query = session.query(Station)
        tmpStation = query.filter(Station.id == inData['id']).first()
        if(tmpStation is None):
            ret = 3
            return ret
        else:
            from sensor import Sensor
            tmpAllSensor = Sensor.select({'stationId': tmpStation.id})
            for tmpSensor in tmpAllSensor['pureData']:
                tmpSensor.stationId = 0
            session.delete(tmpStation)
            session.commit()
            ret = 1
            return ret
예제 #3
0
 def delete_data(self,id):
     try:
         """删除数据,默认开始事务"""
         rows = session.query(ProductModel).filter(ProductModel.id == id).first()
         session.delete(rows)
         session.commit()
         return True
     except:
         session.rollback()
예제 #4
0
def delete_user(*args,**kwargs):
    """"
    query>User.username=='cainiao'
    """
    try:
        rows = session.query(User).filter(*args).filter_by(**kwargs)[0]
        session.delete(rows)
        session.commit()
    except Exception as e:
        session.rollback()
        raise e
예제 #5
0
    def init():

        Base.metadata.create_all(engine)
        old = Hardware.get_all_hardware()
        if old:
            print '[i] delete old data in hardware table...'
        for item in old:
            session.delete(item)
        session.commit()

        hardware_info_csv = 'hardware_info.csv'
        Hardware.read_hardware_info(hardware_info_csv)
        print '[i] complete initing the hardware table...'
예제 #6
0
    def retData(timeSpan, inType):
        if (inType == 'py'):
            query = session.query(Atkinfo)
            sensorQuery = session.query(Sensor)
            nowTime = time.time()
            limitTime = nowTime - timeSpan
            allInfos = query.filter(
                and_(Atkinfo.pyRead == 0, Atkinfo.atkTime > limitTime))
            ret = []
            for tmpInfo in allInfos:
                tmpInfo.pyRead = 1
                tmp = {}
                tmp['attackId'] = tmpInfo.atkId
                tmp['time'] = time.strftime("%Y-%m-%d %H:%M:%S",
                                            time.localtime(tmpInfo.atkTime))

                tmpSensor = sensorQuery.filter(
                    Sensor.mac == tmpInfo.sensorMac).first()
                if (tmpSensor is not None):
                    tmp['sensorId'] = tmpSensor.number
                else:
                    tmp['sensorId'] = 'not known'

                tmp['src'] = {}
                tmp['src']['ip'] = tmpInfo.srcIp
                tmp['src']['port'] = tmpInfo.srcPort
                tmp['src']['lng'] = float(tmpInfo.srcLng)
                tmp['src']['lat'] = float(tmpInfo.srcLat)
                tmp['src']['name'] = ''

                tmp['dst'] = {}
                tmp['dst']['ip'] = tmpInfo.dstIp
                tmp['dst']['port'] = tmpInfo.dstPort
                tmp['dst']['lng'] = float(tmpInfo.dstLng)
                tmp['dst']['lat'] = float(tmpInfo.dstLat)
                tmp['dst']['name'] = ''

                tmp['protocalA'] = tmpInfo.cmProtocal
                tmp['trails'] = tmpInfo.trails
                tmp['references'] = tmpInfo.refer
                tmp['infos'] = tmpInfo.infos
                ret.append(tmp)
                session.delete(tmpInfo)

            session.commit()
            return ret
        else:
            return {}
예제 #7
0
    def delete_auth2(inData):
        '''
        :param inData:
        :return: {2:'there is no id', 3:'this is so such record'}
        '''
        ret = 1
        if (inData.has_key('id')):
            query = session.query(Auth)
            tmpAuth = query.filter(Auth.id == inData['id']).first()
            if (tmpAuth != None):
                session.delete(tmpAuth)
                session.commit()
                ret = 1
            else:
                ret = 3

        else:
            ret = 2
        return ret
예제 #8
0
파일: auth.py 프로젝트: wncbb/trainWeb
    def delete_auth2(inData):
        '''
        :param inData:
        :return: {2:'there is no id', 3:'this is so such record'}
        '''
        ret=1
        if(inData.has_key('id')):
            query=session.query(Auth)
            tmpAuth=query.filter(Auth.id==inData['id']).first()
            if(tmpAuth!=None):
                session.delete(tmpAuth)
                session.commit()
                ret=1
            else:
                ret=3

        else:
            ret=2
        return ret
예제 #9
0
파일: atkinfo.py 프로젝트: wncbb/trainWeb
    def retData(timeSpan, inType):
        if(inType=='py'):
            query=session.query(Atkinfo)
            nowTime=time.time()
            limitTime=nowTime-timeSpan
            delInfos=query.filter(Atkinfo.atkTime<=limitTime)
            allInfos=query.filter(and_(Atkinfo.atkTime>limitTime))
            ret=[]
            for tmpInfo in delInfos:
                session.delete(tmpInfo)
            for tmpInfo in allInfos:
                tmp={}
                tmp['attackId']=tmpInfo.atkId
                tmp['time']=time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(tmpInfo.atkTime))

                tmp['sensorId']=tmpInfo.sensorNumber
                tmp['src']={}
                tmp['src']['ip']=tmpInfo.srcIp
                tmp['src']['port']=tmpInfo.srcPort
                tmp['src']['lng']=float(tmpInfo.srcLng)
                tmp['src']['lat']=float(tmpInfo.srcLat)
                tmp['src']['name']=''

                tmp['dst']={}
                tmp['dst']['ip']=tmpInfo.dstIp
                tmp['dst']['port']=tmpInfo.dstPort
                tmp['dst']['lng']=float(tmpInfo.dstLng)
                tmp['dst']['lat']=float(tmpInfo.dstLat)
                tmp['dst']['name']=''

                tmp['protocalA']=tmpInfo.cmProtocal
                tmp['trails']=tmpInfo.trails
                tmp['references']=tmpInfo.refer
                tmp['infos']=tmpInfo.infos
                ret.append(tmp)
                session.delete(tmpInfo)
            session.commit()
            return ret
        else:
            return {}
예제 #10
0
 def del_user2(inData):
     '''
     :param inData:
     :return{0: error, 2: no id in inData, 3: no such id in userv2, }:
     '''
     ret = 0
     if ('id' not in inData):
         ret = 2
         return ret
     query = session.query(User)
     tmpUser = query.filter(User.id == inData['id']).first()
     if (tmpUser is None):
         ret = 3
         return ret
     else:
         from user_old import User_old
         User_old.add(tmpUser)
         from auth import Auth
         authQuery = session.query(Auth)
         authQuery.filter(Auth.userId == tmpUser.id).delete()
         session.delete(tmpUser)
         session.commit()
         ret = 1
         return ret
예제 #11
0
파일: user.py 프로젝트: wncbb/trainWeb
 def del_user2(inData):
     '''
     :param inData:
     :return{0: error, 2: no id in inData, 3: no such id in userv2, }:
     '''
     ret=0
     if(not inData.has_key('id')):
         ret=2
         return ret
     query=session.query(User)
     tmpUser=query.filter(User.id==inData['id']).first()
     if(tmpUser==None):
         ret=3
         return ret
     else:
         from user_old import User_old
         User_old.add(tmpUser)
         from auth import Auth
         authQuery=session.query(Auth)
         authQuery.filter(Auth.userId==tmpUser.id).delete()
         session.delete(tmpUser)
         session.commit()
         ret=1
         return ret
예제 #12
0
def delete_user():
    row = session.query(User).filter(User.name == 'chenyanqi')[0]
    print(row)
    session.delete(row)
    session.commit()
예제 #13
0
def delete_user():
    rows = session.query(User).filter(User.username == 'xpss')[0]

    session.delete(rows)  #删除第一条记录
    #rows.deleted()   #批量删除
    session.commit()