mozinfo
— Get system information
Throughout Mozilla python code, checking the underlying platform is done in many different ways. The various checks needed lead to a lot of copy+pasting, leaving the reader to wonder….is this specific check necessary for (e.g.) an operating system? Because information is not consolidated, checks are not done consistently, nor is it defined what we are checking for.
mozinfo
proposes to solve this problem. mozinfo is a bridge interface,
making the underlying (complex) plethora of OS and architecture
combinations conform to a subset of values of relevance to
Mozilla software. The current implementation exposes relevant keys and
values such as: os
, version
, bits
, and processor
. Additionally, the
service pack in use is available on the windows platform.
API Usage
mozinfo is a python package. Downloading the software and running
python setup.py develop
will allow you to do import mozinfo
from python.
mozinfo.py
is the only file contained in this package,
so if you need a single-file solution, you can just download or call
this file through the web.
The top level attributes (os
, version
, bits
, processor
) are
available as module globals:
if mozinfo.os == 'win': ...
In addition, mozinfo exports a dictionary, mozinfo.info
, that
contain these values. mozinfo also exports:
choices
: a dictionary of possible values for os, bits, and processormain
: the console_script entry point for mozinfounknown
: a singleton denoting a value that cannot be determined
unknown
has the string representation "UNKNOWN"
.
unknown
will evaluate as False
in python:
if not mozinfo.os: ... # unknown!
Command Line Usage
mozinfo comes with a command line program, mozinfo
which may be used to
diagnose one’s current system.
Example output:
os: linux
version: Ubuntu 10.10
bits: 32
processor: x86
Three of these fields, os, bits, and processor, have a finite set of
choices. You may display the value of these choices using
mozinfo --os
, mozinfo --bits
, and mozinfo --processor
.
mozinfo --help
documents command-line usage.
interface to transform introspected system information to a format palatable to Mozilla
Module variables:
- mozinfo.bits
32 or 64
- mozinfo.isLinux
Returns
True
if the operating system is Linux
- mozinfo.isMac
Returns
True
if the operating system is Mac
- mozinfo.isWin
Returns
True
if the operating system is Windows
- mozinfo.os
Operating system [
'win'
,'mac'
,'linux'
, …]
- mozinfo.processor
Processor architecture [
'x86'
,'x86_64'
,'aarch64'
, …]
- mozinfo.version
Operating system version string. For windows, the service pack information is also included
- class mozinfo.StringVersion(vstring)
A string version that can be compared with comparison operators.
- mozinfo.find_and_update_from_json(*dirs, **kwargs)
Find a mozinfo.json file, load it, and update global symbol table.
This method will first check the relevant objdir directory for the necessary mozinfo.json file, if the current script is being run from a Mozilla objdir.
If the objdir directory did not supply the necessary data, this method will then look for the required mozinfo.json file from the provided tuple of directories.
If file is found, the global symbols table is updated via a helper method.
If no valid files are found, this method no-ops unless the raise_exception kwargs is provided with explicit boolean value of True.
- Parameters:
dirs (tuple) – Directories in which to look for the file.
kwargs (dict) – optional values: raise_exception: if True, exceptions are raised. False by default.
- Returns:
None: default behavior if mozinfo.json cannot be found. json_path: string representation of mozinfo.json path.
- Raises:
IOError: if raise_exception is True and file is not found.
- mozinfo.update(new_info)
Update the info.
- Parameters:
new_info – Either a dict containing the new info or a path/url to a json file containing the new info.