Esempio n. 1
0
def deviceRemove(deviceId):
    rows,isEof = database.db_select_device(id=deviceId)
    if len(rows)<=0:
        return
    accessKey = rows[0][8]
    row = database.db_select_accessKey(accessKey)
    if len(row) <= 0:# key is not alloced
        return error.ERR_CODE_OK_
    # accessDevices format: 'id1|id2|id3|...'
    accessDevices = row[0][3]
    if accessDevices is None:
        return error.ERR_CODE_OK_

    devices = accessDevices.split(':')
    try:
        devices.remove(str(deviceId))
    except:
        return error.ERR_CODE_OK_
    if len(devices) == 0:
        updDevices = None
    else:
        updDevices = str(devices[0])
        for item in devices[1:]:
            updDevices = updDevices + ":" + str(item)
    return database.db_update_accessKey(accessKey,updDevices)
Esempio n. 2
0
 def post(self,deviceId):
     if self.userLoginCheck() != error.ERR_CODE_OK_:
         return
     #sensor的权限,需要先判断其所属的device是否拥有权限
     if self.privilegeCheck(master='user',masterId=self.current_user,\
                           object='device',objectId=deviceId,operation='upd') != error.ERR_CODE_OK_:
         return
     #device是否存在
     rows,isEof = database.db_select_device(num=1,id=deviceId)
     if len(rows)<=0:
         self.send_error_msg(self.__ERRCODE__['notfound'])
         return
     requestApi = copy.deepcopy(restDef.RESTFUL_API[restDef.HTTP_RES['sensor']]['@POST']['REQUEST'])
     responseApi = copy.deepcopy(restDef.RESTFUL_API[restDef.HTTP_RES['sensor']]['@POST']['RESP'])
     self._getAllArguments(requestApi)
     if requestApi['name'] != '':
         id = database.db_insert_sensor(requestApi['name'], requestApi['description'],
                                        deviceId, requestApi['userDefArea'])
         responseApi['id'] = id
     else:
         responseApi['id'] = None
     if responseApi['id'] is not None:
         #add privilege to this sennor
         privilegeM.priv_add(master='user',masterId=self.current_user,
                             object='sensor',objectId=responseApi['id'],
                             masterRole='administrator')
     #print responseApi
     self.write(escape.json_encode(responseApi))
Esempio n. 3
0
 def _getResponse(self, request, pathPara):
     (rows,isEof) = database.db_select_device(id=pathPara[0])
     if len(rows)<=0:
         return {}
     return msgbuilder.respBuilder_get_onedevice(rows[0])
Esempio n. 4
0
 def _getResponse(self, request, pathPara):
     (rows,isEof) = database.db_select_device(request['sort'], request['maxNum'], request['skipNum'])
     return msgbuilder.respBuilder_get_device(rows, isEof)