qubes: pep8 fixes
------------------------------------------------------------------------------- ISSUES: ------------------------------------------------------------------------------- - Some auto-corrected code (when line is too long) may still be over-indented. It can be manually chaged and it will be left alone, or is it acceptable as I am not sure how strict your rule is for under-indented lines for which context. If you want this only indented 4 spaces, I can work on it some more. [Also @ ~line:385 in new file] For example, __init__.py:382 OLD: def __contains__(self, key): return any((key == vm or key == vm.qid or key == vm.name) for vm in self) NEW: def __contains__(self, key): return any((key == vm or key == vm.qid or key == vm.name) for vm in self) - will not detect if there are more than 2 spaces between function methods ------------------------------------------------------------------------------- FIXED: ------------------------------------------------------------------------------- - Now uses the most horizontial space and does not use excessive lines when splitting a line - __init__:489 - '#' comments being indented for some lines and not others; would like no indent - Only happens if line preceeding comment ends in a ':' E128 - Fix visual indentation E128 - Fix a badly indented line [Now allows under-indented lines] E309 - Add missing blank line (after class declaration) [No longer adds it] E303 - Remove extra blank lines [Now allows 2 blank lines between function defs] [TODO: Create definition to enforce this] Conflicts: qubes/__init__.py
This commit is contained in:
parent
6504da9524
commit
0dbcdb8c0d
@ -41,7 +41,7 @@ elif os.name == 'nt':
|
|||||||
import win32file
|
import win32file
|
||||||
import pywintypes
|
import pywintypes
|
||||||
else:
|
else:
|
||||||
raise RuntimeError, "Qubes works only on POSIX or WinNT systems"
|
raise RuntimeError("Qubes works only on POSIX or WinNT systems")
|
||||||
|
|
||||||
import libvirt
|
import libvirt
|
||||||
try:
|
try:
|
||||||
@ -61,8 +61,10 @@ class QubesException(Exception):
|
|||||||
'''Exception that can be shown to the user'''
|
'''Exception that can be shown to the user'''
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class VMMConnection(object):
|
class VMMConnection(object):
|
||||||
'''Connection to Virtual Machine Manager (libvirt)'''
|
'''Connection to Virtual Machine Manager (libvirt)'''
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self._libvirt_conn = None
|
self._libvirt_conn = None
|
||||||
self._xs = None
|
self._xs = None
|
||||||
@ -77,7 +79,8 @@ class VMMConnection(object):
|
|||||||
@offline_mode.setter
|
@offline_mode.setter
|
||||||
def offline_mode(self, value):
|
def offline_mode(self, value):
|
||||||
if value and self._libvirt_conn is not None:
|
if value and self._libvirt_conn is not None:
|
||||||
raise QubesException("Cannot change offline mode while already connected")
|
raise QubesException(
|
||||||
|
"Cannot change offline mode while already connected")
|
||||||
|
|
||||||
self._offline_mode = value
|
self._offline_mode = value
|
||||||
|
|
||||||
@ -294,7 +297,8 @@ class Label(object):
|
|||||||
|
|
||||||
|
|
||||||
def __xml__(self):
|
def __xml__(self):
|
||||||
element = lxml.etree.Element('label', id='label-' + self.index, color=self.color)
|
element = lxml.etree.Element(
|
||||||
|
'label', id='label-' + self.index, color=self.color)
|
||||||
element.text = self.name
|
element.text = self.name
|
||||||
return element
|
return element
|
||||||
|
|
||||||
@ -324,7 +328,8 @@ class Label(object):
|
|||||||
.. deprecated:: 2.0
|
.. deprecated:: 2.0
|
||||||
use :py:meth:`PyQt4.QtGui.QIcon.fromTheme` and :py:attr:`icon_dispvm`
|
use :py:meth:`PyQt4.QtGui.QIcon.fromTheme` and :py:attr:`icon_dispvm`
|
||||||
'''
|
'''
|
||||||
return os.path.join(system_path['qubes_icon_dir'], self.icon_dispvm) + ".png"
|
return os.path.join(
|
||||||
|
system_path['qubes_icon_dir'], self.icon_dispvm) + ".png"
|
||||||
|
|
||||||
|
|
||||||
class VMCollection(object):
|
class VMCollection(object):
|
||||||
@ -342,7 +347,8 @@ class VMCollection(object):
|
|||||||
|
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return '<{} {!r}>'.format(self.__class__.__name__, list(sorted(self.keys())))
|
return '<{} {!r}>'.format(
|
||||||
|
self.__class__.__name__, list(sorted(self.keys())))
|
||||||
|
|
||||||
|
|
||||||
def items(self):
|
def items(self):
|
||||||
@ -394,7 +400,8 @@ class VMCollection(object):
|
|||||||
# this violates duck typing, but is needed
|
# this violates duck typing, but is needed
|
||||||
# for VMProperty to function correctly
|
# for VMProperty to function correctly
|
||||||
if not isinstance(value, qubes.vm.BaseVM):
|
if not isinstance(value, qubes.vm.BaseVM):
|
||||||
raise TypeError('{} holds only BaseVM instances'.format(self.__class__.__name__))
|
raise TypeError(
|
||||||
|
'{} holds only BaseVM instances'.format(self.__class__.__name__))
|
||||||
|
|
||||||
if not hasattr(value, 'qid'):
|
if not hasattr(value, 'qid'):
|
||||||
value.qid = self.domains.get_new_unused_qid()
|
value.qid = self.domains.get_new_unused_qid()
|
||||||
@ -435,7 +442,8 @@ class VMCollection(object):
|
|||||||
|
|
||||||
|
|
||||||
def __contains__(self, key):
|
def __contains__(self, key):
|
||||||
return any((key == vm or key == vm.qid or key == vm.name) for vm in self)
|
return any((key == vm or key == vm.qid or key == vm.name)
|
||||||
|
for vm in self)
|
||||||
|
|
||||||
|
|
||||||
def __len__(self):
|
def __len__(self):
|
||||||
@ -536,7 +544,8 @@ class property(object):
|
|||||||
load_stage=2, order=0, save_via_ref=False, doc=None):
|
load_stage=2, order=0, save_via_ref=False, doc=None):
|
||||||
self.__name__ = name
|
self.__name__ = name
|
||||||
self._setter = setter
|
self._setter = setter
|
||||||
self._saver = saver if saver is not None else (lambda self, prop, value: str(value))
|
self._saver = saver if saver is not None else (
|
||||||
|
lambda self, prop, value: str(value))
|
||||||
self._type = type
|
self._type = type
|
||||||
self._default = default
|
self._default = default
|
||||||
self.order = order
|
self.order = order
|
||||||
@ -560,7 +569,8 @@ class property(object):
|
|||||||
|
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
if self._default is self._NO_DEFAULT:
|
if self._default is self._NO_DEFAULT:
|
||||||
raise AttributeError('property {!r} not set'.format(self.__name__))
|
raise AttributeError(
|
||||||
|
'property {!r} not set'.format(self.__name__))
|
||||||
elif isinstance(self._default, collections.Callable):
|
elif isinstance(self._default, collections.Callable):
|
||||||
return self._default(instance)
|
return self._default(instance)
|
||||||
else:
|
else:
|
||||||
@ -584,14 +594,16 @@ class property(object):
|
|||||||
value = self._type(value)
|
value = self._type(value)
|
||||||
|
|
||||||
if has_oldvalue:
|
if has_oldvalue:
|
||||||
instance.fire_event_pre('property-pre-set:' + self.__name__, value, oldvalue)
|
instance.fire_event_pre(
|
||||||
|
'property-pre-set:' + self.__name__, value, oldvalue)
|
||||||
else:
|
else:
|
||||||
instance.fire_event_pre('property-pre-set:' + self.__name__, value)
|
instance.fire_event_pre('property-pre-set:' + self.__name__, value)
|
||||||
|
|
||||||
instance._init_property(self, value)
|
instance._init_property(self, value)
|
||||||
|
|
||||||
if has_oldvalue:
|
if has_oldvalue:
|
||||||
instance.fire_event('property-set:' + self.__name__, value, oldvalue)
|
instance.fire_event(
|
||||||
|
'property-set:' + self.__name__, value, oldvalue)
|
||||||
else:
|
else:
|
||||||
instance.fire_event('property-set:' + self.__name__, value)
|
instance.fire_event('property-set:' + self.__name__, value)
|
||||||
|
|
||||||
@ -692,9 +704,12 @@ class property(object):
|
|||||||
'''
|
'''
|
||||||
|
|
||||||
lcvalue = value.lower()
|
lcvalue = value.lower()
|
||||||
if lcvalue in ('0', 'no', 'false'): return False
|
if lcvalue in ('0', 'no', 'false'):
|
||||||
if lcvalue in ('1', 'yes', 'true'): return True
|
return False
|
||||||
raise ValueError('Invalid literal for boolean property: {!r}'.format(value))
|
if lcvalue in ('1', 'yes', 'true'):
|
||||||
|
return True
|
||||||
|
raise ValueError(
|
||||||
|
'Invalid literal for boolean property: {!r}'.format(value))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -765,7 +780,8 @@ class PropertyHolder(qubes.events.Emitter):
|
|||||||
if load_stage is not None:
|
if load_stage is not None:
|
||||||
props = set(prop for prop in props
|
props = set(prop for prop in props
|
||||||
if prop.load_stage == load_stage)
|
if prop.load_stage == load_stage)
|
||||||
return sorted(props, key=lambda prop: (prop.load_stage, prop.order, prop.__name__))
|
return sorted(props,
|
||||||
|
key=lambda prop: (prop.load_stage, prop.order, prop.__name__))
|
||||||
|
|
||||||
|
|
||||||
def _init_property(self, prop, value):
|
def _init_property(self, prop, value):
|
||||||
@ -825,7 +841,8 @@ class PropertyHolder(qubes.events.Emitter):
|
|||||||
'''
|
'''
|
||||||
|
|
||||||
self.events_enabled = False
|
self.events_enabled = False
|
||||||
all_names = set(prop.__name__ for prop in self.get_props_list(load_stage))
|
all_names = set(
|
||||||
|
prop.__name__ for prop in self.get_props_list(load_stage))
|
||||||
for node in self.xml.xpath('./properties/property'):
|
for node in self.xml.xpath('./properties/property'):
|
||||||
name = node.get('name')
|
name = node.get('name')
|
||||||
value = node.get('ref') or node.text
|
value = node.get('ref') or node.text
|
||||||
@ -852,8 +869,9 @@ class PropertyHolder(qubes.events.Emitter):
|
|||||||
|
|
||||||
for prop in self.get_props_list():
|
for prop in self.get_props_list():
|
||||||
try:
|
try:
|
||||||
value = getattr(self, (prop.__name__ if with_defaults else prop._attr_name))
|
value = getattr(
|
||||||
except AttributeError, e:
|
self, (prop.__name__ if with_defaults else prop._attr_name))
|
||||||
|
except AttributeError as e:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -1033,7 +1051,8 @@ class Qubes(PropertyHolder):
|
|||||||
|
|
||||||
|
|
||||||
def __init__(self, store='/var/lib/qubes/qubes.xml'):
|
def __init__(self, store='/var/lib/qubes/qubes.xml'):
|
||||||
self._extensions = set(ext(self) for ext in qubes.ext.Extension.register.values())
|
self._extensions = set(ext(self)
|
||||||
|
for ext in qubes.ext.Extension.register.values())
|
||||||
|
|
||||||
#: collection of all VMs managed by this Qubes instance
|
#: collection of all VMs managed by this Qubes instance
|
||||||
self.domains = VMCollection()
|
self.domains = VMCollection()
|
||||||
@ -1054,7 +1073,8 @@ class Qubes(PropertyHolder):
|
|||||||
except IOError:
|
except IOError:
|
||||||
self._init()
|
self._init()
|
||||||
|
|
||||||
super(Qubes, self).__init__(xml=lxml.etree.parse(self.qubes_store_file))
|
super(Qubes, self).__init__(
|
||||||
|
xml=lxml.etree.parse(self.qubes_store_file))
|
||||||
|
|
||||||
|
|
||||||
def _open_store(self):
|
def _open_store(self):
|
||||||
@ -1163,7 +1183,7 @@ class Qubes(PropertyHolder):
|
|||||||
lxml.etree.ElementTree(self.__xml__()).write(
|
lxml.etree.ElementTree(self.__xml__()).write(
|
||||||
self._storefd, encoding='utf-8', pretty_print=True)
|
self._storefd, encoding='utf-8', pretty_print=True)
|
||||||
self._storefd.sync()
|
self._storefd.sync()
|
||||||
os.chmod(self._store, 0660)
|
os.chmod(self._store, 0o660)
|
||||||
os.chown(self._store, -1, grp.getgrnam('qubes').gr_gid)
|
os.chown(self._store, -1, grp.getgrnam('qubes').gr_gid)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user