OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 2 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
3 # for details. All rights reserved. Use of this source code is governed by a | 3 # for details. All rights reserved. Use of this source code is governed by a |
4 # BSD-style license that can be found in the LICENSE file. | 4 # BSD-style license that can be found in the LICENSE file. |
5 | 5 |
6 | 6 |
7 """Tool for creating symlinks from SOURCES to TARGET. | 7 """Tool for creating symlinks from SOURCES to TARGET. |
8 | 8 |
9 For each SOURCE in SOURCES create a link from SOURCE to TARGET. If a | 9 For each SOURCE in SOURCES create a link from SOURCE to TARGET. If a |
10 SOURCE ends with .../lib, the lib suffix is ignored when determining | 10 SOURCE ends with .../lib, the lib suffix is ignored when determining |
(...skipping 24 matching lines...) Expand all Loading... |
35 | 35 |
36 def get_options(): | 36 def get_options(): |
37 result = optparse.OptionParser() | 37 result = optparse.OptionParser() |
38 result.add_option("--timestamp_file", "", | 38 result.add_option("--timestamp_file", "", |
39 help='Create a timestamp file when done creating the links.', | 39 help='Create a timestamp file when done creating the links.', |
40 default='') | 40 default='') |
41 return result.parse_args() | 41 return result.parse_args() |
42 | 42 |
43 def make_link(source, target, orig_source): | 43 def make_link(source, target, orig_source): |
44 if os.path.islink(target): | 44 if os.path.islink(target): |
45 print 'Removing %s' % target | |
46 sys.stdout.flush() | |
47 os.unlink(target) | 45 os.unlink(target) |
48 | 46 |
49 if os.path.isdir(target): | 47 if os.path.isdir(target): |
50 print 'Removing %s' % target | |
51 sys.stdout.flush() | |
52 os.rmdir(target) | 48 os.rmdir(target) |
53 | 49 |
54 if os.path.isfile(orig_source): | 50 if os.path.isfile(orig_source): |
55 print 'Copying file from %s to %s' % (orig_source, target) | |
56 sys.stdout.flush() | |
57 shutil.copyfile(orig_source, target) | 51 shutil.copyfile(orig_source, target) |
58 return 0 | 52 return 0 |
59 else: | 53 else: |
60 print 'Creating link from %s to %s' % (source, target) | |
61 sys.stdout.flush() | |
62 | |
63 if utils.GuessOS() == 'win32': | 54 if utils.GuessOS() == 'win32': |
64 return subprocess.call(['mklink', '/j', target, source], shell=True) | 55 return subprocess.call(['mklink', '/j', target, source], shell=True) |
65 else: | 56 else: |
66 return subprocess.call(['ln', '-s', source, target]) | 57 return subprocess.call(['ln', '-s', source, target]) |
67 | 58 |
68 def create_timestamp_file(options): | 59 def create_timestamp_file(options): |
69 if options.timestamp_file != '': | 60 if options.timestamp_file != '': |
70 dir_name = os.path.dirname(options.timestamp_file) | 61 dir_name = os.path.dirname(options.timestamp_file) |
71 if not os.path.exists(dir_name): | 62 if not os.path.exists(dir_name): |
72 os.mkdir(dir_name) | 63 os.mkdir(dir_name) |
(...skipping 10 matching lines...) Expand all Loading... |
83 for link in os.listdir(target): | 74 for link in os.listdir(target): |
84 full_link = os.path.join(target, link) | 75 full_link = os.path.join(target, link) |
85 if os.path.isdir(full_link) and utils.IsWindows(): | 76 if os.path.isdir(full_link) and utils.IsWindows(): |
86 # It seems like python on Windows is treating pseudo symlinks to | 77 # It seems like python on Windows is treating pseudo symlinks to |
87 # directories as directories. | 78 # directories as directories. |
88 os.rmdir(full_link) | 79 os.rmdir(full_link) |
89 else: | 80 else: |
90 os.remove(full_link) | 81 os.remove(full_link) |
91 else: | 82 else: |
92 os.makedirs(target) | 83 os.makedirs(target) |
93 linked_names = {}; | 84 linked_names = {}; |
94 for source in args[1:]: | 85 for source in args[1:]: |
95 # Assume the source directory is named ".../NAME/lib". | 86 # Assume the source directory is named ".../NAME/lib". |
96 split = source.split(':') | 87 split = source.split(':') |
97 name = None | 88 name = None |
98 if len(split) == 2: (source, name) = split | 89 if len(split) == 2: (source, name) = split |
99 | 90 |
100 (path, lib) = os.path.split(source) | 91 (path, lib) = os.path.split(source) |
101 if lib != 'lib': | 92 if lib != 'lib': |
102 path = source | 93 path = source |
103 # Remove any additional path components preceding NAME, if one wasn't | 94 # Remove any additional path components preceding NAME, if one wasn't |
(...skipping 15 matching lines...) Expand all Loading... |
119 source = os.path.relpath(source, start=target) | 110 source = os.path.relpath(source, start=target) |
120 exit_code = make_link(source, os.path.join(target, name), orig_source) | 111 exit_code = make_link(source, os.path.join(target, name), orig_source) |
121 if exit_code != 0: | 112 if exit_code != 0: |
122 return exit_code | 113 return exit_code |
123 create_timestamp_file(options) | 114 create_timestamp_file(options) |
124 return 0 | 115 return 0 |
125 | 116 |
126 | 117 |
127 if __name__ == '__main__': | 118 if __name__ == '__main__': |
128 sys.exit(main(sys.argv)) | 119 sys.exit(main(sys.argv)) |
OLD | NEW |