diff options
Diffstat (limited to 'scripts/listcontexts.py')
-rw-r--r-- | scripts/listcontexts.py | 46 |
1 files changed, 12 insertions, 34 deletions
diff --git a/scripts/listcontexts.py b/scripts/listcontexts.py index 4aae8bc..a78daa5 100644 --- a/scripts/listcontexts.py +++ b/scripts/listcontexts.py @@ -6,15 +6,8 @@ from misc import idToText, printJSONHeader class ListContexts: - def __init__(self, ranked_only): - self.ranked_only = ranked_only - - - def rankingsExist(self, contextId): - rankings = execQuery( - "SELECT id FROM ranking WHERE context2Id = %s LIMIT 1", - (contextId,)) - return len(rankings) > 0 + def __init__(self): + pass def execute(self): @@ -36,44 +29,29 @@ class ListContexts: id, host, platform, branch, sha1, timestamp = contexts[0] curHost, curPlatform, curBranch = host, platform, branch - - rankings_exist = self.rankingsExist(id) - rankings_exist_count = 1 if rankings_exist else 0 - - curSnapshots = [] - if (not self.ranked_only) or rankings_exist: - curSnapshots = [ - (idToText('sha1', sha1), timestamp, 1 if rankings_exist else 0)] + curSnapshots = [(idToText('sha1', sha1), timestamp)] for (id, host, platform, branch, sha1, timestamp) in contexts[1:]: if (host, platform, branch) != (curHost, curPlatform, curBranch): - if (not self.ranked_only) or (rankings_exist_count > 0): - assert len(curSnapshots) > 0 - self.contexts.append({ - 'host' : idToText('host', curHost), - 'platform' : idToText('platform', curPlatform), - 'branch' : idToText('branch', curBranch), - 'snapshots' : curSnapshots - }) - - rankings_exist_count = 0 + self.contexts.append({ + 'host' : idToText('host', curHost), + 'platform' : idToText('platform', curPlatform), + 'branch' : idToText('branch', curBranch), + 'snapshots' : curSnapshots + }) curHost, curPlatform, curBranch = host, platform, branch curSnapshots = [] - rankings_exist = self.rankingsExist(id) - if rankings_exist: - rankings_exist_count = rankings_exist_count + 1 - if (not self.ranked_only) or rankings_exist: - curSnapshots.append( - (idToText('sha1', sha1), timestamp, - 1 if rankings_exist else 0)) + curSnapshots.append((idToText('sha1', sha1), timestamp)) self.writeOutput() + def writeOutputAsJSON(self): printJSONHeader() json.dump({ 'contexts' : self.contexts }, sys.stdout) + class ListContextsAsJSON(ListContexts): def writeOutput(self): self.writeOutputAsJSON() |