本文整理汇总了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
示例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
示例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