1 | n/a | """ |
---|
2 | n/a | Generic framework path manipulation |
---|
3 | n/a | """ |
---|
4 | n/a | |
---|
5 | n/a | import re |
---|
6 | n/a | |
---|
7 | n/a | __all__ = ['framework_info'] |
---|
8 | n/a | |
---|
9 | n/a | STRICT_FRAMEWORK_RE = re.compile(r"""(?x) |
---|
10 | n/a | (?P<location>^.*)(?:^|/) |
---|
11 | n/a | (?P<name> |
---|
12 | n/a | (?P<shortname>\w+).framework/ |
---|
13 | n/a | (?:Versions/(?P<version>[^/]+)/)? |
---|
14 | n/a | (?P=shortname) |
---|
15 | n/a | (?:_(?P<suffix>[^_]+))? |
---|
16 | n/a | )$ |
---|
17 | n/a | """) |
---|
18 | n/a | |
---|
19 | n/a | def framework_info(filename): |
---|
20 | n/a | """ |
---|
21 | n/a | A framework name can take one of the following four forms: |
---|
22 | n/a | Location/Name.framework/Versions/SomeVersion/Name_Suffix |
---|
23 | n/a | Location/Name.framework/Versions/SomeVersion/Name |
---|
24 | n/a | Location/Name.framework/Name_Suffix |
---|
25 | n/a | Location/Name.framework/Name |
---|
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.framework/Versions/SomeVersion/Name_Suffix', |
---|
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_framework = STRICT_FRAMEWORK_RE.match(filename) |
---|
40 | n/a | if not is_framework: |
---|
41 | n/a | return None |
---|
42 | n/a | return is_framework.groupdict() |
---|
43 | n/a | |
---|
44 | n/a | def test_framework_info(): |
---|
45 | n/a | def d(location=None, name=None, shortname=None, version=None, suffix=None): |
---|
46 | n/a | return dict( |
---|
47 | n/a | location=location, |
---|
48 | n/a | name=name, |
---|
49 | n/a | shortname=shortname, |
---|
50 | n/a | version=version, |
---|
51 | n/a | suffix=suffix |
---|
52 | n/a | ) |
---|
53 | n/a | assert framework_info('completely/invalid') is None |
---|
54 | n/a | assert framework_info('completely/invalid/_debug') is None |
---|
55 | n/a | assert framework_info('P/F.framework') is None |
---|
56 | n/a | assert framework_info('P/F.framework/_debug') is None |
---|
57 | n/a | assert framework_info('P/F.framework/F') == d('P', 'F.framework/F', 'F') |
---|
58 | n/a | assert framework_info('P/F.framework/F_debug') == d('P', 'F.framework/F_debug', 'F', suffix='debug') |
---|
59 | n/a | assert framework_info('P/F.framework/Versions') is None |
---|
60 | n/a | assert framework_info('P/F.framework/Versions/A') is None |
---|
61 | n/a | assert framework_info('P/F.framework/Versions/A/F') == d('P', 'F.framework/Versions/A/F', 'F', 'A') |
---|
62 | n/a | assert framework_info('P/F.framework/Versions/A/F_debug') == d('P', 'F.framework/Versions/A/F_debug', 'F', 'A', 'debug') |
---|
63 | n/a | |
---|
64 | n/a | if __name__ == '__main__': |
---|
65 | n/a | test_framework_info() |
---|