Debian Codegraph @

meson/install-file.py

raw symbols SCIP
1 #!/usr/bin/env python3
2
3 # Copies (installs) file(s) into a new location.
4 #
5 # Usage:
6 # install-file.py SOURCE... DESTINATION
7 #
8 # Copy SOURCE file as DESTINATION file if DESTINATION ends with
9 # a filename extension, or copy SOURCE file(s) into DESTINATION
10 # directory.
11 #
12 # All leading components of DESTINATION path are created if they
13 # don't exist. Paths can contain environment variables. If SOURCE
14 # is a symlink, a new symlink in created instead of installing
15 # the file the link points to.
16
17 import sys
18 import os
19 import shutil
20
21 source = sys.argv[1:-1]
22 dest = os.path.expandvars(sys.argv[-1])
23
24 if not os.path.splitext(dest)[1]:
25 dest_dir = dest
26 else:
27 if len(source) == 1:
28 dest_dir = os.path.dirname(dest)
29 else:
30 raise Exception("Too many source files")
31
32 os.makedirs(dest_dir, exist_ok=True)
33
34 for src in source:
35 try:
36 shutil.copy(src, dest, follow_symlinks=False)
37 except FileExistsError:
38 if os.path.islink(dest):
39 os.remove(dest)
40 shutil.copy(src, dest, follow_symlinks=False)