blob: 3e8ccf6a1dac6af56cfb762faa3625bc0e06bf7b [file] [log] [blame]
David Brazdil6c63a262019-12-23 13:23:46 +00001#!/usr/bin/env python3
David Brazdile7a5a1f2019-08-09 18:48:38 +01002#
3# Copyright 2019 The Hafnium Authors.
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# https://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
David Brazdile7a5a1f2019-08-09 18:48:38 +010017"""Copies all files inside one folder to another, preserving subfolders."""
18
19import argparse
20import os
21import shutil
22import sys
23
24def main():
25 parser = argparse.ArgumentParser()
26 parser.add_argument("source_folder",
27 help="directory to be copied from")
28 parser.add_argument("destination_folder",
29 help="directory to be copied into")
30 parser.add_argument("stamp_file",
31 help="stamp file to be touched")
32 args = parser.parse_args()
33
34 # Walk the subfolders of the source directory and copy individual files.
35 # Not using shutil.copytree() because it never overwrites files.
36 for root, _, files in os.walk(args.source_folder):
37 for f in files:
38 abs_src_path = os.path.join(root, f)
39 rel_path = os.path.relpath(abs_src_path, args.source_folder)
40 abs_dst_path = os.path.join(args.destination_folder, rel_path)
41 abs_dst_folder = os.path.dirname(abs_dst_path)
42 if not os.path.isdir(abs_dst_folder):
43 os.makedirs(abs_dst_folder)
44 shutil.copyfile(abs_src_path, abs_dst_path)
45
46 # Touch `stamp_file`.
47 with open(args.stamp_file, "w"):
48 pass
49
50if __name__ == "__main__":
51 sys.exit(main())