1#!/usr/bin/env python
2
3from __future__ import absolute_import, print_function
4
5import logging
6import os
7from os import path
8import sys
9from tempfile import mkstemp
10
11sys.path.append(path.join(path.dirname(__file__), "../python"))
12logging.basicConfig(
13    stream=sys.stdout, level=logging.INFO, format="%(message)s")
14log = logging.getLogger(__name__)
15
16from mozrelease.update_verify import UpdateVerifyConfig
17from util.commands import run_cmd
18
19UPDATE_VERIFY_COMMAND = ["bash", "verify.sh", "-c"]
20UPDATE_VERIFY_DIR = path.join(
21    path.dirname(__file__), "../release/updates")
22
23
24if __name__ == "__main__":
25    from argparse import ArgumentParser
26    parser = ArgumentParser("")
27
28    parser.set_defaults(
29        chunks=None,
30        thisChunk=None,
31    )
32    parser.add_argument("--verify-config", required=True, dest="verifyConfig")
33    parser.add_argument("--verify-channel", required=True, dest="verify_channel")
34    parser.add_argument("--chunks", required=True, dest="chunks", type=int)
35    parser.add_argument("--this-chunk", required=True, dest="thisChunk", type=int)
36
37    options = parser.parse_args()
38    assert options.chunks and options.thisChunk, \
39        "chunks and this-chunk are required"
40    assert path.isfile(options.verifyConfig), "Update verify config must exist!"
41    verifyConfigFile = options.verifyConfig
42
43    fd, configFile = mkstemp()
44    fh = os.fdopen(fd, "w")
45    try:
46        verifyConfig = UpdateVerifyConfig()
47        verifyConfig.read(path.join(UPDATE_VERIFY_DIR, verifyConfigFile))
48        myVerifyConfig = verifyConfig.getChunk(
49            options.chunks, options.thisChunk)
50        # override the channel if explicitly set
51        if options.verify_channel:
52            myVerifyConfig.channel = options.verify_channel
53        myVerifyConfig.write(fh)
54        fh.close()
55        run_cmd(["cat", configFile])
56        run_cmd(UPDATE_VERIFY_COMMAND + [configFile], cwd=UPDATE_VERIFY_DIR)
57    finally:
58        if path.exists(configFile):
59            os.unlink(configFile)
60