2013-01-22 21:57:14 +04:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# Copyright (c) 2013 The Chromium Authors. All rights reserved.
|
|
|
|
# Use of this source code is governed by a BSD-style license that can be
|
|
|
|
# found in the LICENSE file.
|
|
|
|
|
|
|
|
"""Make a symlink and optionally touch a file (to handle dependencies)."""
|
|
|
|
|
|
|
|
|
|
|
|
import errno
|
|
|
|
import optparse
|
|
|
|
import os.path
|
2015-07-01 22:09:40 +03:00
|
|
|
import shutil
|
2013-01-22 21:57:14 +04:00
|
|
|
import sys
|
|
|
|
|
|
|
|
|
|
|
|
def Main(argv):
|
|
|
|
parser = optparse.OptionParser()
|
|
|
|
parser.add_option('-f', '--force', action='store_true')
|
|
|
|
parser.add_option('--touch')
|
|
|
|
|
2013-05-29 01:49:11 +04:00
|
|
|
options, args = parser.parse_args(argv[1:])
|
2013-01-22 21:57:14 +04:00
|
|
|
if len(args) < 2:
|
|
|
|
parser.error('at least two arguments required.')
|
|
|
|
|
|
|
|
target = args[-1]
|
|
|
|
sources = args[:-1]
|
|
|
|
for s in sources:
|
|
|
|
t = os.path.join(target, os.path.basename(s))
|
2015-07-15 23:13:15 +03:00
|
|
|
if len(sources) == 1 and not os.path.isdir(target):
|
|
|
|
t = target
|
2013-01-22 21:57:14 +04:00
|
|
|
try:
|
|
|
|
os.symlink(s, t)
|
|
|
|
except OSError, e:
|
|
|
|
if e.errno == errno.EEXIST and options.force:
|
2015-07-01 22:09:40 +03:00
|
|
|
if os.path.isdir(t):
|
|
|
|
shutil.rmtree(t, ignore_errors=True)
|
|
|
|
else:
|
|
|
|
os.remove(t)
|
2013-01-22 21:57:14 +04:00
|
|
|
os.symlink(s, t)
|
|
|
|
else:
|
|
|
|
raise
|
|
|
|
|
|
|
|
|
|
|
|
if options.touch:
|
|
|
|
with open(options.touch, 'w') as f:
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
sys.exit(Main(sys.argv))
|