qubes: Fix comments accross the code

Acknowledgement:
This commit is a result of core3 review by Marek.
This commit is contained in:
Wojtek Porczyk 2015-01-13 15:40:43 +01:00
parent 2e1696cb16
commit 92eca8edb9
5 changed files with 12 additions and 17 deletions

View File

@ -547,7 +547,6 @@ class property(object):
def __get__(self, instance, owner): def __get__(self, instance, owner):
# sys.stderr.write('{!r}.__get__({}, {!r})\n'.format(self.__name__, hex(id(instance)), owner))
if instance is None: if instance is None:
return self return self
@ -556,12 +555,10 @@ class property(object):
raise AttributeError( raise AttributeError(
'qubes.property should be used on qubes.PropertyHolder instances only') 'qubes.property should be used on qubes.PropertyHolder instances only')
# sys.stderr.write(' __get__ try\n')
try: try:
return getattr(instance, self._attr_name) return getattr(instance, self._attr_name)
except AttributeError: except AttributeError:
# sys.stderr.write(' __get__ except\n')
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):
@ -761,7 +758,6 @@ class PropertyHolder(qubes.events.Emitter):
:type load_stage: :py:func:`int` or :py:obj:`None` :type load_stage: :py:func:`int` or :py:obj:`None`
''' '''
# sys.stderr.write('{!r}.get_props_list(load_stage={})\n'.format('self', load_stage))
props = set() props = set()
for class_ in cls.__mro__: for class_ in cls.__mro__:
props.update(prop for prop in class_.__dict__.values() props.update(prop for prop in class_.__dict__.values()
@ -769,7 +765,6 @@ 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)
# sys.stderr.write(' props={!r}\n'.format(props))
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__))
@ -829,16 +824,12 @@ class PropertyHolder(qubes.events.Emitter):
:param lxml.etree._Element xml: XML node reference :param lxml.etree._Element xml: XML node reference
''' '''
# sys.stderr.write('<{}>.load_properties(load_stage={}) xml={!r}\n'.format(hex(id(self)), load_stage, self.xml))
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))
# sys.stderr.write(' all_names={!r}\n'.format(all_names))
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
# sys.stderr.write(' load_properties name={!r} value={!r}\n'.format(name, value))
if not name in all_names: if not name in all_names:
raise AttributeError( raise AttributeError(
'No property {!r} found in {!r}'.format( 'No property {!r} found in {!r}'.format(
@ -848,7 +839,6 @@ class PropertyHolder(qubes.events.Emitter):
self.events_enabled = True self.events_enabled = True
self.fire_event('property-loaded') self.fire_event('property-loaded')
# sys.stderr.write(' load_properties return\n')
def save_properties(self, with_defaults=False): def save_properties(self, with_defaults=False):
@ -857,7 +847,6 @@ class PropertyHolder(qubes.events.Emitter):
:param bool with_defaults: If :py:obj:`True`, then it also includes properties which were not set explicite, but have default values filled. :param bool with_defaults: If :py:obj:`True`, then it also includes properties which were not set explicite, but have default values filled.
''' '''
# sys.stderr.write('{!r}.save_properties(with_defaults={})\n'.format(self, with_defaults))
properties = lxml.etree.Element('properties') properties = lxml.etree.Element('properties')
@ -865,7 +854,6 @@ class PropertyHolder(qubes.events.Emitter):
try: try:
value = getattr(self, (prop.__name__ if with_defaults else prop._attr_name)) value = getattr(self, (prop.__name__ if with_defaults else prop._attr_name))
except AttributeError, e: except AttributeError, e:
# sys.stderr.write('AttributeError: {!s}\n'.format(e))
continue continue
try: try:

View File

@ -4,7 +4,7 @@
# The Qubes OS Project, http://www.qubes-os.org # The Qubes OS Project, http://www.qubes-os.org
# #
# Copyright (C) 2010 Joanna Rutkowska <joanna@invisiblethingslab.com> # Copyright (C) 2010 Joanna Rutkowska <joanna@invisiblethingslab.com>
# Copyright (C) 2014 Wojtek Porczyk <joanna@invisiblethingslab.com> # Copyright (C) 2014 Wojtek Porczyk <woju@invisiblethingslab.com>
# #
# This program is free software; you can redistribute it and/or # This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License # modify it under the terms of the GNU General Public License

View File

@ -23,8 +23,7 @@
# #
# FIXME: should be outside of QubesVM? def get_timezone():
def get_timezone(self):
# fc18 # fc18
if os.path.islink('/etc/localtime'): if os.path.islink('/etc/localtime'):
return '/'.join(os.readlink('/etc/localtime').split('/')[-2:]) return '/'.join(os.readlink('/etc/localtime').split('/')[-2:])

View File

@ -586,9 +586,13 @@ class BaseVM(qubes.PropertyHolder):
conf["rules"].append(rule) conf["rules"].append(rule)
except EnvironmentError as err: except EnvironmentError as err:
# problem accessing file, like ENOTFOUND, EPERM or sth
# return default config
return conf return conf
except (xml.parsers.expat.ExpatError, except (xml.parsers.expat.ExpatError,
ValueError, LookupError) as err: ValueError, LookupError) as err:
# config is invalid
print("{0}: load error: {1}".format( print("{0}: load error: {1}".format(
os.path.basename(sys.argv[0]), err)) os.path.basename(sys.argv[0]), err))
return None return None

View File

@ -416,7 +416,7 @@ class QubesVM(qubes.vm.BaseVM):
self.maxmem = total_mem_mb/2 self.maxmem = total_mem_mb/2
# Linux specific cap: max memory can't scale beyond 10.79*init_mem # Linux specific cap: max memory can't scale beyond 10.79*init_mem
# XXX what?! -woju # see https://groups.google.com/forum/#!topic/qubes-devel/VRqkFj1IOtA
if self.maxmem > self.memory * 10: if self.maxmem > self.memory * 10:
self.maxmem = self.memory * 10 self.maxmem = self.memory * 10
@ -447,7 +447,6 @@ class QubesVM(qubes.vm.BaseVM):
# event handlers # event handlers
# #
@qubes.events.handler('property-set:label') @qubes.events.handler('property-set:label')
def on_property_set_label(self, event, name, new_label, old_label=None): def on_property_set_label(self, event, name, new_label, old_label=None):
if self.icon_path: if self.icon_path:
@ -557,6 +556,7 @@ class QubesVM(qubes.vm.BaseVM):
return return
try: try:
# TODO: libvirt-ise
subprocess.check_call(['sudo', system_path["qubes_pciback_cmd"], pci]) subprocess.check_call(['sudo', system_path["qubes_pciback_cmd"], pci])
subprocess.check_call(['sudo', 'xl', 'pci-attach', str(self.xid), pci]) subprocess.check_call(['sudo', 'xl', 'pci-attach', str(self.xid), pci])
except Exception as e: except Exception as e:
@ -569,6 +569,7 @@ class QubesVM(qubes.vm.BaseVM):
if not self.is_running(): if not self.is_running():
return return
# TODO: libvirt-ise
p = subprocess.Popen(['xl', 'pci-list', str(self.xid)], p = subprocess.Popen(['xl', 'pci-list', str(self.xid)],
stdout=subprocess.PIPE) stdout=subprocess.PIPE)
result = p.communicate() result = p.communicate()
@ -802,6 +803,8 @@ class QubesVM(qubes.vm.BaseVM):
args += ["-t"] args += ["-t"]
if os.isatty(sys.stderr.fileno()): if os.isatty(sys.stderr.fileno()):
args += ["-T"] args += ["-T"]
# TODO: QSB#13
if passio: if passio:
if os.name == 'nt': if os.name == 'nt':
# wait for qrexec-client to exit, otherwise client is not properly attached to console # wait for qrexec-client to exit, otherwise client is not properly attached to console
@ -854,6 +857,7 @@ class QubesVM(qubes.vm.BaseVM):
source = 'dom0' if source is None else self.app.domains[source].name source = 'dom0' if source is None else self.app.domains[source].name
# XXX TODO FIXME this looks bad...
if input: if input:
return self.run("QUBESRPC %s %s" % (service, source), return self.run("QUBESRPC %s %s" % (service, source),
localcmd="echo %s" % input, user=user, wait=True) localcmd="echo %s" % input, user=user, wait=True)