diff --git a/qubes/__init__.py b/qubes/__init__.py index 9ce60735..b8f4fa5f 100644 --- a/qubes/__init__.py +++ b/qubes/__init__.py @@ -485,7 +485,7 @@ class VMCollection(object): def get_vms_connected_to(self, netvm): - new_vms = set([netvm]) + new_vms = set([self[netvm]]) dependent_vms = set() # Dependency resolving only makes sense on NetVM (or derivative) @@ -962,7 +962,7 @@ class PropertyHolder(qubes.events.Emitter): for prop in self.proplist(): try: # pylint: disable=protected-access - self._init_property(self, prop, getattr(src, prop._attr_name)) + self._init_property(prop, getattr(src, prop._attr_name)) except AttributeError: continue @@ -1211,11 +1211,11 @@ class Qubes(PropertyHolder): self, None, qid=0, name='dom0')) # stage 3: load global properties - self.load_properties(self.xml, load_stage=3) + self.load_properties(load_stage=3) # stage 4: fill all remaining VM properties for vm in self.domains: - vm.load_properties(None, load_stage=4) + vm.load_properties(load_stage=4) # stage 5: misc fixups @@ -1335,8 +1335,6 @@ class Qubes(PropertyHolder): if self.default_template == vm: del self.default_template - return super(QubesVmCollection, self).pop(qid) - @qubes.events.handler('property-pre-set:clockvm') def on_property_pre_set_clockvm(self, event, name, newvalue, oldvalue=None): @@ -1349,7 +1347,9 @@ class Qubes(PropertyHolder): newvalue.services['ntpd'] = False - @qubes.events.handler('property-pre-set:default_netvm') + @qubes.events.handler( + 'property-pre-set:default_netvm', + 'property-pre-set:default_fw_netvm') def on_property_pre_set_default_netvm(self, event, name, newvalue, oldvalue=None): # pylint: disable=unused-argument,invalid-name diff --git a/qubes/dochelpers.py b/qubes/dochelpers.py index 188e3afc..2120dfb3 100644 --- a/qubes/dochelpers.py +++ b/qubes/dochelpers.py @@ -58,7 +58,7 @@ def fetch_ticket_info(uri): for row in list(reader)[:2]))) -def ticket(name, rawtext, text, lineno, inliner, options={}, content=[]): +def ticket(name, rawtext, text, lineno, inliner, options=None, content=None): '''Link to qubes ticket :param str name: The role name used in the document @@ -71,6 +71,9 @@ def ticket(name, rawtext, text, lineno, inliner, options={}, content=[]): :param content: The directive content for customisation ''' # pylint: disable=unused-argument + if options is None: + options = {} + ticketno = text.lstrip('#') if not ticket.isdigit(): msg = inliner.reporter.error( diff --git a/qubes/events.py b/qubes/events.py index 236ec9ef..c773f3c7 100644 --- a/qubes/events.py +++ b/qubes/events.py @@ -69,7 +69,7 @@ def ishandler(obj): class EmitterMeta(type): '''Metaclass for :py:class:`Emitter`''' def __init__(cls, name, bases, dict_): - super(type, cls).__init__(name, bases, dict_) + super(EmitterMeta, cls).__init__(name, bases, dict_) cls.__handlers__ = collections.defaultdict(set) try: diff --git a/qubes/plugins.py b/qubes/plugins.py index 18e4e98d..618237bf 100644 --- a/qubes/plugins.py +++ b/qubes/plugins.py @@ -33,6 +33,7 @@ import os class Plugin(type): '''Base metaclass for plugins''' def __init__(cls, name, bases, dict_): + super(Plugin, cls).__init__(name, bases, dict_) # pylint: disable=unused-argument if hasattr(cls, 'register'): cls.register[cls.__name__] = cls diff --git a/qubes/storage/__init__.py b/qubes/storage/__init__.py index d889e961..8de21d23 100644 --- a/qubes/storage/__init__.py +++ b/qubes/storage/__init__.py @@ -100,7 +100,8 @@ class VMStorage(object): def get_config_params(self): raise NotImplementedError() - def _copy_file(self, source, destination): + @staticmethod + def _copy_file(source, destination): '''Effective file copy, preserving sparse files etc. ''' # TODO: Windows support @@ -142,9 +143,9 @@ class VMStorage(object): self.vm.log.info('Creating directory: {0}'.format(self.vm.dir_path)) os.mkdir(self.vmdir) - self.create_on_disk_private_img(verbose, source_template) - self.create_on_disk_root_img(verbose, source_template) - self.reset_volatile_storage(verbose, source_template) + self.create_on_disk_private_img(source_template) + self.create_on_disk_root_img(source_template) + self.reset_volatile_storage(source_template) os.umask(old_umask) @@ -166,7 +167,8 @@ class VMStorage(object): # XXX which modules? -woju - def rename(self, newpath, oldpath): + @staticmethod + def rename(newpath, oldpath): '''Move storage directory, most likely during domain's rename. .. note:: diff --git a/qubes/tests/__init__.py b/qubes/tests/__init__.py index 01a94680..bb493f5f 100644 --- a/qubes/tests/__init__.py +++ b/qubes/tests/__init__.py @@ -138,7 +138,7 @@ class QubesTestCase(unittest.TestCase): self.assertEqual(xml1.get(key), xml2.get(key)) - def assertEventFired(self, emitter, event, args=[], kwargs=[]): + def assertEventFired(self, emitter, event, args=None, kwargs=None): '''Check whether event was fired on given emitter and fail if it did not. @@ -154,9 +154,9 @@ class QubesTestCase(unittest.TestCase): for ev, ev_args, ev_kwargs in emitter.fired_events: if ev != event: continue - if any(i not in ev_args for i in args): + if args is not None and any(i not in ev_args for i in args): continue - if any(i not in ev_kwargs for i in kwargs): + if kwargs is not None and any(i not in ev_kwargs for i in kwargs): continue return @@ -164,7 +164,7 @@ class QubesTestCase(unittest.TestCase): self.fail('event {!r} did not fire on {!r}'.format(event, emitter)) - def assertEventNotFired(self, emitter, event, args=[], kwargs=[]): + def assertEventNotFired(self, emitter, event, args=None, kwargs=None): '''Check whether event was fired on given emitter. Fail if it did. :param emitter: emitter which is being checked @@ -179,9 +179,9 @@ class QubesTestCase(unittest.TestCase): for ev, ev_args, ev_kwargs in emitter.fired_events: if ev != event: continue - if any(i not in ev_args for i in args): + if args is not None and any(i not in ev_args for i in args): continue - if any(i not in ev_kwargs for i in kwargs): + if kwargs is not None and any(i not in ev_kwargs for i in kwargs): continue self.fail('event {!r} did fire on {!r}'.format(event, emitter)) diff --git a/qubes/tests/vm/adminvm.py b/qubes/tests/vm/adminvm.py index 8bc3e316..655812ba 100644 --- a/qubes/tests/vm/adminvm.py +++ b/qubes/tests/vm/adminvm.py @@ -36,12 +36,13 @@ class TestVMM(object): class TestHost(object): # pylint: disable=too-few-public-methods - def __init__(self, offline_mode=False): + def __init__(self): self.memory_total = 1000 # this probably can be shared and not as dummy as is class TestApp(qubes.tests.TestEmitter): def __init__(self): + super(TestApp, self).__init__() self.vmm = TestVMM() self.host = TestHost() diff --git a/qubes/vm/__init__.py b/qubes/vm/__init__.py index 3dbabe0f..2301c212 100644 --- a/qubes/vm/__init__.py +++ b/qubes/vm/__init__.py @@ -141,21 +141,21 @@ class BaseVM(qubes.PropertyHolder): __metaclass__ = BaseVMMeta - def __init__(self, app, xml, load_stage=2, services={}, devices=None, - tags={}, *args, **kwargs): + def __init__(self, app, xml, services=None, devices=None, tags=None, + *args, **kwargs): # pylint: disable=redefined-outer-name #: mother :py:class:`qubes.Qubes` object self.app = app #: dictionary of services that are run on this domain - self.services = services + self.services = services or {} #: :py:class`DeviceManager` object keeping devices that are attached to #: this domain self.devices = DeviceManager(self) if devices is None else devices #: user-specified tags - self.tags = tags + self.tags = tags or {} self.events_enabled = False all_names = set(prop.__name__ @@ -535,7 +535,8 @@ class BaseVM(qubes.PropertyHolder): def has_firewall(self): return os.path.exists(self.firewall_conf) - def get_firewall_defaults(self): + @staticmethod + def get_firewall_defaults(): return { 'rules': list(), 'allow': True, diff --git a/qubes/vm/qubesvm.py b/qubes/vm/qubesvm.py index c176f382..0547e67d 100644 --- a/qubes/vm/qubesvm.py +++ b/qubes/vm/qubesvm.py @@ -357,7 +357,7 @@ class QubesVM(qubes.vm.BaseVM): @property def uses_custom_config(self): '''True if this machine has config in non-standard place.''' - return not self.property_is_default(self, 'conf_file') + return not self.property_is_default('conf_file') # return self.conf_file != self.storage.abspath(self.name + '.conf') @property @@ -585,7 +585,7 @@ class QubesVM(qubes.vm.BaseVM): self.dir_path = self.dir_path.replace( '/{}/', '/{}/'.format(old_name, new_name)) - if self.property_is_default(self, 'conf_file'): + if self.property_is_default('conf_file'): new_conf = os.path.join( self.dir_path, _default_conf_file(self, old_name)) old_conf = os.path.join( @@ -746,14 +746,14 @@ class QubesVM(qubes.vm.BaseVM): if self._start_guid_first and start_guid and not preparing_dvm \ and os.path.exists('/var/run/shm.id'): - self.start_guid(notify_function=notify_function) + self.start_guid() if not preparing_dvm: - self.start_qrexec_daemon(notify_function=notify_function) + self.start_qrexec_daemon() if start_guid and not preparing_dvm \ and os.path.exists('/var/run/shm.id'): - self.start_guid(notify_function=notify_function) + self.start_guid() def shutdown(self): @@ -881,7 +881,7 @@ class QubesVM(qubes.vm.BaseVM): if gui and os.getenv("DISPLAY") is not None \ and not self.is_guid_running(): - self.start_guid(verbose=verbose, notify_function=notify_function) + self.start_guid() args = [qubes.config.system_path['qrexec_client_path'], '-d', str(self.name), @@ -957,7 +957,7 @@ class QubesVM(qubes.vm.BaseVM): - def start_guid(self, extra_guid_args=[]): + def start_guid(self, extra_guid_args=None): '''Launch gui daemon. GUI daemon securely displays windows from domain. @@ -972,7 +972,8 @@ class QubesVM(qubes.vm.BaseVM): '-c', self.label.color, '-i', self.label.icon_path, '-l', str(self.label.index)] - guid_cmd += extra_guid_args + if extra_guid_args is not None: + guid_cmd += extra_guid_args if self.debug: guid_cmd += ['-v', '-v'] @@ -1059,7 +1060,7 @@ class QubesVM(qubes.vm.BaseVM): source_template = self.template assert source_template is not None - self.storage.create_on_disk(verbose, source_template) + self.storage.create_on_disk(source_template) if self.updateable: kernels_dir = source_template.kernels_dir