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

« back to all changes in this revision

Viewing changes to mozilla/testing/mozbase/mozinfo/mozinfo/mozinfo.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
file for interface to transform introspected system information to a format
 
9
pallatable to Mozilla
 
10
 
 
11
Information:
 
12
- os : what operating system ['win', 'mac', 'linux', ...]
 
13
- bits : 32 or 64
 
14
- processor : processor architecture ['x86', 'x86_64', 'ppc', ...]
 
15
- version : operating system version string
 
16
 
 
17
For windows, the service pack information is also included
 
18
"""
 
19
 
 
20
# TODO: it might be a good idea of adding a system name (e.g. 'Ubuntu' for
 
21
# linux) to the information; I certainly wouldn't want anyone parsing this
 
22
# information and having behaviour depend on it
 
23
 
 
24
import os
 
25
import platform
 
26
import re
 
27
import sys
 
28
 
 
29
# keep a copy of the os module since updating globals overrides this
 
30
_os = os
 
31
 
 
32
class unknown(object):
 
33
    """marker class for unknown information"""
 
34
    def __nonzero__(self):
 
35
        return False
 
36
    def __str__(self):
 
37
        return 'UNKNOWN'
 
38
unknown = unknown() # singleton
 
39
 
 
40
# get system information
 
41
info = {'os': unknown,
 
42
        'processor': unknown,
 
43
        'version': unknown,
 
44
        'bits': unknown }
 
45
(system, node, release, version, machine, processor) = platform.uname()
 
46
(bits, linkage) = platform.architecture()
 
47
 
 
48
# get os information and related data
 
49
if system in ["Microsoft", "Windows"]:
 
50
    info['os'] = 'win'
 
51
    # There is a Python bug on Windows to determine platform values
 
52
    # http://bugs.python.org/issue7860
 
53
    if "PROCESSOR_ARCHITEW6432" in os.environ:
 
54
        processor = os.environ.get("PROCESSOR_ARCHITEW6432", processor)
 
55
    else:
 
56
        processor = os.environ.get('PROCESSOR_ARCHITECTURE', processor)
 
57
        system = os.environ.get("OS", system).replace('_', ' ')
 
58
        service_pack = os.sys.getwindowsversion()[4]
 
59
        info['service_pack'] = service_pack
 
60
elif system == "Linux":
 
61
    (distro, version, codename) = platform.dist()
 
62
    version = "%s %s" % (distro, version)
 
63
    if not processor:
 
64
        processor = machine
 
65
    info['os'] = 'linux'
 
66
elif system == "Darwin":
 
67
    (release, versioninfo, machine) = platform.mac_ver()
 
68
    version = "OS X %s" % release
 
69
    info['os'] = 'mac'
 
70
elif sys.platform in ('solaris', 'sunos5'):
 
71
    info['os'] = 'unix'
 
72
    version = sys.platform
 
73
info['version'] = version # os version
 
74
 
 
75
# processor type and bits
 
76
if processor in ["i386", "i686"]:
 
77
    if bits == "32bit":
 
78
        processor = "x86"
 
79
    elif bits == "64bit":
 
80
        processor = "x86_64"
 
81
elif processor == "AMD64":
 
82
    bits = "64bit"
 
83
    processor = "x86_64"
 
84
elif processor == "Power Macintosh":
 
85
    processor = "ppc"
 
86
bits = re.search('(\d+)bit', bits).group(1)
 
87
info.update({'processor': processor,
 
88
             'bits': int(bits),
 
89
            })
 
90
 
 
91
# standard value of choices, for easy inspection
 
92
choices = {'os': ['linux', 'win', 'mac', 'unix'],
 
93
           'bits': [32, 64],
 
94
           'processor': ['x86', 'x86_64', 'ppc']}
 
95
 
 
96
 
 
97
def sanitize(info):
 
98
    """Do some sanitization of input values, primarily
 
99
    to handle universal Mac builds."""
 
100
    if "processor" in info and info["processor"] == "universal-x86-x86_64":
 
101
        # If we're running on OS X 10.6 or newer, assume 64-bit
 
102
        if release[:4] >= "10.6": # Note this is a string comparison
 
103
            info["processor"] = "x86_64"
 
104
            info["bits"] = 64
 
105
        else:
 
106
            info["processor"] = "x86"
 
107
            info["bits"] = 32
 
108
 
 
109
# method for updating information
 
110
def update(new_info):
 
111
    """update the info"""
 
112
    info.update(new_info)
 
113
    sanitize(info)
 
114
    globals().update(info)
 
115
 
 
116
    # convenience data for os access
 
117
    for os_name in choices['os']:
 
118
        globals()['is' + os_name.title()] = info['os'] == os_name
 
119
    # unix is special
 
120
    if isLinux:
 
121
        globals()['isUnix'] = True
 
122
 
 
123
update({})
 
124
 
 
125
# exports
 
126
__all__ = info.keys()
 
127
__all__ += ['is' + os_name.title() for os_name in choices['os']]
 
128
__all__ += ['info', 'unknown', 'main', 'choices', 'update']
 
129
 
 
130
 
 
131
def main(args=None):
 
132
 
 
133
    # parse the command line
 
134
    from optparse import OptionParser
 
135
    parser = OptionParser(description=__doc__)
 
136
    for key in choices:
 
137
        parser.add_option('--%s' % key, dest=key,
 
138
                          action='store_true', default=False,
 
139
                          help="display choices for %s" % key)
 
140
    options, args = parser.parse_args()
 
141
 
 
142
    # args are JSON blobs to override info
 
143
    if args:
 
144
        try:
 
145
            from json import loads
 
146
        except ImportError:
 
147
            try:
 
148
                from simplejson import loads
 
149
            except ImportError:
 
150
                def loads(string):
 
151
                    """*really* simple json; will not work with unicode"""
 
152
                    return eval(string, {'true': True, 'false': False, 'null': None})
 
153
        for arg in args:
 
154
            if _os.path.exists(arg):
 
155
                string = file(arg).read()
 
156
            else:
 
157
                string = arg
 
158
            update(loads(string))
 
159
 
 
160
    # print out choices if requested
 
161
    flag = False
 
162
    for key, value in options.__dict__.items():
 
163
        if value is True:
 
164
            print '%s choices: %s' % (key, ' '.join([str(choice)
 
165
                                                     for choice in choices[key]]))
 
166
            flag = True
 
167
    if flag: return
 
168
 
 
169
    # otherwise, print out all info
 
170
    for key, value in info.items():
 
171
        print '%s: %s' % (key, value)
 
172
 
 
173
if __name__ == '__main__':
 
174
    main()