1

OSが64ビットUbuntuかどうかを確認するpythonicの方法はありますか?

現在、私はそのようにやっています:

import os

def check_is_linux(distro, architecture, err_msg):
    try:
        this_os = os.popen('lsb_release -d').read()
        this_arch = os.popen('uname -a').read()
        assert distro in this_os and architecture in this_arch, err_msg
    except:
        print(err_msg)

def check_is_64bit_ubuntu(err_msg):
    check_is_linux('Ubuntu', 'x86_64', err_msg)
4

2 に答える 2

3

platformモジュールを使用して、ディストリビューションとプロセッサの情報を取得できます。

import platform

def is_linux(distro, architecture):
    if not platform.system() == 'Linux':
        return False

    if platform.linux_distribution()[0].lower() != distro:
        return False

    return platform.processor() == architecture

def is_64bit_ubuntu():
    return is_linux('ubuntu', 'x86_64')

if not is_64bit_ubuntu():
    print(err_msg)
于 2015-08-03T11:19:51.450 に答える
0

モジュールによって提供される機能platform、具体的には platform.architecture および platform.uname を使用します。

于 2015-08-03T11:36:46.193 に答える