blob: 1c81cb34c5e535ded06b1c171bdcc95659b0911b [file] [log] [blame]
#!/usr/bin/env python
# Copyright 2015 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
./ -a path_to_archiver -d input_output_dir
input_output_dir should points to the directory where images are created by The script outputs archives to input_output_dir.
path_to_archiver should points to the tool which bundles files into a blob,
which can be unpacked by Depthcharge.
from collections import defaultdict
import getopt
import glob
import os
import subprocess
import sys
def archive_images(archiver, output, name, files):
"""Archive files.
archiver: path to the archive tool
output: path to the output directory
name: name of the archive file
files: list of files to be archived
archive = os.path.join(output, name)
paths = [ os.path.join(output, x) for x in files]
args = ' '.join(paths)
command = '%s %s create %s' % (archiver, archive, args), shell=True)
def archive(archiver, output):
"""Archive base images and localized images
archiver: path to the archive tool
output: path to the output directory
base_images = []
locale_images = defaultdict(lambda: [])
files = glob.glob(os.path.join(output, "*.bmp"))
for file in files:
base = os.path.basename(file)
# create archive of base images
archive_images(archiver, output, 'vbgfx.bin', base_images)
dirs = glob.glob(os.path.join(output, "locale/*"))
for dir in dirs:
files = glob.glob(os.path.join(dir, "*.bmp"))
locale = os.path.basename(dir)
for file in files:
# create archives of localized images
for locale, images in locale_images.iteritems():
archive_images(archiver, output, 'locale_%s.bin' % locale, images)
def main(args):
opts, args = getopt.getopt(args, 'a:d:')
archiver = ''
output = ''
for opt, arg in opts:
if opt == '-a':
archiver = arg
elif opt == '-d':
output = arg
assert False, 'Invalid option'
if args or not archiver or not output:
assert False, 'Invalid usage'
archive(archiver, output)
if __name__ == '__main__':