本文整理匯總了Python中ubiquity.parted_server.PartedServer.part_entry方法的典型用法代碼示例。如果您正苦於以下問題:Python PartedServer.part_entry方法的具體用法?Python PartedServer.part_entry怎麽用?Python PartedServer.part_entry使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類ubiquity.parted_server.PartedServer
的用法示例。
在下文中一共展示了PartedServer.part_entry方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: grub_options
# 需要導入模塊: from ubiquity.parted_server import PartedServer [as 別名]
# 或者: from ubiquity.parted_server.PartedServer import part_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 part_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 part_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