使用python 2&3获取操作系统类型、品牌、版本和内核的模块

py-osinfo的Python项目详细描述


py osinfo应该在没有任何额外程序或库的情况下工作,除了 你的操作系统提供了什么。我们的目标是在每一个操作系统上 python支持。适用于Linux、OS X、Windows、BSD、solaris、cygwin, 还有俳句。

PIP安装

sudo pip安装py osinfo

sudo pip3安装py osinfo

从osinfo导入osinfo

作为脚本运行

$ python osinfo.py
type: Linux
brand: Slackware
release: 14.1
kernel: (3, 13, 0)

作为库运行

import osinfo
os_type, os_brand, os_release, os_kernel = osinfo.get_os_info()

if os_type in osinfo.OSType.linux:
    print("Looks like you're using Linux.")

    if os_kernel < (3, 13, 1):
        print("Your Linux kernel version is too old!")

if os_brand in osinfo.OSBrand.CentOS:
    print("Looks like you're using CentOS.")

if os_release == '99.01':
    print("OMG CentOS from 2099. Can I see the sorce code?")

输出

centos

type: Linux
brand: CentOS
release: 6.5
kernel: (2, 6, 32)

cygwin

type: Cygwin
brand: CYGWIN_NT-6.3
release: 1.7.32
kernel: (1, 7, 32)

crunch bang

type: Linux
brand: CrunchBang
release: 11
kernel: (3, 2, 0)

debian

type: Linux
brand: Debian
release: 7.6
kernel: (3, 2, 0)

fedora 20

type: Linux
brand: Fedora
release: 20

freebsd 10

type: BSD
brand: FreeBSD
release: 10.0

俳句

type: BeOS
brand: Haiku
release: 1
kernel: (1,)

linux薄荷糖

type: Linux
brand: LinuxMint
release: 10.9.4
kernel: (3, 11, 10)

manjaro

type: Linux
brand: Manjaro
release: 0.8.10
kernel: (3, 12, 20)

mac os x

type: MacOS
brand: OSX
release: 10.9.4
kernel: (13, 3, 0)

netbsd

type: BSD
brand: NetBSD
release: 6.1.4

打开印第安纳州

type: Solaris
brand: OpenIndiana
release: 151a8
kernel: (5, 11)

打开SUSE

type: Linux
brand: openSUSE
release: 13.1
kernel: (3, 11, 10)

open sxce

type: Solaris
brand: OpenSXCE
release: pensxce2014.05__illumos20140505
kernel: (5, 11)

pcbsd

type: BSD
brand: FreeBSD
release: 10.0-release-p13

redhat

type: Linux
brand: Redhat
release: 6.5
kernel: (2, 6, 32)

sabayon

type: Linux
brand: Sabayon
release: 5.5
kernel: (2, 6, 37)

scientific Linux

type: Linux
brand: ScientificLinux
release: 6.5
kernel: (2, 6, 32)

ubuntu 14.04

type: Linux
brand: Ubuntu
release: 14.04
kernel: (3, 13, 0)

windows 7

type: Windows
brand: Windows7
release: 6.1.7601
kernel: (6, 1, 7601)

windows 8

type: Windows
brand: Windows8
release: 6.2.9200
kernel: (6, 2, 9200)

windows xp

type: Windows
brand: WindowsXP
release: 5.1.2600
kernel: (5, 1, 2600)

请提交一个拉请求与结果为您最喜爱的操作系统!

错误和更正

如果您怀疑这些信息有任何错误,请报告一个错误。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java SimpleFramework和工厂方法   Java适当地处理异常   java单例类不起作用   java小程序和Swing在eclipse中不显示组件   多个键上的java Redisson FastRemove不起作用   java验证请求正文不等于模式   在Java中从URL读取数据   eche RecyclerView项的java Set自定义字体   string Java如何从Date获取HH:mm:ss   当Java应用程序落后于负载均衡器时,在某些URL上强制使用SSL   使用esapi时发生java错误   java使用流根据第二个列表中的值更新一个列表中的对象   组织。openqa。硒。Java中的NoTouchElementException WebDriver?   从JSON字符串Java创建CSV文件