File: update_binaries.py

package info (click to toggle)
chromium 138.0.7204.157-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 6,071,864 kB
  • sloc: cpp: 34,936,859; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,967; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (77 lines) | stat: -rwxr-xr-x 2,683 bytes parent folder | download | duplicates (5)
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/env python3
# Copyright 2021 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import logging
import os
import subprocess
import shutil
import sys
import tempfile

from zipfile import ZipFile

DIR_SOURCE_ROOT = os.path.abspath(
    os.path.join(os.path.dirname(__file__), os.pardir, os.pardir))

sys.path.append(os.path.join(DIR_SOURCE_ROOT, 'build'))
import find_depot_tools

CAST_CORE_ROOT = os.path.abspath(
    os.path.join(DIR_SOURCE_ROOT, 'third_party', 'cast_core', 'prebuilts'))
CAST_CORE_ZIP_PATH_TEMPLATE = (
    'gs://castlite-release-artifacts/{version}/third_party/castlite' \
    '/cast_core_qa_sdk_runtime_vizio_castos_armv7a' \
    '/sdk_runtime_vizio_castos_armv7a.tgz')
SIGNATURE_FILE = '.version'
RUNTIME_ROOT = os.path.abspath(
    os.path.join(DIR_SOURCE_ROOT, 'third_party', 'cast_web_runtime'))
RUNTIME_ZIP_PATH_TEMPLATE = (
    'gs://gtv-eureka/internal/1.56core/core_runtime-eng/{version}' \
    '/core_runtime_package.zip')


def DownloadFromCloudStorage(url, output_dir):
  """Fetches a file from GCS and put it in |output_dir|."""
  cmd = [
      os.path.join(find_depot_tools.DEPOT_TOOLS_PATH, 'gsutil.py'), 'cp', url,
      output_dir
  ]
  task = subprocess.check_call(cmd,
                               stdout=subprocess.DEVNULL,
                               stderr=subprocess.DEVNULL)


def MakeCleanDirectory(directory_name):
  if os.path.exists(directory_name):
    shutil.rmtree(directory_name)
  os.mkdir(directory_name)


def UpdateBinaryIfNecessary(name, version_file, output_dir, gcs_path_template):
  """Update the binary at |output_dir| if necessary by comparing versions."""
  version = open(os.path.join(os.path.dirname(__file__),
                              version_file)).read().strip()
  signature_file_path = os.path.join(output_dir, SIGNATURE_FILE)
  current_signature = (open(signature_file_path, 'r').read().strip()
                       if os.path.exists(signature_file_path) else '')
  if current_signature != version:
    logging.info('Downloading {} version {}...'.format(name, version))
    MakeCleanDirectory(output_dir)
    DownloadFromCloudStorage(gcs_path_template.format(version=version),
                             output_dir)
  with open(signature_file_path, 'w') as f:
    f.write(version)


def main():
  UpdateBinaryIfNecessary('Cast Core', 'cast_core.version', CAST_CORE_ROOT,
                          CAST_CORE_ZIP_PATH_TEMPLATE)
  UpdateBinaryIfNecessary('Cast Web Runtime', 'runtime.version', RUNTIME_ROOT,
                          RUNTIME_ZIP_PATH_TEMPLATE)
  return 0


if __name__ == '__main__':
  sys.exit(main())