blob: aade2f865c7a18993dcf58d5aa68ea74464741fa [file] [log] [blame]
phajdan.jr@chromium.orga15170a2013-01-23 02:57:14 +09001#!/usr/bin/env python
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.
5
6"""Make a symlink and optionally touch a file (to handle dependencies)."""
7
8
9import errno
10import optparse
11import os.path
12import sys
13
14
15def Main(argv):
16 parser = optparse.OptionParser()
17 parser.add_option('-f', '--force', action='store_true')
18 parser.add_option('--touch')
19
mostynb@opera.com9f6c0ea2013-05-29 06:49:11 +090020 options, args = parser.parse_args(argv[1:])
phajdan.jr@chromium.orga15170a2013-01-23 02:57:14 +090021 if len(args) < 2:
22 parser.error('at least two arguments required.')
23
24 target = args[-1]
25 sources = args[:-1]
26 for s in sources:
27 t = os.path.join(target, os.path.basename(s))
28 try:
29 os.symlink(s, t)
30 except OSError, e:
31 if e.errno == errno.EEXIST and options.force:
32 os.remove(t)
33 os.symlink(s, t)
34 else:
35 raise
36
37
38 if options.touch:
39 with open(options.touch, 'w') as f:
40 pass
41
42
43if __name__ == '__main__':
44 sys.exit(Main(sys.argv))