import sys import json from dbaccess import execQuery, database, commit from misc import textToId, printJSONHeader class SetTimeSeriesNote: def __init__( self, host, platform, branch, benchmark, metric, note): self.host_id = textToId('host', host) self.platform_id = textToId('platform', platform) self.branch_id = textToId('branch', branch) self.benchmark_id = textToId('benchmark', benchmark) self.metric_id = textToId('metric', metric) max_length = 256 self.note = note.strip()[:max_length] def execute(self): if len(self.note) == 0: # Delete the row from the table: query = ( "DELETE FROM timeSeriesAnnotation" " WHERE hostId = %d" " AND platformId = %d" " AND branchId = %d" " AND benchmarkId = %d" " AND metricId = %d;" % (self.host_id, self.platform_id, self.branch_id, self.benchmark_id, self.metric_id)) execQuery(query, False) else: # Insert or update table row: query = ( "SELECT merge_timeSeriesNote(%d, %d, %d, %d, %d, '%s');" % (self.host_id, self.platform_id, self.branch_id, self.benchmark_id, self.metric_id, self.note)) execQuery(query, False) # Write to database: commit() # Return empty reply to client: printJSONHeader() json.dump({ }, sys.stdout)