3
# This Source Code Form is subject to the terms of the Mozilla Public
4
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
5
# You can obtain one at http://mozilla.org/MPL/2.0/.
8
utility functions for mozrunner
11
__all__ = ['findInPath', 'get_metadata_from_egg']
18
### python package method metadata by introspection
21
def get_metadata_from_egg(module):
24
dist = pkg_resources.get_distribution(module)
25
except pkg_resources.DistributionNotFound:
27
if dist.has_metadata("PKG-INFO"):
29
for line in dist.get_metadata("PKG-INFO").splitlines():
30
# see http://www.python.org/dev/peps/pep-0314/
31
if key == 'Description':
32
# descriptions can be long
33
if not line or line[0].isspace():
41
key, value = line.split(':', 1)
45
if dist.has_metadata("requires.txt"):
46
ret["Dependencies"] = "\n" + dist.get_metadata("requires.txt")
49
# package resources not avaialable
50
def get_metadata_from_egg(module):
54
def findInPath(fileName, path=os.environ['PATH']):
55
"""python equivalent of which; should really be in the stdlib"""
56
dirs = path.split(os.pathsep)
58
if os.path.isfile(os.path.join(dir, fileName)):
59
return os.path.join(dir, fileName)
61
if os.path.isfile(os.path.join(dir, fileName + ".exe")):
62
return os.path.join(dir, fileName + ".exe")
64
if __name__ == '__main__':
65
for i in sys.argv[1:]: