1#!/usr/bin/env python 2# 3# Copyright 2013 The Flutter Authors. All rights reserved. 4# Use of this source code is governed by a BSD-style license that can be 5# found in the LICENSE file. 6""" Copies paths, creates if they do not exist. 7""" 8 9import argparse 10import errno 11import json 12import os 13import platform 14import shutil 15import subprocess 16import sys 17 18 19def EnsureParentExists(path): 20 dir_name, _ = os.path.split(path) 21 if not os.path.exists(dir_name): 22 os.makedirs(dir_name) 23 24 25def SameStat(s1, s2): 26 return s1.st_ino == s2.st_ino and s1.st_dev == s2.st_dev 27 28 29def SameFile(f1, f2): 30 if not os.path.exists(f2): 31 return False 32 s1 = os.stat(f1) 33 s2 = os.stat(f2) 34 return SameStat(s1, s2) 35 36 37def CopyPath(src, dst): 38 try: 39 EnsureParentExists(dst) 40 shutil.copytree(src, dst) 41 except OSError as exc: 42 if exc.errno == errno.ENOTDIR: 43 if not SameFile(src, dst): 44 shutil.copyfile(src, dst) 45 else: 46 raise 47 48 49def main(): 50 parser = argparse.ArgumentParser() 51 52 parser.add_argument( 53 '--file-list', dest='file_list', action='store', required=True) 54 55 args = parser.parse_args() 56 57 files = open(args.file_list, 'r') 58 files_to_copy = files.read().split() 59 num_files = len(files_to_copy) / 2 60 61 for i in range(num_files): 62 CopyPath(files_to_copy[i], files_to_copy[num_files + i]) 63 64 return 0 65 66 67if __name__ == '__main__': 68 sys.exit(main()) 69