Completed
Pull Request — develop (#115)
by Wu
01:09
created

repath_lib()   B

Complexity

Conditions 5

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
rs 8.5454
cc 5
1
""" Change install names and ids to reflect changed path
2
"""
3
4
USAGE = """\
5
USAGE: repath_lib_names.py <old_path> <new_path> <lib_fname> [<lib_fname, ...]
6
"""
7
8
from os.path import islink, isfile
9
import sys
10
11
from delocate.tools import (get_install_names, set_install_name,
12
                            get_install_id, set_install_id)
13
14
15
def repath_lib(lib_fname, old_path, new_path):
16
    install_id = get_install_id(lib_fname)
17
    L = len(old_path)
18
    if install_id and install_id.startswith(old_path):
19
        set_install_id(lib_fname, new_path + install_id[L:])
20
    for name in get_install_names(lib_fname):
21
        if name.startswith(old_path):
22
            set_install_name(lib_fname, name, new_path + name[L:])
23
24
25
def main():
26
    if len(sys.argv) < 4:
27
        print(USAGE)
28
        sys.exit(-1)
29
    old_path, new_path = sys.argv[1:3]
30
    for lib_fname in sys.argv[3:]:
31
        if isfile(lib_fname) and not islink(lib_fname):
32
            repath_lib(lib_fname, old_path, new_path)
33
34
35
if __name__ == '__main__':
36
    main()
37