-
Notifications
You must be signed in to change notification settings - Fork 0
/
install_links.py
executable file
·41 lines (31 loc) · 1.04 KB
/
install_links.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env python3
"""Create a symlink or a copy of an installed file."""
import argparse
import os
import shutil
def main():
parser = argparse.ArgumentParser()
parser.add_argument('bindir')
parser.add_argument('source')
parser.add_argument('dest', nargs='+')
parser.add_argument('--use-links', action='store_true')
args = parser.parse_args()
os.chdir(os.environ['MESON_INSTALL_DESTDIR_PREFIX'])
os.chdir(args.bindir)
# Windows doesn't really use symlinks, just copy in that case. Windows
# before vista (xp) doesn't have symlinks at all.
if args.use_links:
func = os.symlink
verb = 'Linking'
else:
func = shutil.copy
verb = 'Copying'
# at least os.symlink will fail if the destination already exists, just
# remove the dest if it already exists.
for dest in args.dest:
if os.path.exists(dest):
os.unlink(dest)
func(args.source, dest)
print('{} {} to {}'.format(verb, args.source, dest))
if __name__ == "__main__":
main()