1 | n/a | """ |
---|
2 | n/a | Generic dylib path manipulation |
---|
3 | n/a | """ |
---|
4 | n/a | |
---|
5 | n/a | import re |
---|
6 | n/a | |
---|
7 | n/a | __all__ = ['dylib_info'] |
---|
8 | n/a | |
---|
9 | n/a | DYLIB_RE = re.compile(r"""(?x) |
---|
10 | n/a | (?P<location>^.*)(?:^|/) |
---|
11 | n/a | (?P<name> |
---|
12 | n/a | (?P<shortname>\w+?) |
---|
13 | n/a | (?:\.(?P<version>[^._]+))? |
---|
14 | n/a | (?:_(?P<suffix>[^._]+))? |
---|
15 | n/a | \.dylib$ |
---|
16 | n/a | ) |
---|
17 | n/a | """) |
---|
18 | n/a | |
---|
19 | n/a | def dylib_info(filename): |
---|
20 | n/a | """ |
---|
21 | n/a | A dylib name can take one of the following four forms: |
---|
22 | n/a | Location/Name.SomeVersion_Suffix.dylib |
---|
23 | n/a | Location/Name.SomeVersion.dylib |
---|
24 | n/a | Location/Name_Suffix.dylib |
---|
25 | n/a | Location/Name.dylib |
---|
26 | n/a | |
---|
27 | n/a | returns None if not found or a mapping equivalent to: |
---|
28 | n/a | dict( |
---|
29 | n/a | location='Location', |
---|
30 | n/a | name='Name.SomeVersion_Suffix.dylib', |
---|
31 | n/a | shortname='Name', |
---|
32 | n/a | version='SomeVersion', |
---|
33 | n/a | suffix='Suffix', |
---|
34 | n/a | ) |
---|
35 | n/a | |
---|
36 | n/a | Note that SomeVersion and Suffix are optional and may be None |
---|
37 | n/a | if not present. |
---|
38 | n/a | """ |
---|
39 | n/a | is_dylib = DYLIB_RE.match(filename) |
---|
40 | n/a | if not is_dylib: |
---|
41 | n/a | return None |
---|
42 | n/a | return is_dylib.groupdict() |
---|
43 | n/a | |
---|
44 | n/a | |
---|
45 | n/a | def test_dylib_info(): |
---|
46 | n/a | def d(location=None, name=None, shortname=None, version=None, suffix=None): |
---|
47 | n/a | return dict( |
---|
48 | n/a | location=location, |
---|
49 | n/a | name=name, |
---|
50 | n/a | shortname=shortname, |
---|
51 | n/a | version=version, |
---|
52 | n/a | suffix=suffix |
---|
53 | n/a | ) |
---|
54 | n/a | assert dylib_info('completely/invalid') is None |
---|
55 | n/a | assert dylib_info('completely/invalide_debug') is None |
---|
56 | n/a | assert dylib_info('P/Foo.dylib') == d('P', 'Foo.dylib', 'Foo') |
---|
57 | n/a | assert dylib_info('P/Foo_debug.dylib') == d('P', 'Foo_debug.dylib', 'Foo', suffix='debug') |
---|
58 | n/a | assert dylib_info('P/Foo.A.dylib') == d('P', 'Foo.A.dylib', 'Foo', 'A') |
---|
59 | n/a | assert dylib_info('P/Foo_debug.A.dylib') == d('P', 'Foo_debug.A.dylib', 'Foo_debug', 'A') |
---|
60 | n/a | assert dylib_info('P/Foo.A_debug.dylib') == d('P', 'Foo.A_debug.dylib', 'Foo', 'A', 'debug') |
---|
61 | n/a | |
---|
62 | n/a | if __name__ == '__main__': |
---|
63 | n/a | test_dylib_info() |
---|