~ubuntu-branches/ubuntu/quantal/enigmail/quantal-security

« back to all changes in this revision

Viewing changes to testing/mozbase/mozrunner/mozrunner/utils.py

  • Committer: Package Import Robot
  • Author(s): Chris Coulson
  • Date: 2013-09-13 16:02:15 UTC
  • mfrom: (0.12.16)
  • Revision ID: package-import@ubuntu.com-20130913160215-u3g8nmwa0pdwagwc
Tags: 2:1.5.2-0ubuntu0.12.10.1
* New upstream release v1.5.2 for Thunderbird 24

* Build enigmail using a stripped down Thunderbird 17 build system, as it's
  now quite difficult to build the way we were doing previously, with the
  latest Firefox build system
* Add debian/patches/no_libxpcom.patch - Don't link against libxpcom, as it
  doesn't exist anymore (but exists in the build system)
* Add debian/patches/use_sdk.patch - Use the SDK version of xpt.py and
  friends
* Drop debian/patches/ipc-pipe_rename.diff (not needed anymore)
* Drop debian/patches/makefile_depth.diff (not needed anymore)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/env python
2
 
 
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/.
6
 
 
7
 
"""
8
 
utility functions for mozrunner
9
 
"""
10
 
 
11
 
__all__ = ['findInPath', 'get_metadata_from_egg']
12
 
 
13
 
import mozinfo
14
 
import os
15
 
import sys
16
 
 
17
 
 
18
 
### python package method metadata by introspection
19
 
try:
20
 
    import pkg_resources
21
 
    def get_metadata_from_egg(module):
22
 
        ret = {}
23
 
        try:
24
 
            dist = pkg_resources.get_distribution(module)
25
 
        except pkg_resources.DistributionNotFound:
26
 
            return {}
27
 
        if dist.has_metadata("PKG-INFO"):
28
 
            key = None
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():
34
 
                        value += '\n' + line
35
 
                        continue
36
 
                    else:
37
 
                        key = key.strip()
38
 
                        value = value.strip()
39
 
                        ret[key] = value
40
 
 
41
 
                key, value = line.split(':', 1)
42
 
                key = key.strip()
43
 
                value = value.strip()
44
 
                ret[key] = value
45
 
        if dist.has_metadata("requires.txt"):
46
 
            ret["Dependencies"] = "\n" + dist.get_metadata("requires.txt")
47
 
        return ret
48
 
except ImportError:
49
 
    # package resources not avaialable
50
 
    def get_metadata_from_egg(module):
51
 
        return {}
52
 
 
53
 
 
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)
57
 
    for dir in dirs:
58
 
        if os.path.isfile(os.path.join(dir, fileName)):
59
 
            return os.path.join(dir, fileName)
60
 
        if mozinfo.isWin:
61
 
            if os.path.isfile(os.path.join(dir, fileName + ".exe")):
62
 
                return os.path.join(dir, fileName + ".exe")
63
 
 
64
 
if __name__ == '__main__':
65
 
    for i in sys.argv[1:]:
66
 
        print findInPath(i)