summaryrefslogtreecommitdiffstats
path: root/scripts/getsnapshots.py
blob: ecbd7d8aaa8c8ad4d67f5a2c92d5f653133ca05d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import sys
import json

from misc import idToText, textToId, getSnapshots, printJSONHeader

class GetSnapshots:

    def __init__(
        self, host, platform, branch, sha11, sha12):
        self.host = host
        self.platform = platform
        self.branch = branch
        self.sha11 = sha11
        self.sha12 = sha12
        self.host_id = textToId("host", host)
        self.platform_id = textToId("platform", platform)
        self.branch_id = textToId("branch", branch)
        self.sha11_id = textToId("sha1", sha11)
        self.sha12_id = textToId("sha1", sha12)

    def execute(self):
        self.snapshots = []
        for sha1_id, timestamp in getSnapshots(self.host_id, self.platform_id,
                self.branch_id, self.sha11_id, self.sha12_id):
            self.snapshots.append((idToText('sha1', sha1_id), timestamp))

        self.writeOutput()

    def writeOutputAsJSON(self):
        printJSONHeader()
        json.dump({ 'snapshots': self.snapshots }, sys.stdout)

class GetSnapshotsAsJSON(GetSnapshots):
    def writeOutput(self):
        self.writeOutputAsJSON()