本文整理汇总了Python中show_message.error函数的典型用法代码示例。如果您正苦于以下问题:Python error函数的具体用法?Python error怎么用?Python error使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了error函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: check_all
def check_all(self):
""" Check that all requirements are meet """
path = "/var/tmp/.cnchi_partitioning_completed"
if os.path.exists(path):
show.error(_("You must reboot before retrying again."))
return False
has_internet = misc.has_connection()
self.prepare_network_connection.set_state(has_internet)
on_power = not self.on_battery()
self.prepare_power_source.set_state(on_power)
space = self.has_enough_space()
self.prepare_enough_space.set_state(space)
if has_internet:
updated = self.is_updated()
else:
updated = False
self.updated.set_state(updated)
if self.checks_are_optional:
return True
if has_internet and space:
return True
return False
示例2: download
def download(self, name, md5):
url = _url_prefix + name
response = ""
try:
request = urlopen(url)
txt = request.read()
#.decode('utf-8')
except urllib.error.HTTPError as e:
logging.exception('Unable to get %s - HTTPError = %s' % (name, e.reason))
return False
except urllib.error.URLError as e:
logging.exception('Unable to get %s - URLError = %s' % (name, e.reason))
return False
except httplib.error.HTTPException as e:
logging.exception('Unable to get %s - HTTPException' % name)
return False
except Exception as e:
import traceback
logging.exception('Unable to get %s - Exception = %s' % (name, traceback.format_exc()))
return False
web_md5 = self.get_md5(txt)
if web_md5 != md5:
txt = "Checksum error in %s. Download aborted" % name
logging.error(txt)
show.error(txt)
return False
new_name = os.path.join(_base_dir, name + "." + self.web_version.replace(".", "_"))
with open(new_name, "wb") as f:
f.write(txt)
return True
示例3: do_activate
def do_activate(self):
""" Override the 'activate' signal of GLib.Application. """
try:
import main_window
except ImportError as err:
msg = "Cannot create DSGos_Installer main window: {0}".format(err)
logging.error(msg)
sys.exit(1)
# Check if we have administrative privileges
if os.getuid() != 0:
msg = _("This installer must be run with administrative privileges, " "and cannot continue without them.")
show.error(None, msg)
return
# Check if we're already running
if self.already_running():
msg = _(
"You cannot run two instances of this installer.\n\n"
"If you are sure that the installer is not already running\n"
"you can run this installer using the --force option\n"
"or you can manually delete the offending file.\n\n"
"Offending file: '{0}'"
).format(self.TMP_RUNNING)
show.error(None, msg)
return
window = main_window.MainWindow(self, cmd_line)
self.add_window(window)
window.show()
with open(self.TMP_RUNNING, "w") as tmp_file:
tmp_file.write("DSGos_Installer {0}\n{1}\n".format(info.DSGos_Installer_VERSION, os.getpid()))
示例4: fill_choose_partition_combo
def fill_choose_partition_combo(self):
self.choose_partition_combo.remove_all()
devices = []
for device in sorted(self.oses.keys()):
# if "Swap" not in self.oses[device]:
if "windows" in self.oses[device].lower():
devices.append(device)
if len(devices) > 1:
new_device_found = False
for device in sorted(devices):
if self.get_new_device(device):
new_device_found = True
line = "{0} ({1})".format(self.oses[device], device)
self.choose_partition_combo.append_text(line)
self.select_first_combobox_item(self.choose_partition_combo)
self.show_all()
if not new_device_found:
txt = _("Can't find any spare partition number.\nAlongside installation can't continue.")
self.choose_partition_label.hide()
self.choose_partition_combo.hide()
self.label.set_markup(txt)
show.error(self.get_toplevel(), txt)
elif len(devices) == 1:
self.set_resize_widget(devices[0])
self.show_all()
self.choose_partition_label.hide()
self.choose_partition_combo.hide()
else:
logging.warning(_("Can't find any installed OS!"))
示例5: create_partition
def create_partition(diskob, part_type, geom):
# A lot of this is similar to Anaconda, but customized to fit our needs
nstart = geom.start
nend = geom.end
if nstart < 2048:
nstart = 2048
# Just in case you try to create partition larger than disk.
# This case should be caught in the frontend!
# Never let user specify a length exceeding the free space.
if nend > diskob.device.length - 1:
nend = diskob.device.length - 1
nalign = diskob.partitionAlignment
if not nalign.isAligned(geom, nstart):
nstart = nalign.alignNearest(geom, nstart)
if not nalign.isAligned(geom, nend):
nend = nalign.alignDown(geom, nend)
if part_type == 1:
nstart = nstart + nalign.grainSize
mingeom = parted.Geometry(device=diskob.device, start=nstart, end=nend - 1)
maxgeom = parted.Geometry(device=diskob.device, start=nstart, end=nend)
if diskob.maxPartitionLength < maxgeom.length:
txt = _("Partition is too large!")
logging.error(txt)
show.error(None, txt)
return None
else:
npartition = parted.Partition(disk=diskob, type=part_type, geometry=maxgeom)
nconstraint = parted.Constraint(minGeom=mingeom, maxGeom=maxgeom)
diskob.addPartition(partition=npartition, constraint=nconstraint)
return npartition
示例6: start_installation
def start_installation(self):
# Alongside method shrinks selected partition
# and creates root and swap partition in the available space
if self.is_room_available() is False:
return
partition_path = self.row[0]
otherOS = self.row[1]
fs_type = self.row[2]
# what if path is sda10 (two digits) ? this is wrong
device_path = self.row[0][:-1]
#re.search(r'\d+$', self.row[0])
new_size = self.new_size
# first, shrink filesystem
res = fs.resize(partition_path, fs_type, new_size)
if res:
# destroy original partition and create a new resized one
pm.split_partition(device_path, partition_path, new_size)
else:
txt = _("Can't shrink %s(%s) filesystem") % (otherOS, fs_type)
logging.error(txt)
show.error(txt)
return
'''
示例7: delete_partition
def delete_partition(diskob, part):
try:
diskob.deletePartition(part)
except Exception as general_error:
txt = _("Can't delete partition {0}").format(part)
logging.error(txt)
logging.error(general_error)
debug_txt = "{0}\n{1}".format(txt, general_error)
show.error(None, debug_txt)
示例8: delete_partition
def delete_partition(diskob, part):
try:
diskob.deletePartition(part)
except Exception as err:
txt = _("Can't delete partition %s") % part
logging.error(txt)
logging.error(err)
debugtxt = ("%s\n%s" % (txt, err))
show.error(debugtxt)
示例9: delete_partition
def delete_partition(diskob, part):
""" Remove partition from disk object """
try:
diskob.deletePartition(part)
except Exception as ex:
template = "Cannot delete partition {1}. An exception of type {1} occured. Arguments:\n{2!r}"
message = template.format(part, type(ex).__name__, ex.args)
logging.error(message)
show.error(None, message)
示例10: remove_logical_volume
def remove_logical_volume(logical_volume):
""" Removes a logical volume """
try:
subprocess.check_call(["lvremove", "-f", logical_volume])
except subprocess.CalledProcessError as err:
txt = _("Can't remove logical volume {0}").format(logical_volume)
logging.error(txt)
logging.error(err)
debugtxt = "{0}\n{1}".format(txt, err)
show.error(None, debugtxt)
示例11: remove_physical_volume
def remove_physical_volume(physical_volume):
""" Removes a physical volume """
try:
subprocess.check_call(["pvremove", "-f", physical_volume])
except subprocess.CalledProcessError as err:
txt = _("Can't remove physical volume %s") % physical_volume
logging.error(txt)
logging.error(err)
debugtxt = ("%s\n%s" % (txt, err))
show.error(debugtxt)
示例12: get_devices
def get_devices():
""" Get all devices """
device_list = parted.getAllDevices()
disk_dic = {}
myhomepath = '/run/archiso/bootmnt'
if os.path.exists(myhomepath):
myhome = subprocess.check_output(["df", "-P", myhomepath]).decode()
else:
myhome = ""
for dev in device_list:
if dev.path in myhome:
continue
# I left all of the below here but commented out to see some use cases
# isbusy = in use/mounted. Needs to flag if 'yes' to prompt user to umount
# isbusy = dev.busy
# path gives /dev/sda or something similar
# myname = dev.path
# Hard drives measure themselves assuming kilo=1000, mega=1mil, etc
# limiter = 1000
# Some disk size calculations
# byte_size = dev.length * dev.sectorSize
# megabyte_size = byte_size / (limiter * limiter)
# gigabyte_size = megabyte_size / limiter
# print(byte_size)
# print(dev.length)
# Must create disk object to drill down
# Skip cd drive, special devices like LUKS and LVM and
# RPMB (Replay Protected Memory Block)
disk_obj = None
rpmb = (dev.path.startswith("/dev/mmcblk") and dev.path.endswith("rpmb"))
exclude = (dev.path.startswith("/dev/sr") or dev.path.startswith("/dev/mapper"))
if not rpmb and not exclude:
try:
disk_obj = parted.Disk(dev)
result = OK
except parted.DiskLabelException:
# logging.warning('Unrecognised disk label in device %s.', dev.path)
result = UNRECOGNISED_DISK_LABEL
except Exception as ex:
template = "Cannot get devices information. An exception of type {0} occured. Arguments:\n{1!r}"
message = template.format(type(ex).__name__, ex.args)
logging.error(message)
show.error(None, message)
result = UNKNOWN_ERROR
finally:
disk_dic[dev.path] = (disk_obj, result)
return disk_dic
示例13: get_devices
def get_devices():
device_list = parted.getAllDevices()
disk_dic = {}
myhomepath = '/bootmnt'
if os.path.exists(myhomepath):
myhome = subprocess.check_output(["df", "-P", myhomepath]).decode()
else:
myhome = ""
for dev in device_list:
if dev.path in myhome:
continue
# I left all of the below here but commented out to see some use cases
# isbusy = in use/mounted. Needs to flag if 'yes' to prompt user to umount
# isbusy = dev.busy
# path gives /dev/sda or something similar
# myname = dev.path
# Hard drives measure themselves assuming kilo=1000, mega=1mil, etc
# limiter = 1000
# Some disk size calculations
# byte_size = dev.length * dev.sectorSize
# megabyte_size = byte_size / (limiter * limiter)
# gigabyte_size = megabyte_size / limiter
# print(byte_size)
# print(dev.length)
# Must create disk object to drill down
# Skip all blacklisted devices
dev_name = dev.path[5:]
if any(re.search(expr, dev_name) for expr in DEVICE_BLACKLIST):
continue
# Skip cd drive and special devices like LUKS and LVM
disk_obj = None
if not dev.path.startswith("/dev/sr") and not dev.path.startswith("/dev/mapper"):
try:
disk_obj = parted.Disk(dev)
result = OK
except parted.DiskLabelException:
# logging.warning(_('Unrecognised disk label in device {0}.'.format(dev.path)))
result = UNRECOGNISED_DISK_LABEL
except Exception as general_error:
logging.error(general_error)
msg = _("Exception: {0}.\nFor more information take a look at /tmp/thus.log").format(general_error)
show.error(None, msg)
result = UNKNOWN_ERROR
finally:
disk_dic[dev.path] = (disk_obj, result)
return disk_dic
示例14: get_used_space_from_path
def get_used_space_from_path(path):
try:
result = subprocess.check_output(shlex.split('df -H %s' % path)).decode()
lines = result.split('\n')
used_space = lines[1].split()[2]
except subprocess.CalledProcessError as err:
used_space = 0
txt = _("Can't detect used space from %s") % path
logging.error(txt)
logging.error(err)
debugtxt = ("%s\n%s" % (txt, err))
show.error(debugtxt)
return used_space
示例15: get_used_space_from_path
def get_used_space_from_path(path):
try:
cmd = ["df", "-H", path]
result = subprocess.check_output(cmd).decode()
lines = result.split("\n")
used_space = lines[1].split()[2]
except subprocess.CalledProcessError as process_error:
used_space = 0
txt = _("Can't detect used space from {0}: {1}").format(path, process_error)
logging.error(txt)
debug_txt = "{0}\n{1}".format(txt, process_error)
show.error(None, debug_txt)
return used_space