1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 __author__ = "Michael Cohen <scudette@gmail.com>"
23 """Finds resources which are normally bundled with Rekall.
24
25 Rekall is shipped both as a python package and as a pyinstaller
26 application. This module is the interface between the two.
27 """
28
29 import os
30 import sys
31
32 import pkg_resources
33
34
35 -def get_resource(filename, package="rekall-core", prefix="resources"):
36 """Use the pkg_resources API to extract resources.
37
38 This will extract into a temporary file in case the egg is compressed.
39
40 Args:
41 package: name of the package (e.g. rekall-core, rekall-gui).
42 filename: The filename inside the package.
43 prefix: The sub-directory in the source distribution which contains the
44 resource.
45
46 Returns:
47 A path to the actual filename.
48
49 """
50 target = _get_pkg_resource(filename, package, prefix)
51 if target and os.access(target, os.R_OK):
52 return target
53
54
55
56
57
58 target = os.path.join(sys.prefix, prefix, filename)
59 if target and os.access(target, os.R_OK):
60 return target
61
62 raise IOError("Unable to find resource %s" % filename)
63
64
66 """Query pkg_resources for the location of the filename."""
67 requirement = pkg_resources.Requirement.parse(package)
68 target = os.path.join(prefix, filename)
69 try:
70 return pkg_resources.resource_filename(requirement, target)
71 except pkg_resources.DistributionNotFound:
72
73
74 pkg_resources.working_set = pkg_resources.WorkingSet()
75 try:
76 return pkg_resources.resource_filename(requirement, target)
77 except pkg_resources.DistributionNotFound:
78 return None
79