blob: 4ee274bc5e5ee29b56870492cbf3e9a609a9b700 [file] [log] [blame]
Daisuke Nojirid853d132015-11-04 12:39:06 -08001#!/usr/bin/env python
2# Copyright 2015 The Chromium OS Authors. All rights reserved.
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
6'''
7Usage:
8 ./archive_images.py -a path_to_archiver -d input_output_dir
9
10 input_output_dir should points to the directory where images are created by
11 build_images.py. The script outputs archives to input_output_dir.
12
13 path_to_archiver should points to the tool which bundles files into a blob,
14 which can be unpacked by Depthcharge.
15'''
16
17from collections import defaultdict
18import getopt
Daisuke Nojiri87f18e02016-08-30 15:49:23 -070019import glob
Daisuke Nojirid853d132015-11-04 12:39:06 -080020import os
21import subprocess
22import sys
Daisuke Nojirid853d132015-11-04 12:39:06 -080023
24def archive_images(archiver, output, name, files):
25 """Archive files.
26
27 Args:
28 archiver: path to the archive tool
29 output: path to the output directory
30 name: name of the archive file
31 files: list of files to be archived
32 """
33 archive = os.path.join(output, name)
Yu-Ping Wu462f4cc2019-12-19 09:14:56 +080034 args = ' '.join(files)
Daisuke Nojirid853d132015-11-04 12:39:06 -080035 command = '%s %s create %s' % (archiver, archive, args)
36 subprocess.call(command, shell=True)
37
38def archive(archiver, output):
Daisuke Nojiri87f18e02016-08-30 15:49:23 -070039 """Archive base images and localized images
Daisuke Nojirid853d132015-11-04 12:39:06 -080040
41 Args:
42 archiver: path to the archive tool
43 output: path to the output directory
44 """
Yu-Ping Wu462f4cc2019-12-19 09:14:56 +080045 base_images = glob.glob(os.path.join(output, "*.bmp"))
Daisuke Nojiri87f18e02016-08-30 15:49:23 -070046
47 # create archive of base images
Daisuke Nojirid853d132015-11-04 12:39:06 -080048 archive_images(archiver, output, 'vbgfx.bin', base_images)
49
Yu-Ping Wu462f4cc2019-12-19 09:14:56 +080050 locale_images = defaultdict(lambda: [])
Daisuke Nojiri87f18e02016-08-30 15:49:23 -070051 dirs = glob.glob(os.path.join(output, "locale/*"))
52 for dir in dirs:
53 files = glob.glob(os.path.join(dir, "*.bmp"))
54 locale = os.path.basename(dir)
55 for file in files:
56 locale_images[locale].append(file)
57
58 # create archives of localized images
59 for locale, images in locale_images.iteritems():
60 archive_images(archiver, output, 'locale_%s.bin' % locale, images)
Daisuke Nojirid853d132015-11-04 12:39:06 -080061
62def main(args):
63 opts, args = getopt.getopt(args, 'a:d:')
64 archiver = ''
65 output = ''
66
67 for opt, arg in opts:
68 if opt == '-a':
69 archiver = arg
70 elif opt == '-d':
71 output = arg
72 else:
73 assert False, 'Invalid option'
74 if args or not archiver or not output:
75 assert False, 'Invalid usage'
76
77 archive(archiver, output)
78
79if __name__ == '__main__':
80 main(sys.argv[1:])