Mozinfo 编辑

Throughout mozmill and other 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 key, values: 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 is 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 processor
  • main: the console_script entry point for mozinfo
  • unknown: 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, 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:99 次

字数:2808

最后编辑:7 年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文