当前位置: 首页>>代码示例>>Python>>正文


Python PartedServer.device_entry方法代码示例

本文整理汇总了Python中ubiquity.parted_server.PartedServer.device_entry方法的典型用法代码示例。如果您正苦于以下问题:Python PartedServer.device_entry方法的具体用法?Python PartedServer.device_entry怎么用?Python PartedServer.device_entry使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ubiquity.parted_server.PartedServer的用法示例。


在下文中一共展示了PartedServer.device_entry方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: grub_options

# 需要导入模块: from ubiquity.parted_server import PartedServer [as 别名]
# 或者: from ubiquity.parted_server.PartedServer import device_entry [as 别名]
def grub_options():
    """ Generates a list of suitable targets for grub-installer
        @return empty list or a list of ['/dev/sda1','Ubuntu Hardy 8.04'] """
    from ubiquity.parted_server import PartedServer

    l = []
    try:
        oslist = {}
        subp = subprocess.Popen(['os-prober'], stdout=subprocess.PIPE,
            stderr=subprocess.PIPE)
        result = subp.communicate()[0].splitlines()
        for res in result:
            res = res.split(':')
            oslist[res[0]] = res[1]
        p = PartedServer()
        for disk in p.disks():
            p.select_disk(disk)
            dev = ''
            mod = ''
            size = ''
            try:
                fp = open(p.device_entry('model'))
                mod = fp.readline()
                fp.close()
                fp = open(p.device_entry('device'))
                dev = fp.readline()
                fp.close()
                fp = open(p.device_entry('size'))
                size = fp.readline()
                fp.close()
            finally:
                if fp:
                    fp.close()
            if dev and mod:
                if size.isdigit():
                    size = format_size(int(size))
                    l.append([dev, '%s (%s)' % (mod, size)])
                else:
                    l.append([dev, mod])
            for part in p.partitions():
                ostype = ''
                if part[4] == 'linux-swap':
                    continue
                if part[4] == 'free':
                    continue
                if os.path.exists(p.part_entry(part[1], 'format')):
                    # Don't bother looking for an OS type.
                    pass
                elif part[5] in oslist.keys():
                    ostype = oslist[part[5]]
                l.append([part[5], ostype])
    except:
        import traceback
        for line in traceback.format_exc().split('\n'):
            syslog.syslog(syslog.LOG_ERR, line)
    return l
开发者ID:guadalinexv9-team,项目名称:guadalinexv9-ubiquity-conf,代码行数:58,代码来源:misc.py

示例2: grub_options

# 需要导入模块: from ubiquity.parted_server import PartedServer [as 别名]
# 或者: from ubiquity.parted_server.PartedServer import device_entry [as 别名]
def grub_options():
    """ Generates a list of suitable targets for grub-installer
        @return empty list or a list of ['/dev/sda1','Ubuntu Hardy 8.04'] """
    from ubiquity.parted_server import PartedServer

    l = []
    try:
        oslist = {}
        subp = subprocess.Popen(["os-prober"], stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
        result = subp.communicate()[0].splitlines()
        for res in result:
            res = res.split(":")
            oslist[res[0]] = res[1]
        p = PartedServer()
        for disk in p.disks():
            p.select_disk(disk)
            with open(p.device_entry("model")) as fp:
                mod = fp.readline()
            with open(p.device_entry("device")) as fp:
                dev = fp.readline()
            with open(p.device_entry("size")) as fp:
                size = fp.readline()
            if dev and mod:
                if size.isdigit():
                    size = format_size(int(size))
                    l.append([dev, "%s (%s)" % (mod, size)])
                else:
                    l.append([dev, mod])
            for part in p.partitions():
                ostype = ""
                if part[4] == "linux-swap":
                    continue
                if part[4] == "free":
                    continue
                if os.path.exists(p.part_entry(part[1], "format")):
                    # Don't bother looking for an OS type.
                    pass
                elif part[5] in oslist.keys():
                    ostype = oslist[part[5]]
                l.append([part[5], ostype])
    except:
        import traceback

        for line in traceback.format_exc().split("\n"):
            syslog.syslog(syslog.LOG_ERR, line)
    return l
开发者ID:Astalaseven,项目名称:Cnchi,代码行数:48,代码来源:misc.py

示例3: grub_options

# 需要导入模块: from ubiquity.parted_server import PartedServer [as 别名]
# 或者: from ubiquity.parted_server.PartedServer import device_entry [as 别名]
def grub_options():
    """ Generates a list of suitable targets for grub-installer
        @return empty list or a list of ['/dev/sda1','Ubuntu Hardy 8.04'] """
    os.seteuid(0)
    l = []
    oslist = {}
    subp = subprocess.Popen(['os-prober'], stdout=subprocess.PIPE,
        stderr=subprocess.PIPE)
    result = subp.communicate()[0].splitlines()
    for res in result:
        res = res.split(':')
        oslist[res[0]] = res[1]
    p = PartedServer()
    for disk in p.disks():
        p.select_disk(disk)
        dev = ''
        mod = ''
        size = ''
        try:
            fp = open(p.device_entry('model'))
            mod = fp.readline()
            fp.close()
            fp = open(p.device_entry('device'))
            dev = fp.readline()
            fp = open(p.device_entry('size'))
            size = fp.readline()
        finally:
            fp.close()
        if dev and mod:
            if size.isdigit():
                size = format_size(int(size))
                l.append([dev, '%s (%s)' % (mod, size)])
            else:
                l.append([dev, mod])
        for part in p.partitions():
            ostype = ''
            if part[4] == 'xfs' or part[4] == 'linux-swap':
                continue
            if os.path.exists(p.part_entry(part[1], 'format')):
                pass
            elif part[5] in oslist.keys():
                ostype = oslist[part[5]]
            l.append([part[5], ostype])
    drop_privileges()
    return l
开发者ID:guadalinex-archive,项目名称:guadalinex-v5,代码行数:47,代码来源:summary.py


注:本文中的ubiquity.parted_server.PartedServer.device_entry方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。