campies.py 文件源码

python
阅读 49 收藏 0 点赞 0 评论 0

项目:campies 作者: fgimian 项目源码 文件源码
def get_model():
    """Obtain's the user's Mac model"""

    # Obtain and parse the output of the system profiler command
    try:
        hardware_type_xml = run([
            'system_profiler', 'SPHardwareDataType', '-xml'
        ])
    except CampiesSubprocessError:
        raise CampiesError(
            'Unable to run the command required to obtain the model'
        )
    try:
        hardware_type = loads_plist(hardware_type_xml)
    except xml.parsers.expat.ExpatError:
        raise CampiesError(
            'Unable to parse hardware XML to obtain the model'
        )

    # We now need to grab the machine model which is buried in the data
    # [{
    #   '_items': [
    #     {
    #       '_name': 'hardware_overview',
    #       'machine_model': 'MacBookPro11,5',
    #       'machine_name': 'MacBook Pro',
    try:
        model = hardware_type[0]['_items'][0]['machine_model']
    except IndexError:
        raise CampiesError(
            'Unable to find model in the hardware XML'
        )

    return model
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号