1""" 2Generic dylib path manipulation 3""" 4 5import re 6 7__all__ = ['dylib_info'] 8 9DYLIB_RE = re.compile(r"""(?x) 10(?P<location>^.*)(?:^|/) 11(?P<name> 12 (?P<shortname>\w+?) 13 (?:\.(?P<version>[^._]+))? 14 (?:_(?P<suffix>[^._]+))? 15 \.dylib$ 16) 17""") 18 19def dylib_info(filename): 20 """ 21 A dylib name can take one of the following four forms: 22 Location/Name.SomeVersion_Suffix.dylib 23 Location/Name.SomeVersion.dylib 24 Location/Name_Suffix.dylib 25 Location/Name.dylib 26 27 returns None if not found or a mapping equivalent to: 28 dict( 29 location='Location', 30 name='Name.SomeVersion_Suffix.dylib', 31 shortname='Name', 32 version='SomeVersion', 33 suffix='Suffix', 34 ) 35 36 Note that SomeVersion and Suffix are optional and may be None 37 if not present. 38 """ 39 is_dylib = DYLIB_RE.match(filename) 40 if not is_dylib: 41 return None 42 return is_dylib.groupdict() 43