blob: dbf4d211483fea8254d4f546736d59ddc088dbee [file] [log] [blame]
#!/usr/bin/python3
# Copyright 2019 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.
"""Copies files from checkout dir to staging dir based on contents.json."""
import argparse
import json
import shutil
from pathlib import Path
def main():
parser = argparse.ArgumentParser(
description=(
'Copy files from checkout directory to staging directory using '
'instructions in <checkout-dir>/contents.json'))
parser.add_argument('staging_dir', metavar='staging-dir', type=str)
parser.add_argument('--checkout-dir', type=str, default='.',
help='Path to jiri checkout directory. Defaults to current working directory.')
args = parser.parse_args()
staging_dir = Path(args.staging_dir).resolve()
checkout_dir = Path(args.checkout_dir).resolve()
contents_path = checkout_dir.joinpath('contents.json')
with open(contents_path, 'r') as file:
contents = json.load(file)
for bundle in contents:
destination_dir = staging_dir.joinpath((bundle['destination']))
destination_dir.mkdir(parents=True, exist_ok=True)
for file_path in bundle['files']:
file_name = Path(file_path).name
src = checkout_dir.joinpath(file_path)
dst = destination_dir.joinpath(file_name)
shutil.copy(src, dst)
if __name__ == '__main__':
main()