Flutter Engine
The Flutter Engine
copy_path.py
Go to the documentation of this file.
1#!/usr/bin/env python3
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
7""" Copies paths, creates if they do not exist.
8"""
9
10import argparse
11import errno
12import json
13import os
14import platform
15import shutil
16import subprocess
17import sys
18
19
21 dir_name, _ = os.path.split(path)
22 if not os.path.exists(dir_name):
23 os.makedirs(dir_name)
24
25
26def SameStat(s1, s2):
27 return s1.st_ino == s2.st_ino and s1.st_dev == s2.st_dev
28
29
30def SameFile(f1, f2):
31 if not os.path.exists(f2):
32 return False
33 s1 = os.stat(f1)
34 s2 = os.stat(f2)
35 return SameStat(s1, s2)
36
37
38def CopyPath(src, dst):
39 try:
41 shutil.copytree(src, dst)
42 except OSError as exc:
43 if exc.errno == errno.ENOTDIR:
44 if not SameFile(src, dst):
45 shutil.copyfile(src, dst)
46 else:
47 raise
48
49
50def main():
51 parser = argparse.ArgumentParser()
52
53 parser.add_argument('--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())
def main()
Definition: copy_path.py:50
def SameFile(f1, f2)
Definition: copy_path.py:30
def SameStat(s1, s2)
Definition: copy_path.py:26
def CopyPath(src, dst)
Definition: copy_path.py:38
def EnsureParentExists(path)
Definition: copy_path.py:20
Definition: main.py:1