Rename variables that shadow built-in functions.

This commit is contained in:
Cole Robinson 2008-11-18 15:42:51 -05:00
parent 11a38c01f3
commit a14b844b20
14 changed files with 248 additions and 242 deletions

View File

@ -142,11 +142,11 @@ def setup_logging():
libvirt.registerErrorHandler(f=libvirt_callback, ctx=None)
# Log uncaught exceptions
def exception_log(type, val, tb):
def exception_log(typ, val, tb):
import traceback
str = traceback.format_exception(type, val, tb)
logging.exception("".join(str))
sys.__excepthook__(type, val, tb)
s = traceback.format_exception(typ, val, tb)
logging.exception("".join(s))
sys.__excepthook__(typ, val, tb)
sys.excepthook = exception_log
def parse_commandline():

View File

@ -261,10 +261,10 @@ class vmmAddHardware(gobject.GObject):
self.window.get_widget("create-forward").show()
def get_config_hardware_type(self):
type = self.window.get_widget("hardware-type")
if type.get_active_iter() == None:
_type = self.window.get_widget("hardware-type")
if _type.get_active_iter() == None:
return None
return type.get_model().get_value(type.get_active_iter(), 2)
return _type.get_model().get_value(_type.get_active_iter(), 2)
def get_config_disk_image(self):
if self.window.get_widget("storage-partition").get_active():
@ -304,15 +304,15 @@ class vmmAddHardware(gobject.GObject):
def get_config_input(self):
target = self.window.get_widget("input-type")
label = target.get_model().get_value(target.get_active_iter(), 0)
type = target.get_model().get_value(target.get_active_iter(), 1)
_type = target.get_model().get_value(target.get_active_iter(), 1)
bus = target.get_model().get_value(target.get_active_iter(), 2)
return label, type, bus
return label, _type, bus
def get_config_graphics(self):
type = self.window.get_widget("graphics-type")
if type.get_active_iter() is None:
_type = self.window.get_widget("graphics-type")
if _type.get_active_iter() is None:
return None
return type.get_model().get_value(type.get_active_iter(), 1)
return _type.get_model().get_value(_type.get_active_iter(), 1)
def get_config_vnc_port(self):
port = self.window.get_widget("graphics-port")
@ -418,9 +418,9 @@ class vmmAddHardware(gobject.GObject):
self.window.get_widget("summary-mac-address").set_text("-")
elif hwpage == PAGE_INPUT:
self.window.get_widget("summary-input").show()
input = self.get_config_input()
self.window.get_widget("summary-input-type").set_text(input[0])
if input[1] == "tablet":
inp = self.get_config_input()
self.window.get_widget("summary-input-type").set_text(inp[0])
if inp[1] == "tablet":
self.window.get_widget("summary-input-mode").set_text(_("Absolute movement"))
else:
self.window.get_widget("summary-input-mode").set_text(_("Relative movement"))
@ -497,8 +497,8 @@ class vmmAddHardware(gobject.GObject):
self.add_device(self._dev.get_xml_config())
def add_input(self):
input = self.get_config_input()
xml = "<input type='%s' bus='%s'/>\n" % (input[1], input[2])
inp = self.get_config_input()
xml = "<input type='%s' bus='%s'/>\n" % (inp[1], inp[2])
self.add_device(xml)
def add_graphics(self):
@ -590,12 +590,13 @@ class vmmAddHardware(gobject.GObject):
def browse_storage_file_address(self, src, ignore=None):
folder = self.config.get_default_image_dir(self.vm.get_connection())
file = self._browse_file(_("Locate or Create New Storage File"), \
folder=folder, confirm_overwrite=True)
if file != None:
self.window.get_widget("storage-file-address").set_text(file)
filename = self._browse_file(_("Locate or Create New Storage File"), \
folder=folder, confirm_overwrite=True)
if filename != None:
self.window.get_widget("storage-file-address").set_text(filename)
def _browse_file(self, dialog_name, folder=None, type=None, confirm_overwrite=False):
def _browse_file(self, dialog_name, folder=None, _type=None,
confirm_overwrite=False):
# user wants to browse for an ISO
fcdialog = gtk.FileChooserDialog(dialog_name,
self.window.get_widget("vmm-add-hardware"),
@ -604,9 +605,9 @@ class vmmAddHardware(gobject.GObject):
gtk.STOCK_OPEN, gtk.RESPONSE_ACCEPT),
None)
fcdialog.set_default_response(gtk.RESPONSE_ACCEPT)
if type != None:
if _type != None:
f = gtk.FileFilter()
f.add_pattern("*." + type)
f.add_pattern("*." + _type)
fcdialog.set_filter(f)
if folder != None:
fcdialog.set_current_folder(folder)
@ -624,9 +625,10 @@ class vmmAddHardware(gobject.GObject):
return None
def toggle_storage_size(self, ignore1=None, ignore2=None):
file = self.get_config_disk_image()
if file != None and len(file) > 0 and \
(self.vm.get_connection().is_remote() or not os.path.exists(file)):
filename = self.get_config_disk_image()
if filename != None and len(filename) > 0 and \
(self.vm.get_connection().is_remote() or
not os.path.exists(filename)):
self.window.get_widget("storage-file-size").set_sensitive(True)
self.window.get_widget("non-sparse").set_sensitive(True)
size = self.get_config_disk_size()
@ -636,8 +638,8 @@ class vmmAddHardware(gobject.GObject):
else:
self.window.get_widget("storage-file-size").set_sensitive(False)
self.window.get_widget("non-sparse").set_sensitive(False)
if os.path.isfile(file):
size = os.path.getsize(file)/(1024*1024)
if os.path.isfile(filename):
size = os.path.getsize(filename)/(1024*1024)
self.window.get_widget("storage-file-size").set_value(size)
else:
self.window.get_widget("storage-file-size").set_value(0)
@ -718,9 +720,9 @@ class vmmAddHardware(gobject.GObject):
bus, device = self.get_config_disk_target()
if self.window.get_widget("storage-partition").get_active():
type = virtinst.VirtualDisk.TYPE_BLOCK
_type = virtinst.VirtualDisk.TYPE_BLOCK
else:
type = virtinst.VirtualDisk.TYPE_FILE
_type = virtinst.VirtualDisk.TYPE_FILE
# Build disk object
filesize = self.get_config_disk_size()
@ -736,7 +738,7 @@ class vmmAddHardware(gobject.GObject):
vmmutil.build_default_pool(self.vm.get_connection().vmm)
self._dev = virtinst.VirtualDisk(self.get_config_disk_image(),
filesize,
type = type,
type = _type,
sparse=self.is_sparse_file(),
readOnly=readonly,
device=device,
@ -809,10 +811,10 @@ class vmmAddHardware(gobject.GObject):
elif page_num == PAGE_GRAPHICS:
graphics = self.get_config_graphics()
if graphics == "vnc":
type = virtinst.VirtualGraphics.TYPE_VNC
_type = virtinst.VirtualGraphics.TYPE_VNC
else:
type = virtinst.VirtualGraphics.TYPE_SDL
self._dev = virtinst.VirtualGraphics(type=type)
_type = virtinst.VirtualGraphics.TYPE_SDL
self._dev = virtinst.VirtualGraphics(type=_type)
try:
self._dev.port = self.get_config_vnc_port()
self._dev.passwd = self.get_config_vnc_password()

View File

@ -130,9 +130,9 @@ class vmmChooseCD(gobject.GObject):
pass
def browse_fv_iso_location(self, ignore1=None, ignore2=None):
file = self._browse_file(_("Locate ISO Image"), type="iso")
if file != None:
self.window.get_widget("iso-path").set_text(file)
filename = self._browse_file(_("Locate ISO Image"), _type="iso")
if filename != None:
self.window.get_widget("iso-path").set_text(filename)
def populate_opt_media(self):
try:
@ -143,7 +143,7 @@ class vmmChooseCD(gobject.GObject):
logging.error("Unable to create optical-helper widget: '%s'", e)
self.window.get_widget("physical-media").set_sensitive(False)
def _browse_file(self, dialog_name, folder=None, type=None):
def _browse_file(self, dialog_name, folder=None, _type=None):
# user wants to browse for an ISO
fcdialog = gtk.FileChooserDialog(dialog_name,
self.window.get_widget("vmm-choose-cd"),
@ -152,9 +152,9 @@ class vmmChooseCD(gobject.GObject):
gtk.STOCK_OPEN, gtk.RESPONSE_ACCEPT),
None)
fcdialog.set_default_response(gtk.RESPONSE_ACCEPT)
if type != None:
if _type != None:
f = gtk.FileFilter()
f.add_pattern("*." + type)
f.add_pattern("*." + _type)
fcdialog.set_filter(f)
if folder != None:
fcdialog.set_current_folder(folder)

View File

@ -250,23 +250,23 @@ class vmmConfig:
return self.keyring.is_available()
def clear_console_password(self, vm):
id = self.conf.get_int(self.conf_dir + "/console/passwords/" + vm.get_uuid())
_id = self.conf.get_int(self.conf_dir + "/console/passwords/" + vm.get_uuid())
if id != None:
if _id != None:
if not(self.has_keyring()):
return
if self.keyring.clear_secret(id):
if self.keyring.clear_secret(_id):
self.conf.unset(self.conf_dir + "/console/passwords/" + vm.get_uuid())
def get_console_password(self, vm):
id = self.conf.get_int(self.conf_dir + "/console/passwords/" + vm.get_uuid())
_id = self.conf.get_int(self.conf_dir + "/console/passwords/" + vm.get_uuid())
if id != None:
if _id != None:
if not(self.has_keyring()):
return ""
secret = self.keyring.get_secret(id)
secret = self.keyring.get_secret(_id)
if secret != None and secret.get_name() == self.get_secret_name(vm):
if not(secret.has_attribute("hvuri")):
return ""
@ -290,9 +290,9 @@ class vmmConfig:
# is our unique key
secret = vmmSecret(self.get_secret_name(vm), password, { "uuid" : vm.get_uuid(), "hvuri": vm.get_connection().get_uri() })
id = self.keyring.add_secret(secret)
if id != None:
self.conf.set_int(self.conf_dir + "/console/passwords/" + vm.get_uuid(), id)
_id = self.keyring.add_secret(secret)
if _id != None:
self.conf.set_int(self.conf_dir + "/console/passwords/" + vm.get_uuid(), _id)
def get_url_list_length(self):
length = self.conf.get_int(self.conf_dir + "/urls/url-list-length")

View File

@ -160,9 +160,9 @@ class vmmConnection(gobject.GObject):
for path in self.hal_iface.FindDeviceByCapability("net"):
self._net_phys_device_added(path)
except:
(type, value, stacktrace) = sys.exc_info ()
(_type, value, stacktrace) = sys.exc_info ()
logging.error("Unable to connect to HAL to list network devices: '%s'" + \
str(type) + " " + str(value) + "\n" + \
str(_type) + " " + str(value) + "\n" + \
traceback.format_exc (stacktrace))
self.bus = None
self.hal_iface = None
@ -395,12 +395,12 @@ class vmmConnection(gobject.GObject):
return self._do_creds_dialog(creds)
except:
(type, value, stacktrace) = sys.exc_info ()
(_type, value, stacktrace) = sys.exc_info ()
# Detailed error message, in English so it can be Googled.
self.connectError = \
("Failed to get credentials '%s':\n" %
str(self.uri)) + \
str(type) + " " + str(value) + "\n" + \
str(_type) + " " + str(value) + "\n" + \
traceback.format_exc (stacktrace)
logging.error(self.connectError)
return -1
@ -424,12 +424,12 @@ class vmmConnection(gobject.GObject):
except:
self.state = self.STATE_DISCONNECTED
(type, value, stacktrace) = sys.exc_info ()
(_type, value, stacktrace) = sys.exc_info ()
# Detailed error message, in English so it can be Googled.
self.connectError = \
("Unable to open connection to hypervisor URI '%s':\n" %
str(self.uri)) + \
str(type) + " " + str(value) + "\n" + \
str(_type) + " " + str(value) + "\n" + \
traceback.format_exc (stacktrace)
logging.error(self.connectError)
@ -500,8 +500,8 @@ class vmmConnection(gobject.GObject):
def get_host_info(self):
return self.hostinfo
def get_max_vcpus(self, type=None):
return virtinst.util.get_max_vcpus(self.vmm, type)
def get_max_vcpus(self, _type=None):
return virtinst.util.get_max_vcpus(self.vmm, _type)
def get_autoconnect(self):
# Use a local variable to cache autoconnect so we don't repeatedly
@ -732,10 +732,10 @@ class vmmConnection(gobject.GObject):
# Filter out active domains which haven't changed
if newActiveIDs != None:
for id in newActiveIDs:
if oldActiveIDs.has_key(id):
for _id in newActiveIDs:
if oldActiveIDs.has_key(_id):
# No change, copy across existing VM object
vm = oldActiveIDs[id]
vm = oldActiveIDs[_id]
curUUIDs[vm.get_uuid()] = vm
activeUUIDs.append(vm.get_uuid())
else:
@ -743,13 +743,13 @@ class vmmConnection(gobject.GObject):
# to create the wrapper so we can see
# if its a previously inactive domain.
try:
vm = self.vmm.lookupByID(id)
vm = self.vmm.lookupByID(_id)
uuid = self.uuidstr(vm.UUID())
maybeNewUUIDs[uuid] = vm
startedUUIDs.append(uuid)
activeUUIDs.append(uuid)
except libvirt.libvirtError:
logging.debug("Couldn't fetch domain id '%s'" % str(id)
logging.debug("Couldn't fetch domain id '%s'" % str(_id)
+ ": it probably went away")
# Filter out inactive domains which haven't changed
@ -996,11 +996,11 @@ class vmmConnection(gobject.GObject):
return [ 0.0 ]
def uuidstr(self, rawuuid):
hex = ['0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f']
hx = ['0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f']
uuid = []
for i in range(16):
uuid.append(hex[((ord(rawuuid[i]) >> 4) & 0xf)])
uuid.append(hex[(ord(rawuuid[i]) & 0xf)])
uuid.append(hx[((ord(rawuuid[i]) >> 4) & 0xf)])
uuid.append(hx[(ord(rawuuid[i]) & 0xf)])
if i == 3 or i == 5 or i == 7 or i == 9:
uuid.append('-')
return "".join(uuid)
@ -1033,9 +1033,9 @@ class vmmConnection(gobject.GObject):
(ignore,bridge) = os.path.split(dest)
return bridge
except:
(type, value, stacktrace) = sys.exc_info ()
(_type, value, stacktrace) = sys.exc_info ()
logging.error("Unable to determine if device is shared:" +
str(type) + " " + str(value) + "\n" + \
str(_type) + " " + str(value) + "\n" + \
traceback.format_exc (stacktrace))
return None

View File

@ -365,12 +365,12 @@ class vmmCreate(gobject.GObject):
else:
return "PXE"
def get_config_installer(self, type, os_type):
def get_config_installer(self, _type, os_type):
if self.get_config_install_method() == VM_INST_PXE:
return virtinst.PXEInstaller(type=type, os_type=os_type,
return virtinst.PXEInstaller(type=_type, os_type=os_type,
conn=self._guest.conn)
else:
return virtinst.DistroInstaller(type=type, os_type=os_type,
return virtinst.DistroInstaller(type=_type, os_type=os_type,
conn=self._guest.conn)
def get_config_kickstart_source(self):
@ -452,9 +452,9 @@ class vmmCreate(gobject.GObject):
return VM_INST_PXE
def get_config_os_type(self):
type = self.window.get_widget("os-type")
if type.get_active_iter() != None:
return type.get_model().get_value(type.get_active_iter(), 0)
_type = self.window.get_widget("os-type")
if _type.get_active_iter() != None:
return _type.get_model().get_value(_type.get_active_iter(), 0)
return None
def get_config_os_variant(self):
@ -468,9 +468,9 @@ class vmmCreate(gobject.GObject):
if variant.get_active_iter() != None:
return variant.get_model().get_value(variant.get_active_iter(), 1)
type = self.window.get_widget("os-type")
if type.get_active_iter() != None:
return type.get_model().get_value(type.get_active_iter(), 1)
_type = self.window.get_widget("os-type")
if _type.get_active_iter() != None:
return _type.get_model().get_value(_type.get_active_iter(), 1)
return "N/A"
def get_config_sound(self):
@ -722,12 +722,12 @@ class vmmCreate(gobject.GObject):
else:
logging.debug("Install completed")
except:
(type, value, stacktrace) = sys.exc_info ()
(_type, value, stacktrace) = sys.exc_info ()
# Detailed error message, in English so it can be Googled.
details = \
"Unable to complete install '%s'" % \
(str(type) + " " + str(value) + "\n" + \
(str(_type) + " " + str(value) + "\n" + \
traceback.format_exc (stacktrace))
self.install_error = _("Unable to complete install: '%s'") % str(value)
@ -735,11 +735,11 @@ class vmmCreate(gobject.GObject):
logging.error(details)
def browse_iso_location(self, ignore1=None, ignore2=None):
file = self._browse_file(_("Locate ISO Image"), type="iso")
if file != None:
self.window.get_widget("fv-iso-location").set_text(file)
f = self._browse_file(_("Locate ISO Image"), _type="iso")
if f != None:
self.window.get_widget("fv-iso-location").set_text(f)
def _browse_file(self, dialog_name, folder=None, type=None):
def _browse_file(self, dialog_name, folder=None, _type=None):
# user wants to browse for an ISO
fcdialog = gtk.FileChooserDialog(dialog_name,
self.window.get_widget("vmm-create"),
@ -748,9 +748,9 @@ class vmmCreate(gobject.GObject):
gtk.STOCK_OPEN, gtk.RESPONSE_ACCEPT),
None)
fcdialog.set_default_response(gtk.RESPONSE_ACCEPT)
if type != None:
if _type != None:
f = gtk.FileFilter()
f.add_pattern("*." + type)
f.add_pattern("*." + _type)
fcdialog.set_filter(f)
if folder != None:
fcdialog.set_current_folder(folder)
@ -782,16 +782,16 @@ class vmmCreate(gobject.GObject):
fcdialog.connect("confirm-overwrite", self.confirm_overwrite_callback)
response = fcdialog.run()
fcdialog.hide()
file = None
f = None
if(response == gtk.RESPONSE_ACCEPT):
file = fcdialog.get_filename()
if file != None:
self.window.get_widget("storage-file-address").set_text(file)
f = fcdialog.get_filename()
if f != None:
self.window.get_widget("storage-file-address").set_text(f)
def toggle_storage_size(self, ignore1=None, ignore2=None):
file = self.get_config_disk_image()
if file != None and len(file) > 0 and \
(self.connection.is_remote() or not os.path.exists(file)):
f = self.get_config_disk_image()
if f != None and len(f) > 0 and \
(self.connection.is_remote() or not os.path.exists(f)):
self.window.get_widget("storage-file-size").set_sensitive(True)
self.window.get_widget("non-sparse").set_sensitive(True)
size = self.get_config_disk_size()
@ -801,8 +801,8 @@ class vmmCreate(gobject.GObject):
else:
self.window.get_widget("storage-file-size").set_sensitive(False)
self.window.get_widget("non-sparse").set_sensitive(False)
if os.path.isfile(file):
size = os.path.getsize(file)/(1024*1024)
if os.path.isfile(f):
size = os.path.getsize(f)/(1024*1024)
self.window.get_widget("storage-file-size").set_value(size)
else:
self.window.get_widget("storage-file-size").set_value(0)
@ -833,19 +833,19 @@ class vmmCreate(gobject.GObject):
else:
self.window.get_widget("storage-partition-box").set_sensitive(False)
self.window.get_widget("storage-file-box").set_sensitive(True)
file = self.window.get_widget("storage-file-address").get_text()
if file is None or file == "":
dir = self.config.get_default_image_dir(self.connection)
file = os.path.join(dir, self.get_config_name() + ".img")
_file = self.window.get_widget("storage-file-address").get_text()
if _file is None or _file == "":
_dir = self.config.get_default_image_dir(self.connection)
_file = os.path.join(_dir, self.get_config_name() + ".img")
if not self.connection.is_remote():
n = 1
while os.path.exists(file) and n < 100:
file = os.path.join(dir, self.get_config_name() + \
"-" + str(n) + ".img")
while os.path.exists(_file) and n < 100:
file = os.path.join(_dir, self.get_config_name() + \
"-" + str(n) + ".img")
n = n + 1
if os.path.exists(file):
file = ""
self.window.get_widget("storage-file-address").set_text(file)
if os.path.exists(_file):
_file = ""
self.window.get_widget("storage-file-address").set_text(_file)
self.toggle_storage_size()
def change_network_type(self, ignore=None):
@ -869,9 +869,9 @@ class vmmCreate(gobject.GObject):
startup_mem_adjustment.value = max_memory
startup_mem_adjustment.upper = max_memory
def set_max_vcpus(self, type):
self.window.get_widget("create-vcpus").get_adjustment().upper = self.connection.get_max_vcpus(type)
self.window.get_widget("config-max-vcpus").set_text(str(self.connection.get_max_vcpus(type)))
def set_max_vcpus(self, _type):
self.window.get_widget("create-vcpus").get_adjustment().upper = self.connection.get_max_vcpus(_type)
self.window.get_widget("config-max-vcpus").set_text(str(self.connection.get_max_vcpus(_type)))
def validate(self, page_num):
@ -987,9 +987,9 @@ class vmmCreate(gobject.GObject):
filesize = self.get_config_disk_size() / 1024.0
try:
if self.window.get_widget("storage-partition").get_active():
type = virtinst.VirtualDisk.TYPE_BLOCK
_type = virtinst.VirtualDisk.TYPE_BLOCK
else:
type = virtinst.VirtualDisk.TYPE_FILE
_type = virtinst.VirtualDisk.TYPE_FILE
if (os.path.dirname(os.path.abspath(path)) == \
vmmutil.DEFAULT_POOL_PATH):
@ -999,7 +999,7 @@ class vmmCreate(gobject.GObject):
filesize,
sparse = self.is_sparse_file(),
device = virtinst.VirtualDisk.DEVICE_DISK,
type = type,
type = _type,
conn=self._guest.conn)
if self._disk.type == virtinst.VirtualDisk.TYPE_FILE and \
@ -1112,19 +1112,22 @@ class vmmCreate(gobject.GObject):
model.append(["generic", "Generic"])
types = virtinst.FullVirtGuest.list_os_types()
types.sort()
for type in types:
model.append([type, virtinst.FullVirtGuest.get_os_type_label(type)])
for _type in types:
model.append([_type,
virtinst.FullVirtGuest.get_os_type_label(_type)])
def populate_os_variant_model(self, type):
def populate_os_variant_model(self, _type):
model = self.window.get_widget("os-variant").get_model()
model.clear()
if type=="generic":
if _type == "generic":
model.append(["generic", "Generic"])
return
variants = virtinst.FullVirtGuest.list_os_variants(type)
variants = virtinst.FullVirtGuest.list_os_variants(_type)
variants.sort()
for variant in variants:
model.append([variant, virtinst.FullVirtGuest.get_os_variant_label(type, variant)])
model.append([variant,
virtinst.FullVirtGuest.get_os_variant_label(_type,
variant)])
def populate_network_model(self, model):
model.clear()
@ -1153,8 +1156,8 @@ class vmmCreate(gobject.GObject):
def change_os_type(self, box):
model = box.get_model()
if box.get_active_iter() != None:
type = model.get_value(box.get_active_iter(), 0)
self.populate_os_variant_model(type)
_type = model.get_value(box.get_active_iter(), 0)
self.populate_os_variant_model(_type)
variant = self.window.get_widget("os-variant")
variant.set_active(0)

View File

@ -123,8 +123,8 @@ class vmmCreatePool(gobject.GObject):
model.clear()
types = Storage.StoragePool.get_pool_types()
types.sort()
for type in types:
model.append([type, "%s: %s" % (type, Storage.StoragePool.get_pool_type_desc(type))])
for typ in types:
model.append([typ, "%s: %s" % (typ, Storage.StoragePool.get_pool_type_desc(typ))])
def populate_pool_format(self):
model = self.window.get_widget("pool-format").get_model()
@ -166,9 +166,9 @@ class vmmCreatePool(gobject.GObject):
def get_config_type(self):
type = self.window.get_widget("pool-type")
if type.get_active_iter() != None:
return type.get_model().get_value(type.get_active_iter(), 0)
typ = self.window.get_widget("pool-type")
if typ.get_active_iter() != None:
return typ.get_model().get_value(typ.get_active_iter(), 0)
return None
def get_config_name(self):
@ -312,13 +312,13 @@ class vmmCreatePool(gobject.GObject):
def validate(self, page):
if page == PAGE_NAME:
type = self.get_config_type()
typ = self.get_config_type()
name = self.get_config_name()
conn = self.conn.vmm
try:
pool_class = Storage.StoragePool.get_pool_class(type)
self._pool = pool_class(name=name,conn=conn)
pool_class = Storage.StoragePool.get_pool_class(typ)
self._pool = pool_class(name=name, conn=conn)
except ValueError, e:
return self.err.val_err(_("Pool Parameter Error"), str(e))

View File

@ -405,12 +405,12 @@ class vmmDetails(gobject.GObject):
topwin = self.window.get_widget("vmm-details")
topwin.set_title(self.title)
def notify_closed(self, id, reason=None):
if self.notifyID is not None and self.notifyID == id:
def notify_closed(self, i, reason=None):
if self.notifyID is not None and self.notifyID == i:
self.notifyID = None
def notify_action(self, id, action):
if self.notifyID is None or self.notifyID != id:
def notify_action(self, i, action):
if self.notifyID is None or self.notifyID != i:
return
if action == "dismiss":
@ -1210,10 +1210,10 @@ class vmmDetails(gobject.GObject):
else:
self.vncViewer.open_host(host, str(port))
except:
(type, value, stacktrace) = sys.exc_info ()
(typ, value, stacktrace) = sys.exc_info ()
details = \
"Unable to start virtual machine '%s'" % \
(str(type) + " " + str(value) + "\n" + \
(str(typ) + " " + str(value) + "\n" + \
traceback.format_exc (stacktrace))
logging.error(details)
@ -1282,13 +1282,14 @@ class vmmDetails(gobject.GObject):
fcdialog.set_do_overwrite_confirmation(True)
if fcdialog.run() == gtk.RESPONSE_ACCEPT:
fcdialog.hide()
file = fcdialog.get_filename()
if not(file.endswith(".png")):
file = file + ".png"
filename = fcdialog.get_filename()
if not(filename.endswith(".png")):
filename += ".png"
image = self.vncViewer.get_pixbuf()
# Save along with a little metadata about us & the domain
image.save(file, 'png', { 'tEXt::Hypervisor URI': self.vm.get_connection().get_uri(),
image.save(filename, 'png',
{ 'tEXt::Hypervisor URI': self.vm.get_connection().get_uri(),
'tEXt::Domain Name': self.vm.get_name(),
'tEXt::Domain UUID': self.vm.get_uuid(),
'tEXt::Generator App': self.config.get_appname(),
@ -1621,14 +1622,15 @@ class vmmDetails(gobject.GObject):
# Populate list of input devices
currentInputs = {}
for input in self.vm.get_input_devices():
for inp in self.vm.get_input_devices():
missing = True
insertAt = 0
currentInputs[input[3]] = 1
currentInputs[inp[3]] = 1
for row in hw_list_model:
if row[HW_LIST_COL_TYPE] == HW_LIST_TYPE_INPUT and row[HW_LIST_COL_DEVICE][3] == input[3]:
if (row[HW_LIST_COL_TYPE] == HW_LIST_TYPE_INPUT and
row[HW_LIST_COL_DEVICE][3] == inp[3]):
# Update metadata
row[HW_LIST_COL_DEVICE] = input
row[HW_LIST_COL_DEVICE] = inp
missing = False
if row[HW_LIST_COL_TYPE] <= HW_LIST_TYPE_INPUT:
@ -1636,12 +1638,12 @@ class vmmDetails(gobject.GObject):
# Add in row
if missing:
if input[0] == "tablet":
hw_list_model.insert(insertAt, [_("Tablet"), gtk.STOCK_INDEX, gtk.ICON_SIZE_LARGE_TOOLBAR, None, HW_LIST_TYPE_INPUT, input])
elif input[0] == "mouse":
hw_list_model.insert(insertAt, [_("Mouse"), gtk.STOCK_INDEX, gtk.ICON_SIZE_LARGE_TOOLBAR, None, HW_LIST_TYPE_INPUT, input])
if inp[0] == "tablet":
hw_list_model.insert(insertAt, [_("Tablet"), gtk.STOCK_INDEX, gtk.ICON_SIZE_LARGE_TOOLBAR, None, HW_LIST_TYPE_INPUT, inp])
elif inp[0] == "mouse":
hw_list_model.insert(insertAt, [_("Mouse"), gtk.STOCK_INDEX, gtk.ICON_SIZE_LARGE_TOOLBAR, None, HW_LIST_TYPE_INPUT, inp])
else:
hw_list_model.insert(insertAt, [_("Input"), gtk.STOCK_INDEX, gtk.ICON_SIZE_LARGE_TOOLBAR, None, HW_LIST_TYPE_INPUT, input])
hw_list_model.insert(insertAt, [_("Inp"), gtk.STOCK_INDEX, gtk.ICON_SIZE_LARGE_TOOLBAR, None, HW_LIST_TYPE_INPUT, inp])
# Populate list of graphics devices
currentGraphics = {}
@ -1804,9 +1806,9 @@ class vmmDetails(gobject.GObject):
self.choose_cd.set_target(self.window.get_widget("disk-target-device").get_text())
self.choose_cd.show()
def connect_cdrom(self, src, type, source, target):
def connect_cdrom(self, src, typ, source, target):
try:
self.vm.connect_cdrom_device(type, source, target)
self.vm.connect_cdrom_device(typ, source, target)
except Exception, e:
self.err.show_err(_("Error Connecting CDROM: %s" % str(e)),
"".join(traceback.format_exc()))

View File

@ -82,10 +82,10 @@ class vmmDomain(gobject.GObject):
return self.vm.ID()
def get_id_pretty(self):
id = self.get_id()
if id < 0:
i = self.get_id()
if i < 0:
return "-"
return str(id)
return str(i)
def get_name(self):
return self.vm.name()
@ -492,14 +492,14 @@ class vmmDomain(gobject.GObject):
self.vm.resume()
self._update_status()
def save(self, file, ignore1=None, background=True):
def save(self, filename, ignore1=None, background=True):
if background:
conn = libvirt.open(self.connection.uri)
vm = conn.lookupByID(self.get_id())
else:
vm = self.vm
vm.save(file)
vm.save(filename)
self._update_status()
def destroy(self):
@ -559,10 +559,10 @@ class vmmDomain(gobject.GObject):
def get_graphics_console(self):
self.xml = None
type = util.get_xml_path(self.get_xml(),
"/domain/devices/graphics/@type")
typ = util.get_xml_path(self.get_xml(),
"/domain/devices/graphics/@type")
port = None
if type == "vnc":
if typ == "vnc":
port = util.get_xml_path(self.get_xml(),
"/domain/devices/graphics[@type='vnc']/@port")
if port is not None:
@ -574,9 +574,9 @@ class vmmDomain(gobject.GObject):
# reliably resolve 'localhost' into 127.0.0.1, either returning
# the public IP, or an IPv6 addr. Neither work since QEMU only
# listens on 127.0.0.1 for VNC.
return [type, "127.0.0.1", port, None, None]
return [typ, "127.0.0.1", port, None, None]
else:
return [type, self.connection.get_hostname(), port, transport, username]
return [typ, self.connection.get_hostname(), port, transport, username]
def get_disk_devices(self):
@ -584,7 +584,7 @@ class vmmDomain(gobject.GObject):
disks = []
ret = ctx.xpathEval("/domain/devices/disk")
for node in ret:
type = node.prop("type")
typ = node.prop("type")
srcpath = None
devdst = None
bus = None
@ -595,12 +595,12 @@ class vmmDomain(gobject.GObject):
devtype = "disk"
for child in node.children:
if child.name == "source":
if type == "file":
if typ == "file":
srcpath = child.prop("file")
elif type == "block":
elif typ == "block":
srcpath = child.prop("dev")
elif type == None:
type = "-"
elif typ == None:
typ = "-"
elif child.name == "target":
devdst = child.prop("dev")
bus = child.prop("bus")
@ -612,13 +612,13 @@ class vmmDomain(gobject.GObject):
if srcpath == None:
if devtype == "cdrom":
srcpath = "-"
type = "block"
typ = "block"
else:
raise RuntimeError("missing source path")
if devdst == None:
raise RuntimeError("missing destination device")
disks.append([type, srcpath, devtype, devdst, readonly, \
disks.append([typ, srcpath, devtype, devdst, readonly, \
sharable, bus])
return disks
@ -652,20 +652,20 @@ class vmmDomain(gobject.GObject):
ret = ctx.xpathEval("/domain/devices/interface")
for node in ret:
type = node.prop("type")
typ = node.prop("type")
devmac = None
source = None
target = None
model = None
for child in node.children:
if child.name == "source":
if type == "bridge":
if typ == "bridge":
source = child.prop("bridge")
elif type == "ethernet":
elif typ == "ethernet":
source = child.prop("dev")
elif type == "network":
elif typ == "network":
source = child.prop("network")
elif type == "user":
elif typ == "user":
source = None
else:
source = None
@ -679,7 +679,7 @@ class vmmDomain(gobject.GObject):
# need mac for uniqueness. Some reason XenD doesn't
# always complete kill the NIC record
if devmac != None:
nics.append([type, source, target, devmac, model])
nics.append([typ, source, target, devmac, model])
return nics
return self._parse_device_xml(_parse_network_devs)
@ -690,11 +690,11 @@ class vmmDomain(gobject.GObject):
ret = ctx.xpathEval("/domain/devices/input")
for node in ret:
type = node.prop("type")
typ = node.prop("type")
bus = node.prop("bus")
# XXX Replace 'None' with device model when libvirt supports
# that
inputs.append([type, bus, None, type + ":" + bus])
inputs.append([typ, bus, None, typ + ":" + bus])
return inputs
return self._parse_device_xml(_parse_input_devs)
@ -704,14 +704,14 @@ class vmmDomain(gobject.GObject):
graphics = []
ret = ctx.xpathEval("/domain/devices/graphics[1]")
for node in ret:
type = node.prop("type")
if type == "vnc":
typ = node.prop("type")
if typ == "vnc":
listen = node.prop("listen")
port = node.prop("port")
keymap = node.prop("keymap")
graphics.append([type, listen, port, type, keymap])
graphics.append([typ, listen, port, typ, keymap])
else:
graphics.append([type, None, None, type])
graphics.append([typ, None, None, typ, None])
return graphics
return self._parse_device_xml(_parse_graphics_devs)
@ -832,17 +832,18 @@ class vmmDomain(gobject.GObject):
ret = ctx.xpathEval("/domain/devices/disk[target/@dev='%s']" % path[0].content)
elif dev_type=="input":
type = dev_ctx.xpathEval("/input/@type")
typ = dev_ctx.xpathEval("/input/@type")
bus = dev_ctx.xpathEval("/input/@bus")
if len(type) > 0 and type[0].content != None and len(bus) > 0 and bus[0].content != None:
logging.debug("Looking for type %s bus %s" % (type[0].content, bus[0].content))
ret = ctx.xpathEval("/domain/devices/input[@type='%s' and @bus='%s']" % (type[0].content, bus[0].content))
if (len(typ) > 0 and typ[0].content != None and
len(bus) > 0 and bus[0].content != None):
logging.debug("Looking for type %s bus %s" % (typ[0].content, bus[0].content))
ret = ctx.xpathEval("/domain/devices/input[@type='%s' and @bus='%s']" % (typ[0].content, bus[0].content))
elif dev_type=="graphics":
type = dev_ctx.xpathEval("/graphics/@type")
if len(type) > 0 and type[0].content != None:
logging.debug("Looking for type %s" % type[0].content)
ret = ctx.xpathEval("/domain/devices/graphics[@type='%s']" % type[0].content)
typ = dev_ctx.xpathEval("/graphics/@type")
if len(typ) > 0 and typ[0].content != None:
logging.debug("Looking for type %s" % typ[0].content)
ret = ctx.xpathEval("/domain/devices/graphics[@type='%s']" % typ[0].content)
elif dev_type == "sound":
model = dev_ctx.xpathEval("/sound/@model")
@ -938,7 +939,7 @@ class vmmDomain(gobject.GObject):
else:
self.attach_device(newdev)
def connect_cdrom_device(self, type, source, target):
def connect_cdrom_device(self, _type, source, target):
xml = self.get_disk_xml(target)
doc = None
ctx = None
@ -948,12 +949,12 @@ class vmmDomain(gobject.GObject):
disk_fragment = ctx.xpathEval("/disk")
driver_fragment = ctx.xpathEval("/disk/driver")
origdisk = disk_fragment[0].serialize()
disk_fragment[0].setProp("type", type)
disk_fragment[0].setProp("type", _type)
elem = disk_fragment[0].newChild(None, "source", None)
if type == "file":
if _type == "file":
elem.setProp("file", source)
if driver_fragment:
driver_fragment[0].setProp("name", type)
driver_fragment[0].setProp("name", _type)
else:
elem.setProp("dev", source)
if driver_fragment:

View File

@ -23,11 +23,11 @@ import gtk.glade
import logging
class vmmErrorDialog (gtk.MessageDialog):
def __init__ (self, parent=None, flags=0, type=gtk.MESSAGE_INFO,
def __init__ (self, parent=None, flags=0, typ=gtk.MESSAGE_INFO,
buttons=gtk.BUTTONS_NONE, message_format=None,
message_details=None, default_title=_("Error")):
gtk.MessageDialog.__init__ (self,
parent, flags, type, buttons,
parent, flags, typ, buttons,
message_format)
self.message_format = message_format
self.message_details = message_details

View File

@ -632,11 +632,11 @@ class vmmHost(gobject.GObject):
def get_pool_size_percent(self, uuid):
pool = self.conn.get_pool(uuid)
cap = pool.get_capacity()
all = pool.get_allocation()
if not cap or all is None:
alloc = pool.get_allocation()
if not cap or alloc is None:
per = 0
else:
per = int(((float(all) / float(cap)) * 100))
per = int(((float(alloc) / float(cap)) * 100))
return per
def populate_storage_pools(self, model):

View File

@ -53,31 +53,31 @@ class vmmKeyring:
def add_secret(self, secret):
try:
id = gnomekeyring.item_create_sync(self.keyring,
_id = gnomekeyring.item_create_sync(self.keyring,
gnomekeyring.ITEM_GENERIC_SECRET,
secret.get_name(),
secret.get_attributes(),
secret.get_secret(),
True)
return id
return _id
except:
return None
def get_secret(self, id):
def get_secret(self, _id):
try:
item = gnomekeyring.item_get_info_sync(self.keyring, id)
attrs = gnomekeyring.item_get_attributes_sync(self.keyring, id)
item = gnomekeyring.item_get_info_sync(self.keyring, _id)
attrs = gnomekeyring.item_get_attributes_sync(self.keyring, _id)
return vmmSecret(item.get_display_name(), item.get_secret(), attrs)
except:
return None
def clear_secret(self, id):
def clear_secret(self, _id):
try:
gnomekeyring.item_delete_sync(self.keyring, id)
gnomekeyring.item_delete_sync(self.keyring, _id)
return True
except:
return False

View File

@ -376,9 +376,9 @@ class vmmManager(gobject.GObject):
self.err.val_err(self.domain_restore_error)
self.domain_restore_error = ""
def is_valid_saved_image(self, file):
def is_valid_saved_image(self, savfile):
try:
f = open(file, "r")
f = open(savfile, "r")
magic = f.read(16)
if magic != "LinuxGuestRecord" and magic != "LibvirtQemudSave":
return False
@ -395,16 +395,16 @@ class vmmManager(gobject.GObject):
vmlist = self.window.get_widget("vm-list")
model = vmlist.get_model()
iter = model.get_iter_first()
while iter is not None:
conn = model.get_value(iter, ROW_HANDLE)
_iter = model.get_iter_first()
while _iter is not None:
conn = model.get_value(_iter, ROW_HANDLE)
children = model.iter_children(iter)
children = model.iter_children(_iter)
while children is not None:
vm = model.get_value(children, ROW_HANDLE)
del self.rows[self.vm_row_key(vm)]
model.remove(children)
children = model.iter_children(iter)
children = model.iter_children(_iter)
if conn:
uuids = conn.list_vm_uuids()
@ -418,7 +418,7 @@ class vmmManager(gobject.GObject):
continue
self._append_vm(model, vm, conn)
iter = model.iter_next(iter)
_iter = model.iter_next(_iter)
def vm_added(self, connection, uri, vmuuid):
@ -471,8 +471,8 @@ class vmmManager(gobject.GObject):
row.insert(ROW_NET_TX, vm.network_tx_rate())
row.insert(ROW_HINT, None)
iter = model.append(parent, row)
path = model.get_path(iter)
_iter = model.append(parent, row)
path = model.get_path(_iter)
self.rows[self.vm_row_key(vm)] = model[path]
# Expand a connection when adding a vm to it
self.window.get_widget("vm-list").expand_row(model.get_path(parent), False)
@ -495,8 +495,8 @@ class vmmManager(gobject.GObject):
row.insert(ROW_NET_RX, conn.network_rx_rate())
row.insert(ROW_NET_TX, conn.network_tx_rate())
iter = model.append(None, row)
path = model.get_path(iter)
_iter = model.append(None, row)
path = model.get_path(_iter)
self.rows[conn.get_uri()] = model[path]
def vm_removed(self, connection, uri, vmuuid):
@ -526,8 +526,8 @@ class vmmManager(gobject.GObject):
missing = True
for row in range(model.iter_n_children(parent)):
iter = model.iter_nth_child(parent, row)
if model.get_value(iter, ROW_KEY) == vm.get_uuid():
_iter = model.iter_nth_child(parent, row)
if model.get_value(_iter, ROW_KEY) == vm.get_uuid():
if wanted:
missing = False
else:
@ -712,15 +712,15 @@ class vmmManager(gobject.GObject):
self.window.get_widget("menu_host_details").set_sensitive(True)
def popup_vm_menu(self, widget, event):
tuple = widget.get_path_at_pos(int(event.x), int(event.y))
if tuple == None:
tup = widget.get_path_at_pos(int(event.x), int(event.y))
if tup == None:
return False
path = tuple[0]
path = tup[0]
model = widget.get_model()
iter = model.get_iter(path)
if model.iter_parent(iter) != None:
_iter = model.get_iter(path)
if model.iter_parent(_iter) != None:
# a vm is selected, retrieve it from the first column of the model
vm = model.get_value(iter, ROW_HANDLE)
vm = model.get_value(_iter, ROW_HANDLE)
if event.button == 3:
# Update popup menu based upon vm status
if vm.is_read_only() == True:
@ -759,7 +759,7 @@ class vmmManager(gobject.GObject):
self.vmmenu.popup(None, None, None, 0, event.time)
return False
else:
conn = model.get_value(iter, ROW_HANDLE)
conn = model.get_value(_iter, ROW_HANDLE)
if event.button == 3:
if conn.get_state() != vmmConnection.STATE_DISCONNECTED:
self.connmenu_items["create"].set_sensitive(True)
@ -1013,22 +1013,22 @@ class vmmManager(gobject.GObject):
col = vmlist.get_column(COL_NETWORK)
col.set_visible(self.config.is_vmlist_network_traffic_visible())
def cpu_usage_img(self, column, cell, model, iter, data):
if model.get_value(iter, ROW_HANDLE) is None:
def cpu_usage_img(self, column, cell, model, _iter, data):
if model.get_value(_iter, ROW_HANDLE) is None:
return
data = model.get_value(iter, ROW_HANDLE).cpu_time_vector_limit(40)
data = model.get_value(_iter, ROW_HANDLE).cpu_time_vector_limit(40)
cell.set_property('data_array', data)
def disk_io_img(self, column, cell, model, iter, data):
if model.get_value(iter, ROW_HANDLE) is None:
def disk_io_img(self, column, cell, model, _iter, data):
if model.get_value(_iter, ROW_HANDLE) is None:
return
data = model.get_value(iter, ROW_HANDLE).disk_io_vector_limit(40)
data = model.get_value(_iter, ROW_HANDLE).disk_io_vector_limit(40)
cell.set_property('data_array', data)
def network_traffic_img(self, column, cell, model, iter, data):
if model.get_value(iter, ROW_HANDLE) is None:
def network_traffic_img(self, column, cell, model, _iter, data):
if model.get_value(_iter, ROW_HANDLE) is None:
return
data = model.get_value(iter, ROW_HANDLE).network_traffic_vector_limit(40)
data = model.get_value(_iter, ROW_HANDLE).network_traffic_vector_limit(40)
cell.set_property('data_array', data)
def start_vm(self, ignore):
@ -1099,14 +1099,12 @@ class vmmManager(gobject.GObject):
model.remove(parent)
del self.rows[conn.get_uri()]
def row_expanded(self, treeview, iter, path):
conn = treeview.get_model().get_value(iter,ROW_HANDLE)
#logging.debug("Activating connection %s" % conn.get_uri())
def row_expanded(self, treeview, _iter, path):
conn = treeview.get_model().get_value(_iter, ROW_HANDLE)
conn.resume()
def row_collapsed(self, treeview, iter, path):
conn = treeview.get_model().get_value(iter,ROW_HANDLE)
#logging.debug("Deactivating connection %s" % conn.get_uri())
def row_collapsed(self, treeview, _iter, path):
conn = treeview.get_model().get_value(_iter, ROW_HANDLE)
conn.pause()
def _connect_error(self, conn, details):

View File

@ -49,8 +49,8 @@ class vmmStoragePool(gobject.GObject):
return self.active
def can_change_alloc(self):
type = self.get_type()
return (type in [virtinst.Storage.StoragePool.TYPE_LOGICAL])
typ = self.get_type()
return (typ in [virtinst.Storage.StoragePool.TYPE_LOGICAL])
def get_connection(self):
return self.connection