示例#1
0
 def _populateFromDb(self, data):
     for k in data:
         setattr(self, '_' + k, data[k])
     self._stats = JSON.decode(self._stats)
     self._get = JSON.decode(self._get)
     self._post = JSON.decode(self._post)
     self._server = JSON.decode(self._server)
示例#2
0
    def createFromNodeJs(self, data):
        if not self._validateNodeJsData(data):
            return False

        self._populateFromNodeJs(data)
        Debugger.log("Storing request data to Database...", 'debug')
        db = Database()

        # Storing main table
        query = "INSERT INTO requests (id, datetime, url, memory, stats, get, post, server, level, read)" \
                " VALUES (NULL, ?,?,?,?,?,?,?,?,0)"
        bind = (self._datetime, self._url, self._memory, JSON.encode(self._stats), JSON.encode(self._get),
                JSON.encode(self._post), JSON.encode(self._server), self._level)
        db.execute(query, bind)
        self._id = db.last_inserted_id

        # Storing messages
        messages = self._messages
        self._messages = []
        for message in messages:
            m = Message()
            message['request'] = self._id
            m.createFromNodeJs(message)
            self._messages.append(m)

        """
        Modify data (this will also affect the Request table model)
        """
        settings = Settings()
        if Request._RECORDS is not None:
            Request._RECORDS.insert(0, self)
            if len(Request._RECORDS) > settings.requests_limit:
                del Request._RECORDS[-1]

        return True
示例#3
0
 def _populateFromNodeJs(self, data):
     map = {
         'name': 'group'
     }
     for k in data:
         value = data[k]
         if k in map:
             k = map[k]
         setattr(self, '_' + k, value)
     self._context = JSON.decode(self._context)
     self._extra = JSON.decode(self._extra)
示例#4
0
 def _makeSettingsDictionary(self, data):
     for r in data:
         value = r['value']
         if self._isNumber(value):
             value = self._toNumber(value)
         if r['key'] == 'log_levels':
             value = JSON.decode(r['value'])
         setattr(self, r['key'], value)
示例#5
0
 def save(self):
     db = Database()
     for i in Settings._SETTINGS.items():
         key = i[0]
         value = i[1]
         if key == 'log_levels':
             value = JSON.encode(value)
         query = "UPDATE settings SET value = ? WHERE key = ?"
         db.execute(query, (value, key))
示例#6
0
    def createFromNodeJs(self, data):
        if not self._validateNodeJsData(data):
            return False

        self._populateFromNodeJs(data)
        Debugger.log("Storing message data to Database...", 'debug')
        db = Database()

        # Storing main table
        query = "INSERT INTO messages (`group`, message, file, line, memory, level, datetime, context, extra, request) " \
                "VALUES (?,?,?,?,?,?,?,?,?,?)"
        bind = (
            self._group, self._message, self._file, self._line, self._memory, self._level, self._datetime, JSON.encode(self._context),
            JSON.encode(self._extra), self._request)
        db.execute(query, bind)
        self._id = db.last_inserted_id
        return True
示例#7
0
 def _populateFromNodeJs(self, data):
     for k in data:
         setattr(self, '_' + k, data[k])
     self._stats = JSON.decode(self._stats)
示例#8
0
def jloads(json_string):
    return JSON.decode(json_string)
示例#9
0
 def _populateFromDb(self, data):
     for k in data:
         setattr(self, '_' + k, data[k])
     self._context = JSON.decode(self._context)
     self._extra = JSON.decode(self._extra)