File: dylib.py

package info (click to toggle)
python-macholib 1.16.2%2Bds0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 520 kB
  • sloc: python: 4,279; makefile: 126; sh: 10
file content (45 lines) | stat: -rw-r--r-- 969 bytes parent folder | download | duplicates (4)
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
42
43
44
45
"""
Generic dylib path manipulation
"""

import re

__all__ = ["dylib_info"]

_DYLIB_RE = re.compile(
    r"""(?x)
(?P<location>^.*)(?:^|/)
(?P<name>
    (?P<shortname>\w+?)
    (?:\.(?P<version>[^._]+))?
    (?:_(?P<suffix>[^._]+))?
    \.dylib$
)
"""
)


def dylib_info(filename):
    """
    A dylib name can take one of the following four forms:
        Location/Name.SomeVersion_Suffix.dylib
        Location/Name.SomeVersion.dylib
        Location/Name_Suffix.dylib
        Location/Name.dylib

    returns None if not found or a mapping equivalent to:
        dict(
            location='Location',
            name='Name.SomeVersion_Suffix.dylib',
            shortname='Name',
            version='SomeVersion',
            suffix='Suffix',
        )

    Note that SomeVersion and Suffix are optional and may be None
    if not present.
    """
    is_dylib = _DYLIB_RE.match(filename)
    if not is_dylib:
        return None
    return is_dylib.groupdict()