2 # Copyright (c) 2013 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
6 """Make a symlink and optionally touch a file (to handle dependencies).
9 symlink.py [options] sources... target
11 A sym link to source is created at target. If multiple sources are specfied,
12 then target is assumed to be a directory, and will contain all the links to
13 the sources (basenames identical to their source).
24 parser = optparse.OptionParser()
25 parser.add_option('-f', '--force', action='store_true')
26 parser.add_option('--touch')
28 options, args = parser.parse_args(argv[1:])
30 parser.error('at least two arguments required.')
35 t = os.path.join(target, os.path.basename(s))
36 if len(sources) == 1 and not os.path.isdir(target):
38 t = os.path.expanduser(t)
39 if os.path.realpath(t) == s:
44 if e.errno == errno.EEXIST and options.force:
46 shutil.rmtree(t, ignore_errors=True)
55 with open(options.touch, 'w') as f:
59 if __name__ == '__main__':
60 sys.exit(Main(sys.argv))