blob: 6c490c9e01a0fff49043daa058118c4b8492d7b7 [file] [log] [blame]
#!/usr/bin/env python
# Copyright 2017 The Fuchsia Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import argparse
import json
import os
import sys
from urlparse import urlparse
from sdk_common import Atom
class MappingAction(argparse.Action):
'''Parses file mappings flags.'''
def __init__(self, option_strings, dest, nargs=None, **kwargs):
if nargs is not None:
raise ValueError("nargs is not allowed")
super(MappingAction, self).__init__(option_strings, dest, nargs=2,
def __call__(self, parser, namespace, values, option_string=None):
mappings = getattr(namespace, 'mappings', None)
if mappings is None:
mappings = {}
setattr(namespace, 'mappings', mappings)
mappings[values[0]] = values[1]
def main():
parser = argparse.ArgumentParser()
help='Path to the SDK\'s manifest file',
help='Extra files to add to the archive',
help='Path to the output file manifest',
args = parser.parse_args()
with open(args.manifest, 'r') as manifest_file:
manifest = json.load(manifest_file)
all_files = {}
def add(dest, src):
if dest in all_files:
print('Error: multiple entries for %s' % dest)
print(' - %s' % all_files[dest])
print(' - %s' % src)
return 1
all_files[dest] = src
for atom in [Atom(a) for a in manifest['atoms']]:
for file in atom.files:
add(file.destination, file.source)
for dest, source in args.mappings.iteritems():
add(dest, source)
with open(args.output, 'w') as output_file:
for mapping in sorted(all_files.iteritems()):
output_file.write('%s=%s\n' % mapping)
if __name__ == '__main__':