@@ -232,34 +232,26 @@ def write(self, value, status=CONTENT_STATUS.IN_PROGRESS, content_type=None):
232232 # Ignore all non-relevant messages
233233 return
234234
235- output = conf .databaseCursor .execute (
236- "SELECT id, status, value FROM data WHERE taskid = ? AND content_type = ?" ,
237- (self .taskid , content_type ))
235+ output = conf .databaseCursor .execute ("SELECT id, status, value FROM data WHERE taskid = ? AND content_type = ?" , (self .taskid , content_type ))
238236
239237 # Delete partial output from IPC database if we have got a complete output
240238 if status == CONTENT_STATUS .COMPLETE :
241239 if len (output ) > 0 :
242240 for index in xrange (len (output )):
243- conf .databaseCursor .execute ("DELETE FROM data WHERE id = ?" ,
244- (output [index ][0 ],))
241+ conf .databaseCursor .execute ("DELETE FROM data WHERE id = ?" , (output [index ][0 ],))
245242
246- conf .databaseCursor .execute ("INSERT INTO data VALUES(NULL, ?, ?, ?, ?)" ,
247- (self .taskid , status , content_type , jsonize (value )))
243+ conf .databaseCursor .execute ("INSERT INTO data VALUES(NULL, ?, ?, ?, ?)" , (self .taskid , status , content_type , jsonize (value )))
248244 if kb .partRun :
249245 kb .partRun = None
250246
251247 elif status == CONTENT_STATUS .IN_PROGRESS :
252248 if len (output ) == 0 :
253- conf .databaseCursor .execute ("INSERT INTO data VALUES(NULL, ?, ?, ?, ?)" ,
254- (self .taskid , status , content_type ,
255- jsonize (value )))
249+ conf .databaseCursor .execute ("INSERT INTO data VALUES(NULL, ?, ?, ?, ?)" , (self .taskid , status , content_type , jsonize (value )))
256250 else :
257251 new_value = "%s%s" % (dejsonize (output [0 ][2 ]), value )
258- conf .databaseCursor .execute ("UPDATE data SET value = ? WHERE id = ?" ,
259- (jsonize (new_value ), output [0 ][0 ]))
252+ conf .databaseCursor .execute ("UPDATE data SET value = ? WHERE id = ?" , (jsonize (new_value ), output [0 ][0 ]))
260253 else :
261- conf .databaseCursor .execute ("INSERT INTO errors VALUES(NULL, ?, ?)" ,
262- (self .taskid , str (value ) if value else "" ))
254+ conf .databaseCursor .execute ("INSERT INTO errors VALUES(NULL, ?, ?)" , (self .taskid , str (value ) if value else "" ))
263255
264256 def flush (self ):
265257 pass
@@ -270,17 +262,13 @@ def close(self):
270262 def seek (self ):
271263 pass
272264
273-
274265class LogRecorder (logging .StreamHandler ):
275266 def emit (self , record ):
276267 """
277268 Record emitted events to IPC database for asynchronous I/O
278269 communication with the parent process
279270 """
280- conf .databaseCursor .execute ("INSERT INTO logs VALUES(NULL, ?, ?, ?, ?)" ,
281- (conf .taskid , time .strftime ("%X" ), record .levelname ,
282- record .msg % record .args if record .args else record .msg ))
283-
271+ conf .databaseCursor .execute ("INSERT INTO logs VALUES(NULL, ?, ?, ?, ?)" , (conf .taskid , time .strftime ("%X" ), record .levelname , record .msg % record .args if record .args else record .msg ))
284272
285273def setRestAPILog ():
286274 if conf .api :
@@ -555,16 +543,11 @@ def scan_data(taskid):
555543 return jsonize ({"success" : False , "message" : "Invalid task ID" })
556544
557545 # Read all data from the IPC database for the taskid
558- for status , content_type , value in DataStore .current_db .execute (
559- "SELECT status, content_type, value FROM data WHERE taskid = ? ORDER BY id ASC" ,
560- (taskid ,)):
561- json_data_message .append (
562- {"status" : status , "type" : content_type , "value" : dejsonize (value )})
546+ for status , content_type , value in DataStore .current_db .execute ("SELECT status, content_type, value FROM data WHERE taskid = ? ORDER BY id ASC" , (taskid ,)):
547+ json_data_message .append ({"status" : status , "type" : content_type , "value" : dejsonize (value )})
563548
564549 # Read all error messages from the IPC database
565- for error in DataStore .current_db .execute (
566- "SELECT error FROM errors WHERE taskid = ? ORDER BY id ASC" ,
567- (taskid ,)):
550+ for error in DataStore .current_db .execute ("SELECT error FROM errors WHERE taskid = ? ORDER BY id ASC" , (taskid ,)):
568551 json_errors_message .append (error )
569552
570553 logger .debug ("[%s] Retrieved scan data and error messages" % taskid )
@@ -591,10 +574,7 @@ def scan_log_limited(taskid, start, end):
591574 end = max (1 , int (end ))
592575
593576 # Read a subset of log messages from the IPC database
594- for time_ , level , message in DataStore .current_db .execute (
595- ("SELECT time, level, message FROM logs WHERE "
596- "taskid = ? AND id >= ? AND id <= ? ORDER BY id ASC" ),
597- (taskid , start , end )):
577+ for time_ , level , message in DataStore .current_db .execute ("SELECT time, level, message FROM logs WHERE taskid = ? AND id >= ? AND id <= ? ORDER BY id ASC" , (taskid , start , end )):
598578 json_log_messages .append ({"time" : time_ , "level" : level , "message" : message })
599579
600580 logger .debug ("[%s] Retrieved scan log messages subset" % taskid )
@@ -613,8 +593,7 @@ def scan_log(taskid):
613593 return jsonize ({"success" : False , "message" : "Invalid task ID" })
614594
615595 # Read all log messages from the IPC database
616- for time_ , level , message in DataStore .current_db .execute (
617- "SELECT time, level, message FROM logs WHERE taskid = ? ORDER BY id ASC" , (taskid ,)):
596+ for time_ , level , message in DataStore .current_db .execute ("SELECT time, level, message FROM logs WHERE taskid = ? ORDER BY id ASC" , (taskid ,)):
618597 json_log_messages .append ({"time" : time_ , "level" : level , "message" : message })
619598
620599 logger .debug ("[%s] Retrieved scan log messages" % taskid )
0 commit comments