1"""
2Generic framework path manipulation
3"""
4
5__all__ = ['infoForFramework']
6
7# This regexp should find:
8#   \1 - framework location
9#   \2 - framework name
10#   \3 - framework version (optional)
11#
12FRAMEWORK_RE_STR = ur"""(^.*)(?:^|/)(\w+).framework(?:/(?:Versions/([^/]+)/)?\2)?$"""
13FRAMEWORK_RE = None
14
15def infoForFramework(filename):
16    """returns (location, name, version) or None"""
17    global FRAMEWORK_RE
18    if FRAMEWORK_RE is None:
19        import re
20        FRAMEWORK_RE = re.compile(FRAMEWORK_RE_STR)
21    is_framework = FRAMEWORK_RE.findall(filename)
22    if not is_framework:
23        return None
24    return is_framework[-1]
25