| #!/usr/bin/env python |
| |
| # Copyright 2019 Google LLC. All rights reserved. |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| |
| """ |
| Opens |base_manifest| and copies the contents to |manifest| then traverses |
| |root_dir| and appends every file as a Fuchsia package manifest entry to |
| |manifest|. |
| """ |
| |
| import argparse |
| import os |
| import subprocess |
| |
| parser = argparse.ArgumentParser() |
| parser.add_argument('--root_dir', dest='root_dir', action='store', required=True) |
| parser.add_argument('--base_manifest', dest='base_manifest', action='store', required=True) |
| parser.add_argument('--manifest', dest='manifest', action='store', required=True) |
| args = parser.parse_args() |
| |
| root_dir = args.root_dir |
| if not os.path.exists(root_dir): |
| print "--root_dir path specified: " + root_dir + " doesn't exist." |
| exit(1) |
| |
| base_manifest = args.base_manifest |
| if not os.path.exists(base_manifest): |
| print "--base_manifest specified: " + base_manifest + " doesn't exist." |
| exit(1) |
| |
| manifest = args.manifest |
| |
| # Prepend |base_manifest| contents to |manifest|. |
| out_file = open(manifest, 'w') |
| with open(base_manifest, 'r') as in_file: |
| out_file.write(in_file.read()) |
| |
| # Append all files discovered under |root_dir| to |manifest|. |
| files = subprocess.check_output(["find", root_dir, "-type", "f"]) |
| file_lines = files.splitlines() |
| |
| for file in file_lines: |
| source = file |
| if not source.startswith(root_dir): |
| print "Error: source path " + source + " is not under |root_dir|\n" |
| exit(1) |
| dest = source[len(root_dir):] |
| out_file.write('data%s=' % dest) |
| out_file.write('%s\n' % source) |
| |
| out_file.close() |