summaryrefslogtreecommitdiffstats
path: root/python/macholib/macholib/dylib.py
diff options
context:
space:
mode:
Diffstat (limited to 'python/macholib/macholib/dylib.py')
-rw-r--r--python/macholib/macholib/dylib.py42
1 files changed, 42 insertions, 0 deletions
diff --git a/python/macholib/macholib/dylib.py b/python/macholib/macholib/dylib.py
new file mode 100644
index 000000000..cea6a95c3
--- /dev/null
+++ b/python/macholib/macholib/dylib.py
@@ -0,0 +1,42 @@
+"""
+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()