コード例 #1
0
ファイル: cache_.py プロジェクト: deanshishang/WillCompany
 def syncAllFromDb():
     #TODO:  lock
     
     try:
         deviceList=[]
         cursor = connection.cursor()
         sql = "select name,id from detect_device"
         cursor.execute(sql)
         row = cursor.fetchone()
         while row:
             device={}    
             device['name'] = row[0]
             device['id'] = row[1]
             deviceList.append(device)
             CacheDb.device[row[0]]={'id':row[1]}
             row = cursor.fetchone()
         
         for device in deviceList:
         
             deviceName = device['name']
             deviceId = device['id']
             sql = "select t.id,t.url,t.ip,t.interval from detect_task t, detect_device_tasks r " \
                   "where t.id=r.task_id and r.device_id=%d" % deviceId
             cursor.execute(sql)
             row = cursor.fetchone()
             while row:
                 taskId = row[0]
                 detectUrl = row[1]
                 detectIp = row[2]
                 detectInterval = row[3]
                 if CacheDb.device.has_key(deviceName):
                     if CacheDb.device[deviceName].has_key('task'):
                         CacheDb.device[deviceName]['task'][taskId] = {'url':detectUrl,
                                                                       'ip':detectIp,
                                                                       'interval':detectInterval,
                                                                       'lasttime':int(time.time()),
                                                                       'detectNum':0}
                     else:
                        CacheDb.device[deviceName]['task'] ={taskId:{'url':detectUrl,
                                                                     'ip':detectIp,
                                                                     'interval':detectInterval,
                                                                     'lasttime':int(time.time()),
                                                                     'detectNum':0}} 
             
                 row = cursor.fetchone()
     except Exception,e:
         exstr = traceback.format_exc()
         logger.critical("%s" % str(exstr))
コード例 #2
0
ファイル: cache_.py プロジェクト: deanshishang/WillCompany
	def syncAllFromDb():
		try:
			deviceList = []
			cursor = connection.cursor()
			sql = "select name,id from yun_hotel"
			cursor.execute(sql)
			row = cursor.fetchone()
			while row:
				device = {}
				device['name'] = row[0]
				device['id'] = row[1]
				deviceList.append(device)
				CacheDb.device[row[0]] = {"id":row[1]}
				row = cursor.fetchone()
		except Exception, e:
			exstr = traceback.format_exc()
			logger.critical("%s" % str(exstr))
コード例 #3
0
ファイル: views.py プロジェクト: deanshishang/WillCompany
def entry(request):
	try:
		if request.method == 'GET':
			return HttpResponse('dfdfdfdfdf')
		if request.method == 'POST':
			data = request.raw_post_data
			logger.debug("The request data: %s" % data)
			header = {}
			retCode = Packet.unpackHeader(data, header)
			if retCode:
				logger.debug("header: %s %s %s %s"% (header['prover'], header['protype'],
					header['devicename'], header['valuelen']))

				reportDataList = Packet.unpackBody(header['valuelen'], header['value'])
				logger.debug("The reportDataList: %s" % reportDataList)
				data = Handler.handle(header['devicename'], reportDataList)
			return HttpResponse(data)
	except Exception, e:
		exstr = traceback.format_exc()
		logger.critical("%s" % str(exstr))
コード例 #4
0
ファイル: view.py プロジェクト: deanshishang/WillCompany
def entry(request):
    
    if request.method == 'GET':
        return HttpResponse("KAO")
    elif request.method == 'POST':
        
        try:
            #TODO: check MAC
            #logger.info("Remote %s request" % str(request.META['REMOTE_ADDR']))
            #get post data
            data = request.raw_post_data;
            #unpack data
			#print "\n#####################\n"
			#print data
			#print "\n#####################\n"


            header={}
            retcode = Packet.unpackHeader(data,header)
            
            if retcode:
                
                logger.debug("header: %s %s %s %s" % \
                             (header['prover'],header['protype'],
                              header['devicename'],header['valuelen']))
                
                reportDataList = Packet.unpackBody(header['valuelen'],header['value'])
                
                data = Handler.handle(header['devicename'], reportDataList)
                
                return HttpResponse(data)
            else:
                return HttpResponse("Bad Packet")
        
        except Exception,e:
            exstr = traceback.format_exc()
            logger.critical("%s" % str(exstr))