diff --git a/qubes/__init__.py b/qubes/__init__.py index 6b7cd051..134827b5 100644 --- a/qubes/__init__.py +++ b/qubes/__init__.py @@ -1,6 +1,3 @@ -#!/usr/bin/python2 -O -# vim: fileencoding=utf-8 - # # The Qubes OS Project, https://www.qubes-os.org/ # @@ -30,9 +27,7 @@ Qubes OS :copyright: © 2010-2015 Invisible Things Lab ''' -from __future__ import absolute_import - -import __builtin__ +import builtins import collections import os import os.path @@ -110,7 +105,7 @@ class Label(object): self.name) - @__builtin__.property + @builtins.property def icon_path(self): '''Icon path @@ -121,7 +116,7 @@ class Label(object): self.icon) + ".png" - @__builtin__.property + @builtins.property def icon_path_dispvm(self): '''Icon path @@ -360,7 +355,7 @@ class property(object): # pylint: disable=redefined-builtin,invalid-name :py:obj:`True`. ''' # pylint: disable=bad-staticmethod-argument,unused-argument - if isinstance(value, basestring): + if isinstance(value, str): lcvalue = value.lower() if lcvalue in ('0', 'no', 'false', 'off'): return False diff --git a/qubes/app.py b/qubes/app.py index 2b0f8c5b..6ff44673 100644 --- a/qubes/app.py +++ b/qubes/app.py @@ -1,6 +1,3 @@ -#!/usr/bin/python2 -O -# vim: fileencoding=utf-8 - # # The Qubes OS Project, https://www.qubes-os.org/ # @@ -66,7 +63,6 @@ import qubes.vm.adminvm # pylint: disable=wrong-import-position import qubes.vm.qubesvm # pylint: disable=wrong-import-position import qubes.vm.templatevm # pylint: disable=wrong-import-position - class VirDomainWrapper(object): # pylint: disable=too-few-public-methods @@ -241,7 +237,7 @@ class QubesHost(object): # pylint: disable=unused-variable (model, memory, cpus, mhz, nodes, socket, cores, threads) = \ self.app.vmm.libvirt_conn.getInfo() - self._total_mem = long(memory) * 1024 + self._total_mem = int(memory) * 1024 self._no_cpus = cpus self.app.log.debug('QubesHost: no_cpus={} memory_total={}'.format( @@ -283,7 +279,7 @@ class QubesHost(object): self._physinfo = self.app.xc.physinfo() except AttributeError: raise NotImplementedError('This function requires Xen hypervisor') - return long(self._physinfo['free_memory']) + return int(self._physinfo['free_memory']) def measure_cpu_usage(self, previous_time=None, previous=None, @@ -329,7 +325,7 @@ class QubesHost(object): current[vm['domid']]['cpu_usage'] = ( float(current[vm['domid']]['cpu_time'] - previous[vm['domid']]['cpu_time']) / - long(1000 ** 3) / (current_time - previous_time) * 100) + 1000 ** 3 / (current_time - previous_time) * 100) if current[vm['domid']]['cpu_usage'] < 0: # VM has been rebooted current[vm['domid']]['cpu_usage'] = 0 @@ -428,7 +424,7 @@ class VMCollection(object): if isinstance(key, int): return self._dict[key] - if isinstance(key, basestring): + if isinstance(key, str): for vm in self: if vm.name == key: return vm @@ -682,7 +678,7 @@ class Qubes(qubes.PropertyHolder): try: self.pools[name] = self._get_pool(**node.attrib) except qubes.exc.QubesException as e: - self.log.error(e.message) + self.log.error(str(e)) # stage 2: load VMs for node in self.xml.xpath('./domains/domain'): @@ -783,7 +779,7 @@ class Qubes(qubes.PropertyHolder): lxml.etree.ElementTree(self.__xml__()).write( fh_new, encoding='utf-8', pretty_print=True) fh_new.flush() - os.chmod(fh_new.name, 0660) + os.chmod(fh_new.name, 0o660) os.chown(fh_new.name, -1, grp.getgrnam('qubes').gr_gid) os.rename(fh_new.name, self._store) diff --git a/qubes/backup.py b/qubes/backup.py index b57ece9f..61c70630 100644 --- a/qubes/backup.py +++ b/qubes/backup.py @@ -1,5 +1,3 @@ -#!/usr/bin/python -# -*- coding: utf-8 -*- # # The Qubes OS Project, http://www.qubes-os.org # @@ -962,7 +960,7 @@ class ExtractWorker2(Process): pass process.wait() self.log.error("ERROR: " + unicode(e)) - raise e, None, exc_traceback + raise def handle_dir_relocations(self, dirname): ''' Relocate files in given director when it's already extracted diff --git a/qubes/config.py b/qubes/config.py index f99df8a8..2596e239 100644 --- a/qubes/config.py +++ b/qubes/config.py @@ -1,6 +1,3 @@ -#!/usr/bin/python2 -O -# vim: fileencoding=utf-8 - # # The Qubes OS Project, https://www.qubes-os.org/ # diff --git a/qubes/core2migration.py b/qubes/core2migration.py index 5251276e..831e9b0e 100644 --- a/qubes/core2migration.py +++ b/qubes/core2migration.py @@ -1,5 +1,3 @@ -#!/usr/bin/python -# -*- coding: utf-8 -*- # # The Qubes OS Project, http://www.qubes-os.org # diff --git a/qubes/devices.py b/qubes/devices.py index 329ef36e..b0635cb8 100644 --- a/qubes/devices.py +++ b/qubes/devices.py @@ -1,6 +1,3 @@ -#!/usr/bin/python2 -O -# vim: fileencoding=utf-8 - # # The Qubes OS Project, https://www.qubes-os.org/ # @@ -47,6 +44,7 @@ Such extension should provide: - handle `device-list-attached:class` event - list currently attached devices to this domain ''' + import qubes.utils diff --git a/qubes/dochelpers.py b/qubes/dochelpers.py index 18731d48..00504f42 100644 --- a/qubes/dochelpers.py +++ b/qubes/dochelpers.py @@ -1,6 +1,3 @@ -#!/usr/bin/python2 -O -# vim: fileencoding=utf-8 - # # The Qubes OS Project, https://www.qubes-os.org/ # @@ -29,11 +26,12 @@ particularly our custom Sphinx extension. ''' import argparse +import io import json import os import re -import StringIO -import urllib2 +import urllib.error +import urllib.request import docutils import docutils.nodes @@ -64,10 +62,10 @@ def fetch_ticket_info(app, number): :param app: Sphinx app object :param str number: number of the ticket, without # :rtype: mapping - :raises: urllib2.HTTPError + :raises: urllib.error.HTTPError ''' - response = urllib2.urlopen(urllib2.Request( + response = urllib.request.urlopen(urllib.request.Request( app.config.ticket_base_uri.format(number=number), headers={ 'Accept': 'application/vnd.github.v3+json', @@ -99,7 +97,7 @@ def ticket(name, rawtext, text, lineno, inliner, options=None, content=None): try: info = fetch_ticket_info(inliner.document.settings.env.app, ticketno) - except urllib2.HTTPError, e: + except urllib.error.HTTPError as e: msg = inliner.reporter.error( 'Error while fetching ticket info: {!s}'.format(e), line=lineno) prb = inliner.problematic(rawtext, rawtext, msg) @@ -167,7 +165,7 @@ def make_rst_section(heading, char): def prepare_manpage(command): parser = qubes.tools.get_parser_for_command(command) - stream = StringIO.StringIO() + stream = io.StringIO() stream.write('.. program:: {}\n\n'.format(command)) stream.write(make_rst_section( ':program:`{}` -- {}'.format(command, parser.description), '=')) diff --git a/qubes/events.py b/qubes/events.py index 3c94c96a..151fa7a1 100644 --- a/qubes/events.py +++ b/qubes/events.py @@ -1,6 +1,3 @@ -#!/usr/bin/python2 -O -# vim: fileencoding=utf-8 - # # The Qubes OS Project, https://www.qubes-os.org/ # @@ -94,15 +91,13 @@ class EmitterMeta(type): cls.add_handler(event, attr) -class Emitter(object): +class Emitter(object, metaclass=EmitterMeta): '''Subject that can emit events. By default all events are disabled not to interfere with loading from XML. To enable event dispatch, set :py:attr:`events_enabled` to :py:obj:`True`. ''' - __metaclass__ = EmitterMeta - def __init__(self, *args, **kwargs): super(Emitter, self).__init__(*args, **kwargs) if not hasattr(self, 'events_enabled'): diff --git a/qubes/exc.py b/qubes/exc.py index 58d6df20..c7bf27b5 100644 --- a/qubes/exc.py +++ b/qubes/exc.py @@ -1,6 +1,3 @@ -#!/usr/bin/python2 -O -# vim: fileencoding=utf-8 - # # The Qubes OS Project, https://www.qubes-os.org/ # diff --git a/qubes/ext/__init__.py b/qubes/ext/__init__.py index 8d4c7804..c02011b2 100644 --- a/qubes/ext/__init__.py +++ b/qubes/ext/__init__.py @@ -1,6 +1,3 @@ -#!/usr/bin/python2 -O -# vim: fileencoding=utf-8 - # # The Qubes OS Project, https://www.qubes-os.org/ # diff --git a/qubes/ext/gui.py b/qubes/ext/gui.py index a855d344..77e5d91f 100644 --- a/qubes/ext/gui.py +++ b/qubes/ext/gui.py @@ -1,6 +1,3 @@ -#!/usr/bin/env python -# vim: fileencoding=utf-8 - # # The Qubes OS Project, https://www.qubes-os.org/ # diff --git a/qubes/ext/pci.py b/qubes/ext/pci.py index bb6c23a5..5aaa60ab 100644 --- a/qubes/ext/pci.py +++ b/qubes/ext/pci.py @@ -1,5 +1,3 @@ -#!/usr/bin/python2 -O -# vim: fileencoding=utf-8 # # The Qubes OS Project, https://www.qubes-os.org/ # @@ -20,6 +18,7 @@ # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # + import os import re import subprocess diff --git a/qubes/ext/qubesmanager.py b/qubes/ext/qubesmanager.py index e22b30a5..2f063806 100644 --- a/qubes/ext/qubesmanager.py +++ b/qubes/ext/qubesmanager.py @@ -1,6 +1,3 @@ -#!/usr/bin/python2 -O -# vim: fileencoding=utf-8 - # # The Qubes OS Project, https://www.qubes-os.org/ # diff --git a/qubes/ext/r3compatibility.py b/qubes/ext/r3compatibility.py index 5aa8f335..919493db 100644 --- a/qubes/ext/r3compatibility.py +++ b/qubes/ext/r3compatibility.py @@ -1,5 +1,3 @@ -#!/usr/bin/python2 -O -# vim: fileencoding=utf-8 # # The Qubes OS Project, https://www.qubes-os.org/ # @@ -21,6 +19,7 @@ # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # + import datetime import qubes.ext import qubes.firewall diff --git a/qubes/firewall.py b/qubes/firewall.py index dde01403..cad16ff9 100644 --- a/qubes/firewall.py +++ b/qubes/firewall.py @@ -1,6 +1,5 @@ -#!/usr/bin/python2 -O -# vim: fileencoding=utf-8 # pylint: disable=too-few-public-methods + # # The Qubes OS Project, https://www.qubes-os.org/ # @@ -21,6 +20,7 @@ # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # + import datetime import subprocess @@ -54,7 +54,7 @@ class RuleChoice(RuleOption): super(RuleChoice, self).__init__(value) self.allowed_values = \ [v for k, v in self.__class__.__dict__.items() - if not k.startswith('__') and isinstance(v, basestring) and + if not k.startswith('__') and isinstance(v, str) and not v.startswith('__')] if value not in self.allowed_values: raise ValueError(value) @@ -457,7 +457,7 @@ class Firewall(object): try: old_umask = os.umask(0o002) - with open(firewall_conf, 'w') as firewall_xml: + with open(firewall_conf, 'wb') as firewall_xml: xml_tree.write(firewall_xml, encoding="UTF-8", pretty_print=True) os.umask(old_umask) diff --git a/qubes/log.py b/qubes/log.py index 0292ee31..1882502b 100644 --- a/qubes/log.py +++ b/qubes/log.py @@ -1,6 +1,3 @@ -#!/usr/bin/python2 -O -# vim: fileencoding=utf-8 - # # The Qubes OS Project, https://www.qubes-os.org/ # diff --git a/qubes/qmemman/__init__.py b/qubes/qmemman/__init__.py index 94f00d55..d9865ea7 100644 --- a/qubes/qmemman/__init__.py +++ b/qubes/qmemman/__init__.py @@ -1,5 +1,3 @@ -#!/usr/bin/python2 -# -*- coding: utf-8 -*- # pylint: skip-file # @@ -22,7 +20,6 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # -# import logging import os diff --git a/qubes/qmemman/algo.py b/qubes/qmemman/algo.py index 4da69294..3beef4b0 100644 --- a/qubes/qmemman/algo.py +++ b/qubes/qmemman/algo.py @@ -1,5 +1,3 @@ -#!/usr/bin/python2 -# -*- coding: utf-8 -*- # pylint: skip-file # @@ -22,7 +20,7 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # -# + import logging import string diff --git a/qubes/qmemman/client.py b/qubes/qmemman/client.py index 449e0612..33bad031 100644 --- a/qubes/qmemman/client.py +++ b/qubes/qmemman/client.py @@ -1,5 +1,3 @@ -#!/usr/bin/python2 -# -*- coding: utf-8 -*- # pylint: skip-file # @@ -21,11 +19,11 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # -# + import socket import fcntl -class QMemmanClient: +class QMemmanClient: def request_memory(self, amount): self.sock = socket.socket(socket.AF_UNIX) diff --git a/qubes/rngdoc.py b/qubes/rngdoc.py index 8582253f..7791145f 100755 --- a/qubes/rngdoc.py +++ b/qubes/rngdoc.py @@ -1,6 +1,3 @@ -#!/usr/bin/python2 -O -# vim: fileencoding=utf-8 - # # The Qubes OS Project, https://www.qubes-os.org/ # diff --git a/qubes/storage/__init__.py b/qubes/storage/__init__.py index db06a232..c10c69a7 100644 --- a/qubes/storage/__init__.py +++ b/qubes/storage/__init__.py @@ -1,6 +1,3 @@ -#!/usr/bin/python2 -O -# vim: fileencoding=utf-8 - # # The Qubes OS Project, https://www.qubes-os.org/ # @@ -23,6 +20,7 @@ # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # + """ Qubes storage system""" from __future__ import absolute_import @@ -325,7 +323,7 @@ class Storage(object): def resize(self, volume, size): ''' Resizes volume a read-writable volume ''' - if isinstance(volume, basestring): + if isinstance(volume, str): volume = self.vm.volumes[volume] self.get_pool(volume).resize(volume, size) if self.vm.is_running(): @@ -444,7 +442,7 @@ class Storage(object): def get_pool(self, volume): ''' Helper function ''' - assert isinstance(volume, (Volume, basestring)), \ + assert isinstance(volume, (Volume, str)), \ "You need to pass a Volume or pool name as str" if isinstance(volume, Volume): return self.pools[volume.name] @@ -474,7 +472,7 @@ class Storage(object): def export(self, volume): ''' Helper function to export volume (pool.export(volume))''' - assert isinstance(volume, (Volume, basestring)), \ + assert isinstance(volume, (Volume, str)), \ "You need to pass a Volume or pool name as str" if isinstance(volume, Volume): return self.pools[volume.name].export(volume) diff --git a/qubes/storage/domain.py b/qubes/storage/domain.py index 9159b775..9e511f01 100644 --- a/qubes/storage/domain.py +++ b/qubes/storage/domain.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python2 -# -*- encoding: utf8 -*- # # The Qubes OS Project, http://www.qubes-os.org # @@ -19,8 +17,10 @@ # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # + ''' Manages block devices in a domain ''' +import itertools import string # pylint: disable=deprecated-module from qubes.storage import Pool, Volume @@ -43,9 +43,10 @@ class DomainPool(Pool): ''' Queries qubesdb and returns volumes for `self.vm` ''' qdb = self.vm.qdb - safe_set = set(string.letters + string.digits + string.punctuation) + safe_set = set(itertools.chain( + string.ascii_letters, string.digits, string.punctuation)) allowed_attributes = {'desc': string.printable, - 'mode': string.letters, + 'mode': string.ascii_letters, 'size': string.digits} if not self.vm.is_running(): return [] diff --git a/qubes/storage/file.py b/qubes/storage/file.py index d056b8b7..a7d779b0 100644 --- a/qubes/storage/file.py +++ b/qubes/storage/file.py @@ -1,5 +1,3 @@ -#!/usr/bin/python2 -O -# vim: fileencoding=utf-8 # # The Qubes OS Project, https://www.qubes-os.org/ # @@ -22,6 +20,7 @@ # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # + ''' This module contains pool implementations backed by file images''' from __future__ import absolute_import @@ -67,7 +66,7 @@ class FilePool(qubes.storage.Pool): return target def create(self, volume): - assert isinstance(volume.size, (int, long)) and volume.size > 0, \ + assert isinstance(volume.size, int) and volume.size > 0, \ 'Volatile volume size must be > 0' if volume._is_origin: create_sparse_file(volume.path, volume.size) @@ -157,7 +156,7 @@ class FilePool(qubes.storage.Pool): # TODO: Renaming the old revisions new_path = os.path.join(self.dir_path, subdir, new_name) if not os.path.exists(new_path): - os.mkdir(new_path, 0755) + os.mkdir(new_path, 0o755) new_volume_path = os.path.join(new_path, self.name + '.img') if not volume.backward_comp: os.rename(volume.path, new_volume_path) @@ -203,7 +202,7 @@ class FilePool(qubes.storage.Pool): def reset(self, volume): ''' Remove and recreate a volatile volume ''' assert volume._is_volatile, "Not a volatile volume" - assert isinstance(volume.size, (int, long)) and volume.size > 0, \ + assert isinstance(volume.size, int) and volume.size > 0, \ 'Volatile volume size must be > 0' _remove_if_exists(volume.path) diff --git a/qubes/storage/kernels.py b/qubes/storage/kernels.py index 5d5e703d..8e28880d 100644 --- a/qubes/storage/kernels.py +++ b/qubes/storage/kernels.py @@ -1,5 +1,3 @@ -#!/usr/bin/python2 -# -*- encoding: utf8 -*- # # The Qubes OS Project, http://www.qubes-os.org # @@ -21,7 +19,9 @@ # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # + ''' This module contains pool implementations for different OS kernels. ''' + import os from qubes.storage import Pool, StoragePoolException, Volume diff --git a/qubes/storage/lvm.py b/qubes/storage/lvm.py index 933d62f9..3803bd8e 100644 --- a/qubes/storage/lvm.py +++ b/qubes/storage/lvm.py @@ -1,5 +1,3 @@ -# vim: fileencoding=utf-8 -# pylint: disable=abstract-method # # The Qubes OS Project, http://www.qubes-os.org # @@ -19,6 +17,7 @@ # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # + ''' Driver for storing vm images in a LVM thin pool ''' import logging diff --git a/qubes/tarwriter.py b/qubes/tarwriter.py index eccf639b..35bef30d 100644 --- a/qubes/tarwriter.py +++ b/qubes/tarwriter.py @@ -1,5 +1,3 @@ -#!/usr/bin/python2 -# -*- encoding: utf8 -*- # # The Qubes OS Project, http://www.qubes-os.org # @@ -27,7 +25,6 @@ import io BUF_SIZE = 409600 - class TarSparseInfo(tarfile.TarInfo): def __init__(self, name="", sparsemap=None): super(TarSparseInfo, self).__init__(name) @@ -48,12 +45,12 @@ class TarSparseInfo(tarfile.TarInfo): def sparse_header_chunk(self, index): if index < len(self.sparsemap): - return ''.join([ + return b''.join([ tarfile.itn(self.sparsemap[index][0], 12, tarfile.GNU_FORMAT), tarfile.itn(self.sparsemap[index][1], 12, tarfile.GNU_FORMAT), ]) else: - return '\0' * 12 * 2 + return b'\0' * 12 * 2 def get_gnu_header(self): '''Part placed in 'prefix' field of posix header''' @@ -62,20 +59,20 @@ class TarSparseInfo(tarfile.TarInfo): tarfile.itn(self.mtime, 12, tarfile.GNU_FORMAT), # atime tarfile.itn(self.mtime, 12, tarfile.GNU_FORMAT), # ctime tarfile.itn(0, 12, tarfile.GNU_FORMAT), # offset - tarfile.stn('', 4), # longnames - '\0', # unused_pad2 + tarfile.stn('', 4, tarfile.ENCODING, 'surrogateescape'), #longnames + b'\0', # unused_pad2 ] parts += [self.sparse_header_chunk(i) for i in range(4)] parts += [ - '\1' if len(self.sparsemap) > 4 else '\0', # isextended + b'\1' if len(self.sparsemap) > 4 else b'\0', # isextended tarfile.itn(self.realsize, 12, tarfile.GNU_FORMAT), # realsize ] - return ''.join(parts) + return b''.join(parts) - def get_info(self, encoding, errors): - info = super(TarSparseInfo, self).get_info(encoding, errors) + def get_info(self): + info = super(TarSparseInfo, self).get_info() # place GNU extension into - info['prefix'] = self.get_gnu_header() + info['prefix'] = self.get_gnu_header().decode(tarfile.ENCODING) return info def tobuf(self, format=tarfile.DEFAULT_FORMAT, encoding=tarfile.ENCODING, @@ -83,16 +80,20 @@ class TarSparseInfo(tarfile.TarInfo): # pylint: disable=redefined-builtin header_buf = super(TarSparseInfo, self).tobuf(format, encoding, errors) if len(self.sparsemap) > 4: - return header_buf + ''.join(self.create_ext_sparse_headers()) + return header_buf + b''.join(self.create_ext_sparse_headers()) else: return header_buf def create_ext_sparse_headers(self): for ext_hdr in range(4, len(self.sparsemap), 21): - sparse_parts = [self.sparse_header_chunk(i) for i in - range(ext_hdr, ext_hdr+21)] - sparse_parts += '\1' if ext_hdr+21 < len(self.sparsemap) else '\0' - yield tarfile.stn(''.join(sparse_parts), 512) + sparse_parts = [ + self.sparse_header_chunk(i).decode( + tarfile.ENCODING, 'surrogateescape') + for i in range(ext_hdr, ext_hdr+21)] + sparse_parts.append( + '\1' if ext_hdr+21 < len(self.sparsemap) else '\0') + yield tarfile.stn(''.join(sparse_parts), 512, + tarfile.ENCODING, 'surrogateescape') def get_sparse_map(input_file): @@ -161,8 +162,8 @@ def copy_sparse_data(input_stream, output_stream, sparse_map): def finalize(output): '''Write EOF blocks''' - output.write('\0' * 512) - output.write('\0' * 512) + output.write(b'\0' * 512) + output.write(b'\0' * 512) def main(args=None): parser = argparse.ArgumentParser() diff --git a/qubes/tests/__init__.py b/qubes/tests/__init__.py index 82a180c2..5e20b2cf 100644 --- a/qubes/tests/__init__.py +++ b/qubes/tests/__init__.py @@ -1,5 +1,3 @@ -#!/usr/bin/python2 -O -# vim: fileencoding=utf-8 # pylint: disable=invalid-name # @@ -33,7 +31,6 @@ don't run the tests. """ -import __builtin__ import collections import functools import logging @@ -90,7 +87,7 @@ except libvirt.libvirtError: try: in_git = subprocess.check_output( - ['git', 'rev-parse', '--show-toplevel']).strip() + ['git', 'rev-parse', '--show-toplevel']).decode().strip() qubes.log.LOGPATH = '/tmp' qubes.log.LOGFILE = '/tmp/qubes.log' except subprocess.CalledProcessError: @@ -166,7 +163,7 @@ def expectedFailureIfTemplate(templates): @functools.wraps(func) def wrapper(self, *args, **kwargs): template = self.template - if isinstance(templates, basestring): + if isinstance(templates, str): should_expect_fail = template in templates else: should_expect_fail = any([template in x for x in templates]) @@ -283,7 +280,11 @@ class QubesTestCase(unittest.TestCase): def tearDown(self): super(QubesTestCase, self).tearDown() - result = self._resultForDoCleanups + # TODO: find better way in py3 + try: + result = self._outcome.result + except: + result = self._resultForDoCleanups failed_test_cases = result.failures \ + result.errors \ + [(tc, None) for tc in result.unexpectedSuccesses] @@ -334,7 +335,7 @@ class QubesTestCase(unittest.TestCase): self.assertEqual(xml1.tag, xml2.tag) self.assertEqual(xml1.text, xml2.text) - self.assertItemsEqual(xml1.keys(), xml2.keys()) + self.assertCountEqual(xml1.keys(), xml2.keys()) for key in xml1.keys(): self.assertEqual(xml1.get(key), xml2.get(key)) @@ -503,7 +504,7 @@ class SystemTestsMixin(object): def init_default_template(self, template=None): if template is None: template = self.host_app.default_template - elif isinstance(template, basestring): + elif isinstance(template, str): template = self.host_app.domains[template] template_vm = self.app.add_new_vm(qubes.vm.templatevm.TemplateVM, @@ -752,9 +753,8 @@ class SystemTestsMixin(object): wait_count = 0 while subprocess.call(['xdotool', 'search', '--name', title], - stdout=open(os.path.devnull, 'w'), - stderr=subprocess.STDOUT) == \ - __builtin__.int(show): + stdout=open(os.path.devnull, 'w'), stderr=subprocess.STDOUT) \ + == int(show): wait_count += 1 if wait_count > timeout*10: self.fail("Timeout while waiting for {} window to {}".format( @@ -841,7 +841,7 @@ class SystemTestsMixin(object): init_path = os.path.join(mountpoint, 'init') with open(init_path, 'w') as f: f.write(init_script) - os.chmod(init_path, 0755) + os.chmod(init_path, 0o755) dracut_args = [ '--kver', kernel_version, '--include', init_path, @@ -894,23 +894,23 @@ def load_tests(loader, tests, pattern): # pylint: disable=unused-argument for modname in ( # integration tests - 'qubes.tests.int.basic', - 'qubes.tests.int.storage', - 'qubes.tests.int.devices_pci', - 'qubes.tests.int.dom0_update', - 'qubes.tests.int.network', - 'qubes.tests.int.dispvm', - 'qubes.tests.int.vm_qrexec_gui', - 'qubes.tests.int.backup', - 'qubes.tests.int.backupcompatibility', + 'qubes.tests.integ.basic', + 'qubes.tests.integ.storage', + 'qubes.tests.integ.devices_pci', + 'qubes.tests.integ.dom0_update', + 'qubes.tests.integ.network', + 'qubes.tests.integ.dispvm', + 'qubes.tests.integ.vm_qrexec_gui', + 'qubes.tests.integ.backup', + 'qubes.tests.integ.backupcompatibility', # 'qubes.tests.regressions', # tool tests - 'qubes.tests.int.tools.qubes_create', - 'qubes.tests.int.tools.qvm_check', - 'qubes.tests.int.tools.qvm_firewall', - 'qubes.tests.int.tools.qvm_prefs', - 'qubes.tests.int.tools.qvm_run', + 'qubes.tests.integ.tools.qubes_create', + 'qubes.tests.integ.tools.qvm_check', + 'qubes.tests.integ.tools.qvm_firewall', + 'qubes.tests.integ.tools.qvm_prefs', + 'qubes.tests.integ.tools.qvm_run', # external modules # 'qubes.tests.extra', diff --git a/qubes/tests/app.py b/qubes/tests/app.py index adbe8447..79ea3f91 100644 --- a/qubes/tests/app.py +++ b/qubes/tests/app.py @@ -1,5 +1,3 @@ -#!/usr/bin/python2 -O -# vim: fileencoding=utf-8 # pylint: disable=protected-access,pointless-statement # @@ -32,26 +30,7 @@ import qubes import qubes.events import qubes.tests - -# FIXME: blatant duplication with qubes.tests.init - -class TestVM(qubes.vm.BaseVM): - qid = qubes.property('qid', type=int) - name = qubes.property('name') - netid = qid - uuid = uuid.uuid5(uuid.NAMESPACE_DNS, 'testvm') - - class MockLibvirt(object): - def undefine(self): - pass - - libvirt_domain = MockLibvirt() - - def is_halted(self): - return True - - def get_power_state(self): - return "Halted" +import qubes.tests.init class TestApp(qubes.tests.TestEmitter): pass @@ -61,8 +40,10 @@ class TC_30_VMCollection(qubes.tests.QubesTestCase): self.app = TestApp() self.vms = qubes.app.VMCollection(self.app) - self.testvm1 = TestVM(None, None, qid=1, name='testvm1') - self.testvm2 = TestVM(None, None, qid=2, name='testvm2') + self.testvm1 = qubes.tests.init.TestVM( + None, None, qid=1, name='testvm1') + self.testvm2 = qubes.tests.init.TestVM( + None, None, qid=2, name='testvm2') def test_000_contains(self): self.vms._dict = {1: self.testvm1} @@ -91,8 +72,10 @@ class TC_30_VMCollection(qubes.tests.QubesTestCase): with self.assertRaises(TypeError): self.vms.add(object()) - testvm_qid_collision = TestVM(None, None, name='testvm2', qid=1) - testvm_name_collision = TestVM(None, None, name='testvm1', qid=2) + testvm_qid_collision = qubes.tests.init.TestVM( + None, None, name='testvm2', qid=1) + testvm_name_collision = qubes.tests.init.TestVM( + None, None, name='testvm1', qid=2) with self.assertRaises(ValueError): self.vms.add(testvm_qid_collision) @@ -103,27 +86,27 @@ class TC_30_VMCollection(qubes.tests.QubesTestCase): self.vms.add(self.testvm1) self.vms.add(self.testvm2) - self.assertItemsEqual(self.vms.qids(), [1, 2]) - self.assertItemsEqual(self.vms.keys(), [1, 2]) + self.assertCountEqual(self.vms.qids(), [1, 2]) + self.assertCountEqual(self.vms.keys(), [1, 2]) def test_004_names(self): self.vms.add(self.testvm1) self.vms.add(self.testvm2) - self.assertItemsEqual(self.vms.names(), ['testvm1', 'testvm2']) + self.assertCountEqual(self.vms.names(), ['testvm1', 'testvm2']) def test_005_vms(self): self.vms.add(self.testvm1) self.vms.add(self.testvm2) - self.assertItemsEqual(self.vms.vms(), [self.testvm1, self.testvm2]) - self.assertItemsEqual(self.vms.values(), [self.testvm1, self.testvm2]) + self.assertCountEqual(self.vms.vms(), [self.testvm1, self.testvm2]) + self.assertCountEqual(self.vms.values(), [self.testvm1, self.testvm2]) def test_006_items(self): self.vms.add(self.testvm1) self.vms.add(self.testvm2) - self.assertItemsEqual(self.vms.items(), + self.assertCountEqual(self.vms.items(), [(1, self.testvm1), (2, self.testvm2)]) def test_007_len(self): @@ -138,7 +121,7 @@ class TC_30_VMCollection(qubes.tests.QubesTestCase): del self.vms['testvm2'] - self.assertItemsEqual(self.vms.vms(), [self.testvm1]) + self.assertCountEqual(self.vms.vms(), [self.testvm1]) self.assertEventFired(self.app, 'domain-delete', args=[self.testvm2]) def test_100_get_new_unused_qid(self): diff --git a/qubes/tests/devices.py b/qubes/tests/devices.py index a851ac83..e2e8448f 100644 --- a/qubes/tests/devices.py +++ b/qubes/tests/devices.py @@ -1,5 +1,3 @@ -#!/usr/bin/python2 -O -# vim: fileencoding=utf-8 # pylint: disable=protected-access,pointless-statement # diff --git a/qubes/tests/events.py b/qubes/tests/events.py index 8873046f..d102e67a 100644 --- a/qubes/tests/events.py +++ b/qubes/tests/events.py @@ -1,6 +1,3 @@ -#!/usr/bin/python2 -O -# vim: fileencoding=utf-8 - # # The Qubes OS Project, https://www.qubes-os.org/ # @@ -80,7 +77,7 @@ class TC_00_Emitter(qubes.tests.QubesTestCase): effect = emitter.fire_event('testevent') - self.assertItemsEqual(effect, + self.assertCountEqual(effect, ('testvalue1', 'testvalue2', 'testvalue3', 'testvalue4')) def test_004_catch_all(self): diff --git a/qubes/tests/extra.py b/qubes/tests/extra.py index fa877476..5b9a2d6d 100644 --- a/qubes/tests/extra.py +++ b/qubes/tests/extra.py @@ -1,6 +1,3 @@ -#!/usr/bin/python2 -O -# vim: fileencoding=utf-8 - # # The Qubes OS Project, https://www.qubes-os.org/ # @@ -76,9 +73,8 @@ def load_tests(loader, tests, pattern): for test_case in entry.load()(): tests.addTests(loader.loadTestsFromTestCase(test_case)) except Exception as err: # pylint: disable=broad-except - tb = sys.exc_info()[2] def runTest(self): - raise err, None, tb + raise err ExtraLoadFailure = type('ExtraLoadFailure', (qubes.tests.QubesTestCase,), {entry.name: runTest}) @@ -105,9 +101,8 @@ def load_tests(loader, tests, pattern): ) )) except Exception as err: # pylint: disable=broad-except - tb = sys.exc_info()[2] def runTest(self): - raise err, None, tb + raise err ExtraForTemplateLoadFailure = type('ExtraForTemplateLoadFailure', (qubes.tests.QubesTestCase,), {entry.name: runTest}) diff --git a/qubes/tests/firewall.py b/qubes/tests/firewall.py index ea3d9df0..e17a616d 100644 --- a/qubes/tests/firewall.py +++ b/qubes/tests/firewall.py @@ -1,6 +1,3 @@ -#!/usr/bin/python2 -O -# vim: fileencoding=utf-8 - # # The Qubes OS Project, https://www.qubes-os.org/ # diff --git a/qubes/tests/init.py b/qubes/tests/init.py index 99105e47..a691d73a 100644 --- a/qubes/tests/init.py +++ b/qubes/tests/init.py @@ -1,5 +1,3 @@ -#!/usr/bin/python2 -O -# vim: fileencoding=utf-8 # pylint: disable=protected-access,pointless-statement # @@ -292,6 +290,12 @@ class TestVM(qubes.vm.BaseVM): netid = qid uuid = uuid.uuid5(uuid.NAMESPACE_DNS, 'testvm') + def __lt__(self, other): + try: + return self.name < other.name + except AttributeError: + return NotImplemented + class MockLibvirt(object): def undefine(self): pass @@ -304,6 +308,7 @@ class TestVM(qubes.vm.BaseVM): def get_power_state(self): return "Halted" + class TestApp(qubes.tests.TestEmitter): pass @@ -354,27 +359,27 @@ class TC_30_VMCollection(qubes.tests.QubesTestCase): self.vms.add(self.testvm1) self.vms.add(self.testvm2) - self.assertItemsEqual(self.vms.qids(), [1, 2]) - self.assertItemsEqual(self.vms.keys(), [1, 2]) + self.assertCountEqual(self.vms.qids(), [1, 2]) + self.assertCountEqual(self.vms.keys(), [1, 2]) def test_004_names(self): self.vms.add(self.testvm1) self.vms.add(self.testvm2) - self.assertItemsEqual(self.vms.names(), ['testvm1', 'testvm2']) + self.assertCountEqual(self.vms.names(), ['testvm1', 'testvm2']) def test_005_vms(self): self.vms.add(self.testvm1) self.vms.add(self.testvm2) - self.assertItemsEqual(self.vms.vms(), [self.testvm1, self.testvm2]) - self.assertItemsEqual(self.vms.values(), [self.testvm1, self.testvm2]) + self.assertCountEqual(self.vms.vms(), [self.testvm1, self.testvm2]) + self.assertCountEqual(self.vms.values(), [self.testvm1, self.testvm2]) def test_006_items(self): self.vms.add(self.testvm1) self.vms.add(self.testvm2) - self.assertItemsEqual(self.vms.items(), + self.assertCountEqual(self.vms.items(), [(1, self.testvm1), (2, self.testvm2)]) def test_007_len(self): @@ -389,7 +394,7 @@ class TC_30_VMCollection(qubes.tests.QubesTestCase): del self.vms['testvm2'] - self.assertItemsEqual(self.vms.vms(), [self.testvm1]) + self.assertCountEqual(self.vms.vms(), [self.testvm1]) self.assertEventFired(self.app, 'domain-delete', args=[self.testvm2]) def test_100_get_new_unused_qid(self): diff --git a/qubes/tests/int/__init__.py b/qubes/tests/integ/__init__.py similarity index 100% rename from qubes/tests/int/__init__.py rename to qubes/tests/integ/__init__.py diff --git a/qubes/tests/int/backup.py b/qubes/tests/integ/backup.py similarity index 99% rename from qubes/tests/int/backup.py rename to qubes/tests/integ/backup.py index 83acb86b..03bc5587 100644 --- a/qubes/tests/int/backup.py +++ b/qubes/tests/integ/backup.py @@ -1,6 +1,3 @@ -#!/usr/bin/python -# vim: fileencoding=utf-8 - # # The Qubes OS Project, https://www.qubes-os.org/ # @@ -22,6 +19,7 @@ # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # + import hashlib import logging import multiprocessing diff --git a/qubes/tests/int/backupcompatibility.py b/qubes/tests/integ/backupcompatibility.py similarity index 99% rename from qubes/tests/int/backupcompatibility.py rename to qubes/tests/integ/backupcompatibility.py index 419b1580..608ed2f3 100644 --- a/qubes/tests/int/backupcompatibility.py +++ b/qubes/tests/integ/backupcompatibility.py @@ -1,5 +1,3 @@ -#!/usr/bin/python -# -*- coding: utf-8 -*- # # The Qubes OS Project, http://www.qubes-os.org # @@ -19,7 +17,7 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # -# + from multiprocessing import Queue import os @@ -31,7 +29,7 @@ import sys import re import qubes.tests -import qubes.tests.int.backup +import qubes.tests.integ.backup QUBESXML_R2B2 = ''' @@ -145,7 +143,7 @@ compression-filter=gzip ''' class TC_00_BackupCompatibility( - qubes.tests.int.backup.BackupTestsMixin, qubes.tests.QubesTestCase): + qubes.tests.integ.backup.BackupTestsMixin, qubes.tests.QubesTestCase): def tearDown(self): self.remove_test_vms(prefix="test-") diff --git a/qubes/tests/int/basic.py b/qubes/tests/integ/basic.py similarity index 99% rename from qubes/tests/int/basic.py rename to qubes/tests/integ/basic.py index 008f0276..384169f6 100644 --- a/qubes/tests/int/basic.py +++ b/qubes/tests/integ/basic.py @@ -1,6 +1,5 @@ -#!/usr/bin/python -# vim: fileencoding=utf-8 # pylint: disable=invalid-name + # # The Qubes OS Project, https://www.qubes-os.org/ # @@ -22,6 +21,7 @@ # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # + from distutils import spawn import os diff --git a/qubes/tests/int/devices_pci.py b/qubes/tests/integ/devices_pci.py similarity index 99% rename from qubes/tests/int/devices_pci.py rename to qubes/tests/integ/devices_pci.py index ffb5a552..f9b3cec0 100644 --- a/qubes/tests/int/devices_pci.py +++ b/qubes/tests/integ/devices_pci.py @@ -1,5 +1,3 @@ -#!/usr/bin/python2 -O -# vim: fileencoding=utf-8 # pylint: disable=protected-access,pointless-statement # @@ -22,6 +20,7 @@ # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # + import os import subprocess import time diff --git a/qubes/tests/int/dispvm.py b/qubes/tests/integ/dispvm.py similarity index 99% rename from qubes/tests/int/dispvm.py rename to qubes/tests/integ/dispvm.py index 493a4eb5..2faa9cfc 100644 --- a/qubes/tests/int/dispvm.py +++ b/qubes/tests/integ/dispvm.py @@ -1,5 +1,3 @@ -#!/usr/bin/python -# -*- coding: utf-8 -*- # # The Qubes OS Project, http://www.qubes-os.org # @@ -20,7 +18,6 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # -# from distutils import spawn import qubes.tests diff --git a/qubes/tests/int/dom0_update.py b/qubes/tests/integ/dom0_update.py similarity index 99% rename from qubes/tests/int/dom0_update.py rename to qubes/tests/integ/dom0_update.py index 2f14f74a..b26f6cba 100644 --- a/qubes/tests/int/dom0_update.py +++ b/qubes/tests/integ/dom0_update.py @@ -1,5 +1,3 @@ -#!/usr/bin/python -# -*- coding: utf-8 -*- # # The Qubes OS Project, http://www.qubes-os.org # @@ -20,6 +18,7 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, # USA. # + import os import shutil import subprocess diff --git a/qubes/tests/int/network.py b/qubes/tests/integ/network.py similarity index 99% rename from qubes/tests/int/network.py rename to qubes/tests/integ/network.py index 977d74d7..858e72a6 100644 --- a/qubes/tests/int/network.py +++ b/qubes/tests/integ/network.py @@ -1,6 +1,3 @@ -#!/usr/bin/python -# vim: fileencoding=utf-8 - # # The Qubes OS Project, https://www.qubes-os.org/ # @@ -22,6 +19,7 @@ # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # + from distutils import spawn import multiprocessing diff --git a/qubes/tests/int/storage.py b/qubes/tests/integ/storage.py similarity index 99% rename from qubes/tests/int/storage.py rename to qubes/tests/integ/storage.py index 181d9438..e7f1c7c9 100644 --- a/qubes/tests/int/storage.py +++ b/qubes/tests/integ/storage.py @@ -1,5 +1,3 @@ -#!/usr/bin/python2 -# -*- encoding: utf8 -*- # # The Qubes OS Project, http://www.qubes-os.org # @@ -19,6 +17,8 @@ # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# + import os import shutil diff --git a/qubes/tests/int/tools/__init__.py b/qubes/tests/integ/tools/__init__.py similarity index 100% rename from qubes/tests/int/tools/__init__.py rename to qubes/tests/integ/tools/__init__.py diff --git a/qubes/tests/int/tools/qubes_create.py b/qubes/tests/integ/tools/qubes_create.py similarity index 96% rename from qubes/tests/int/tools/qubes_create.py rename to qubes/tests/integ/tools/qubes_create.py index 284ede2f..cbf8bd00 100644 --- a/qubes/tests/int/tools/qubes_create.py +++ b/qubes/tests/integ/tools/qubes_create.py @@ -1,6 +1,3 @@ -#!/usr/bin/python2 -O -# vim: fileencoding=utf-8 - # # The Qubes OS Project, https://www.qubes-os.org/ # @@ -22,7 +19,6 @@ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # - import qubes import qubes.tools.qubes_create diff --git a/qubes/tests/int/tools/qvm_check.py b/qubes/tests/integ/tools/qvm_check.py similarity index 98% rename from qubes/tests/int/tools/qvm_check.py rename to qubes/tests/integ/tools/qvm_check.py index 84628b0b..c2f8fb6f 100644 --- a/qubes/tests/int/tools/qvm_check.py +++ b/qubes/tests/integ/tools/qvm_check.py @@ -1,5 +1,3 @@ -#!/usr/bin/python2 -O -# vim: fileencoding=utf-8 # # The Qubes OS Project, https://www.qubes-os.org/ # diff --git a/qubes/tests/int/tools/qvm_firewall.py b/qubes/tests/integ/tools/qvm_firewall.py similarity index 99% rename from qubes/tests/int/tools/qvm_firewall.py rename to qubes/tests/integ/tools/qvm_firewall.py index 0bfbaa98..14a970cc 100644 --- a/qubes/tests/int/tools/qvm_firewall.py +++ b/qubes/tests/integ/tools/qvm_firewall.py @@ -1,5 +1,3 @@ -#!/usr/bin/python2 -# -*- encoding: utf8 -*- # # The Qubes OS Project, http://www.qubes-os.org # @@ -19,6 +17,7 @@ # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# import qubes.firewall import qubes.tests diff --git a/qubes/tests/int/tools/qvm_prefs.py b/qubes/tests/integ/tools/qvm_prefs.py similarity index 97% rename from qubes/tests/int/tools/qvm_prefs.py rename to qubes/tests/integ/tools/qvm_prefs.py index ba12cfc7..8de069b6 100644 --- a/qubes/tests/int/tools/qvm_prefs.py +++ b/qubes/tests/integ/tools/qvm_prefs.py @@ -1,6 +1,3 @@ -#!/usr/bin/python2 -O -# vim: fileencoding=utf-8 - # # The Qubes OS Project, https://www.qubes-os.org/ # @@ -22,7 +19,6 @@ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # - import qubes import qubes.tools.qvm_prefs diff --git a/qubes/tests/int/tools/qvm_run.py b/qubes/tests/integ/tools/qvm_run.py similarity index 98% rename from qubes/tests/int/tools/qvm_run.py rename to qubes/tests/integ/tools/qvm_run.py index 2979c76a..4cebcab4 100644 --- a/qubes/tests/int/tools/qvm_run.py +++ b/qubes/tests/integ/tools/qvm_run.py @@ -1,6 +1,3 @@ -#!/usr/bin/python2 -O -# vim: fileencoding=utf-8 - # # The Qubes OS Project, https://www.qubes-os.org/ # diff --git a/qubes/tests/int/vm_qrexec_gui.py b/qubes/tests/integ/vm_qrexec_gui.py similarity index 99% rename from qubes/tests/int/vm_qrexec_gui.py rename to qubes/tests/integ/vm_qrexec_gui.py index d95532ad..742542fc 100644 --- a/qubes/tests/int/vm_qrexec_gui.py +++ b/qubes/tests/integ/vm_qrexec_gui.py @@ -1,6 +1,3 @@ -#!/usr/bin/python -# vim: fileencoding=utf-8 - # # The Qubes OS Project, https://www.qubes-os.org/ # @@ -22,6 +19,7 @@ # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # + from distutils import spawn import multiprocessing diff --git a/qubes/tests/run.py b/qubes/tests/run.py index 4c3d3625..8686d3d1 100755 --- a/qubes/tests/run.py +++ b/qubes/tests/run.py @@ -1,6 +1,3 @@ -#!/usr/bin/python2 -O -# vim: fileencoding=utf-8 - # # The Qubes OS Project, https://www.qubes-os.org/ # @@ -24,6 +21,7 @@ import argparse import curses +import itertools import logging import logging.handlers import os @@ -36,29 +34,37 @@ import unittest.signals import qubes.tests class CursesColor(dict): + colors = ( + 'black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white') + attrs = { + 'bold': 'bold', 'normal': 'sgr0'} def __init__(self): super(CursesColor, self).__init__() + self.has_colors = False try: curses.setupterm() + self.has_colors = True except curses.error: return - # pylint: disable=bad-whitespace - self['black'] = curses.tparm(curses.tigetstr('setaf'), 0) - self['red'] = curses.tparm(curses.tigetstr('setaf'), 1) - self['green'] = curses.tparm(curses.tigetstr('setaf'), 2) - self['yellow'] = curses.tparm(curses.tigetstr('setaf'), 3) - self['blue'] = curses.tparm(curses.tigetstr('setaf'), 4) - self['magenta'] = curses.tparm(curses.tigetstr('setaf'), 5) - self['cyan'] = curses.tparm(curses.tigetstr('setaf'), 6) - self['white'] = curses.tparm(curses.tigetstr('setaf'), 7) - - self['bold'] = curses.tigetstr('bold') - self['normal'] = curses.tigetstr('sgr0') def __missing__(self, key): # pylint: disable=unused-argument,no-self-use - return '' + if not self.has_colors: + return '' + + try: + value = curses.tigetstr(self.attrs[key]) + except KeyError: + try: + value = curses.tparm( + curses.tigetstr('setaf'), self.colors.index(key)) + except ValueError: + return '' + + value = value.decode() + self[key] = value + return value class QubesTestResult(unittest.TestResult): @@ -293,13 +299,18 @@ parser.add_argument('--do-clean', '-C', help='do execute tearDown even on failed tests.') # pylint: disable=protected-access +try: + name_to_level = logging._nameToLevel +except AttributeError: + name_to_level = logging._levelNames parser.add_argument('--loglevel', '-L', metavar='LEVEL', action='store', choices=tuple(k - for k in sorted(logging._levelNames.keys(), - key=lambda x: logging._levelNames[x]) - if isinstance(k, basestring)), + for k in sorted(name_to_level.keys(), + key=lambda x: name_to_level[x]) + if isinstance(k, str)), help='logging level for file and syslog forwarding ' '(one of: %(choices)s; default: %(default)s)') +del name_to_level # pylint: enable=protected-access parser.add_argument('--logfile', '-o', metavar='FILE', diff --git a/qubes/tests/storage.py b/qubes/tests/storage.py index 57e780c1..33838fd2 100644 --- a/qubes/tests/storage.py +++ b/qubes/tests/storage.py @@ -1,3 +1,4 @@ +# # The Qubes OS Project, https://www.qubes-os.org/ # # Copyright (C) 2015 Bahtiar `kalkin-` Gadimov @@ -15,6 +16,7 @@ # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# import qubes.log from qubes.exc import QubesException @@ -80,7 +82,7 @@ class TC_00_Pool(QubesTestCase): def test_001_all_pool_drivers(self): """ The only predefined pool driver is file """ - self.assertEquals(['linux-kernel', 'lvm_thin', 'file'], pool_drivers()) + self.assertCountEqual(['linux-kernel', 'lvm_thin', 'file'], pool_drivers()) def test_002_get_pool_klass(self): """ Expect the default pool to be `FilePool` """ diff --git a/qubes/tests/storage_file.py b/qubes/tests/storage_file.py index 7cd787f4..e0562be2 100644 --- a/qubes/tests/storage_file.py +++ b/qubes/tests/storage_file.py @@ -1,3 +1,4 @@ +# # The Qubes OS Project, https://www.qubes-os.org/ # # Copyright (C) 2015 Bahtiar `kalkin-` Gadimov @@ -15,6 +16,7 @@ # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# ''' Tests for the file storage backend ''' diff --git a/qubes/tests/storage_lvm.py b/qubes/tests/storage_lvm.py index 4760de50..61939e01 100644 --- a/qubes/tests/storage_lvm.py +++ b/qubes/tests/storage_lvm.py @@ -1,5 +1,3 @@ -# vim: fileencoding=utf-8 -# pylint: disable=missing-docstring # # The Qubes OS Project, http://www.qubes-os.org # diff --git a/qubes/tests/tarwriter.py b/qubes/tests/tarwriter.py index d95144e7..3e2c53d5 100644 --- a/qubes/tests/tarwriter.py +++ b/qubes/tests/tarwriter.py @@ -1,5 +1,3 @@ -#!/usr/bin/python2 -# -*- encoding: utf8 -*- # # The Qubes OS Project, http://www.qubes-os.org # @@ -19,6 +17,8 @@ # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# + import os import subprocess import tempfile @@ -58,7 +58,7 @@ class TC_00_TarWriter(qubes.tests.QubesTestCase): expected_output = ( 'tar: Removing leading `/\' from member names\n' + expected_output) - self.assertEqual(tar_output, expected_output) + self.assertEqual(tar_output.decode(), expected_output) extracted_path = os.path.join(self.extract_dir, expected_name.lstrip('/')) with self.assertNotRaises(subprocess.CalledProcessError): diff --git a/qubes/tests/tools/__init__.py b/qubes/tests/tools/__init__.py index cae5797e..2bc36631 100644 --- a/qubes/tests/tools/__init__.py +++ b/qubes/tests/tools/__init__.py @@ -1,6 +1,3 @@ -#!/usr/bin/python2 -O -# vim: fileencoding=utf-8 - # # The Qubes OS Project, https://www.qubes-os.org/ # @@ -20,18 +17,15 @@ # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# +import io import sys -try: - import StringIO -except ImportError: - from io import StringIO - class StdoutBuffer(object): def __init__(self): - self.stdout = StringIO.StringIO() + self.stdout = io.StringIO() def __enter__(self): sys.stdout = self.stdout diff --git a/qubes/tests/tools/init.py b/qubes/tests/tools/init.py index 66c0b3ed..0735b588 100644 --- a/qubes/tests/tools/init.py +++ b/qubes/tests/tools/init.py @@ -1,6 +1,3 @@ -#!/usr/bin/python2 -O -# vim: fileencoding=utf-8 - # # The Qubes OS Project, https://www.qubes-os.org/ # diff --git a/qubes/tests/tools/qvm_device.py b/qubes/tests/tools/qvm_device.py index 5ab3476d..134e19ce 100644 --- a/qubes/tests/tools/qvm_device.py +++ b/qubes/tests/tools/qvm_device.py @@ -1,5 +1,3 @@ -#!/usr/bin/python2 -O -# vim: fileencoding=utf-8 # pylint: disable=protected-access,pointless-statement # diff --git a/qubes/tests/tools/qvm_firewall.py b/qubes/tests/tools/qvm_firewall.py index 0d3e72c9..ef37437d 100644 --- a/qubes/tests/tools/qvm_firewall.py +++ b/qubes/tests/tools/qvm_firewall.py @@ -1,5 +1,3 @@ -#!/usr/bin/python2 -# -*- encoding: utf8 -*- # # The Qubes OS Project, http://www.qubes-os.org # @@ -19,6 +17,8 @@ # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# + import argparse import qubes.firewall @@ -58,4 +58,4 @@ class TC_00_RuleAction(qubes.tests.QubesTestCase): 'dstports=443', 'tcp']) self.assertEqual(ns.rule, qubes.firewall.Rule(None, action='accept', dsthost='127.0.0.1/32', - proto='tcp', dstports=443)) \ No newline at end of file + proto='tcp', dstports=443)) diff --git a/qubes/tests/tools/qvm_ls.py b/qubes/tests/tools/qvm_ls.py index ca6d54e4..969e0681 100644 --- a/qubes/tests/tools/qvm_ls.py +++ b/qubes/tests/tools/qvm_ls.py @@ -1,5 +1,3 @@ -#!/usr/bin/python2 -O -# vim: fileencoding=utf-8 # pylint: disable=protected-access,pointless-statement # diff --git a/qubes/tests/vm/__init__.py b/qubes/tests/vm/__init__.py index 4dc045a1..b14cd27c 100644 --- a/qubes/tests/vm/__init__.py +++ b/qubes/tests/vm/__init__.py @@ -1,5 +1,3 @@ -#!/usr/bin/python2 -O -# vim: fileencoding=utf-8 # pylint: disable=protected-access,pointless-statement # diff --git a/qubes/tests/vm/adminvm.py b/qubes/tests/vm/adminvm.py index ac60d061..87310913 100644 --- a/qubes/tests/vm/adminvm.py +++ b/qubes/tests/vm/adminvm.py @@ -1,6 +1,3 @@ -#!/usr/bin/python2 -O -# vim: fileencoding=utf-8 - # # The Qubes OS Project, https://www.qubes-os.org/ # diff --git a/qubes/tests/vm/init.py b/qubes/tests/vm/init.py index 389bf42c..072271ae 100644 --- a/qubes/tests/vm/init.py +++ b/qubes/tests/vm/init.py @@ -1,5 +1,3 @@ -#!/usr/bin/python2 -O -# vim: fileencoding=utf-8 # pylint: disable=protected-access # @@ -109,8 +107,8 @@ class TC_10_BaseVM(qubes.tests.QubesTestCase): 'testfeature_aqq': 'aqq', }) - self.assertItemsEqual(vm.devices.keys(), ('pci',)) - self.assertItemsEqual(list(vm.devices['pci'].attached(persistent=True)), + self.assertCountEqual(vm.devices.keys(), ('pci',)) + self.assertCountEqual(list(vm.devices['pci'].attached(persistent=True)), [qubes.ext.pci.PCIDevice(vm, '00:11.22')]) self.assertXMLIsValid(vm.__xml__(), 'domain.rng') diff --git a/qubes/tests/vm/mix/net.py b/qubes/tests/vm/mix/net.py index 2f50ec5c..9ee27e48 100644 --- a/qubes/tests/vm/mix/net.py +++ b/qubes/tests/vm/mix/net.py @@ -1,5 +1,3 @@ -#!/usr/bin/python2 -O -# vim: fileencoding=utf-8 # pylint: disable=protected-access # @@ -22,6 +20,7 @@ # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # + import unittest import qubes diff --git a/qubes/tests/vm/qubesvm.py b/qubes/tests/vm/qubesvm.py index a58c2a23..2fe79ff7 100644 --- a/qubes/tests/vm/qubesvm.py +++ b/qubes/tests/vm/qubesvm.py @@ -1,5 +1,3 @@ -#!/usr/bin/python2 -O -# vim: fileencoding=utf-8 # pylint: disable=protected-access # @@ -22,6 +20,7 @@ # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # + import os import unittest @@ -244,7 +243,7 @@ class TC_90_QubesVM(QubesVMTestsMixin,qubes.tests.QubesTestCase): def test_110_name(self): vm = self.get_vm() - self.assertIsInstance(vm.name, basestring) + self.assertIsInstance(vm.name, str) def test_120_uuid(self): my_uuid = uuid.uuid4() diff --git a/qubes/tools/__init__.py b/qubes/tools/__init__.py index 4f420b50..f17abde3 100644 --- a/qubes/tools/__init__.py +++ b/qubes/tools/__init__.py @@ -1,6 +1,3 @@ -#!/usr/bin/python2 -O -# vim: fileencoding=utf-8 - # # The Qubes OS Project, https://www.qubes-os.org/ # @@ -294,7 +291,7 @@ class PoolsAction(QubesAction): pools = [app.get_pool(name) for name in pool_names] setattr(namespace, self.dest, pools) except qubes.exc.QubesException as e: - parser.error(e.message) + parser.error(str(e)) sys.exit(2) @@ -530,9 +527,9 @@ def print_table(table): if sys.stdout != sys.__stdout__: p = subprocess.Popen(cmd + ['-c', '80'], stdin=subprocess.PIPE, stdout=subprocess.PIPE) - p.stdin.write(text_table) + p.stdin.write(text_table.encode()) (out, _) = p.communicate() - sys.stdout.write(out) + sys.stdout.write(out.decode()) else: p = subprocess.Popen(cmd, stdin=subprocess.PIPE) - p.communicate(text_table) + p.communicate(text_table.encode()) diff --git a/qubes/tools/qmemmand.py b/qubes/tools/qmemmand.py index 58b50520..560fdc5a 100644 --- a/qubes/tools/qmemmand.py +++ b/qubes/tools/qmemmand.py @@ -1,5 +1,3 @@ -#!/usr/bin/python2 -# -*- coding: utf-8 -*- # pylint: skip-file # @@ -283,7 +281,7 @@ def main(): log.debug('instantiating server') os.umask(0) server = SocketServer.UnixStreamServer(SOCK_PATH, QMemmanReqHandler) - os.umask(077) + os.umask(0o077) # notify systemd nofity_socket = os.getenv('NOTIFY_SOCKET') diff --git a/qubes/tools/qubes_create.py b/qubes/tools/qubes_create.py index 8b94ab22..f49bf495 100644 --- a/qubes/tools/qubes_create.py +++ b/qubes/tools/qubes_create.py @@ -1,6 +1,3 @@ -#!/usr/bin/python2 -O -# vim: fileencoding=utf-8 - # # The Qubes OS Project, https://www.qubes-os.org/ # diff --git a/qubes/tools/qubes_monitor_layout_notify.py b/qubes/tools/qubes_monitor_layout_notify.py index 7280a38a..7cf3ce8a 100644 --- a/qubes/tools/qubes_monitor_layout_notify.py +++ b/qubes/tools/qubes_monitor_layout_notify.py @@ -1,6 +1,3 @@ -#!/usr/bin/python2 -O -# vim: fileencoding=utf-8 - # # The Qubes OS Project, https://www.qubes-os.org/ # diff --git a/qubes/tools/qubes_prefs.py b/qubes/tools/qubes_prefs.py index 8abf4c23..1634e42f 100644 --- a/qubes/tools/qubes_prefs.py +++ b/qubes/tools/qubes_prefs.py @@ -1,5 +1,3 @@ -#!/usr/bin/python2 -# -*- encoding: utf8 -*- # # The Qubes OS Project, http://www.qubes-os.org # diff --git a/qubes/tools/qvm_backup.py b/qubes/tools/qvm_backup.py index 24c22494..8e18d7f5 100644 --- a/qubes/tools/qvm_backup.py +++ b/qubes/tools/qvm_backup.py @@ -1,5 +1,3 @@ -#!/usr/bin/python2 -# -*- encoding: utf8 -*- # # The Qubes OS Project, http://www.qubes-os.org # @@ -145,7 +143,7 @@ def main(args=None): pass_f.close() else: - if raw_input("Do you want to proceed? [y/N] ").upper() != "Y": + if input("Do you want to proceed? [y/N] ").upper() != "Y": return 0 prompt = ("Please enter the passphrase that will be used to {}verify " diff --git a/qubes/tools/qvm_backup_restore.py b/qubes/tools/qvm_backup_restore.py index 6a389401..88dbf1f4 100644 --- a/qubes/tools/qvm_backup_restore.py +++ b/qubes/tools/qvm_backup_restore.py @@ -1,5 +1,3 @@ -#!/usr/bin/python2 -# -*- encoding: utf8 -*- # # The Qubes OS Project, http://www.qubes-os.org # @@ -249,7 +247,7 @@ def main(args=None): parser.error_runtime(str(e)) if args.pass_file is None: - if raw_input("Do you want to proceed? [y/N] ").upper() != "Y": + if input("Do you want to proceed? [y/N] ").upper() != "Y": exit(0) try: diff --git a/qubes/tools/qvm_block.py b/qubes/tools/qvm_block.py index 92019f46..db114820 100644 --- a/qubes/tools/qvm_block.py +++ b/qubes/tools/qvm_block.py @@ -1,6 +1,5 @@ -#!/usr/bin/python2 # pylint: disable=C,R -# -*- encoding: utf8 -*- + # # The Qubes OS Project, http://www.qubes-os.org # @@ -132,10 +131,10 @@ def list_volumes(args): if hasattr(args, 'domains') and args.domains: result = [x # reduce to only VolumeData with assigned domains - for p in vd_dict.itervalues() for x in p.itervalues() + for p in vd_dict.values() for x in p.values() if x.domains] else: - result = [x for p in vd_dict.itervalues() for x in p.itervalues()] + result = [x for p in vd_dict.values() for x in p.values()] qubes.tools.print_table(prepare_table(result, full=args.full)) def revert_volume(args): @@ -145,7 +144,7 @@ def revert_volume(args): pool = app.pools[volume.pool] pool.revert(volume) except qubes.storage.StoragePoolException as e: - print(e.message, file=sys.stderr) + print(str(e), file=sys.stderr) sys.exit(1) def attach_volumes(args): @@ -158,7 +157,7 @@ def attach_volumes(args): rw = not args.ro vm.storage.attach(volume, rw=rw) except qubes.storage.StoragePoolException as e: - print(e.message, file=sys.stderr) + print(str(e), file=sys.stderr) sys.exit(1) @@ -171,7 +170,7 @@ def detach_volumes(args): try: vm.storage.detach(volume) except qubes.storage.StoragePoolException as e: - print(e.message, file=sys.stderr) + print(str(e), file=sys.stderr) sys.exit(1) @@ -266,7 +265,7 @@ def main(args=None): args = parser.parse_args(args) args.func(args) except qubes.exc.QubesException as e: - parser.print_error(e.message) + parser.print_error(str(e)) return 1 diff --git a/qubes/tools/qvm_check.py b/qubes/tools/qvm_check.py index 834140ca..0a911528 100644 --- a/qubes/tools/qvm_check.py +++ b/qubes/tools/qvm_check.py @@ -1,6 +1,5 @@ -#!/usr/bin/python2 -# -*- encoding: utf8 -*- -# :pylint: disable=too-few-public-methods +# pylint: disable=too-few-public-methods + # # The Qubes OS Project, http://www.qubes-os.org # diff --git a/qubes/tools/qvm_clone.py b/qubes/tools/qvm_clone.py index f3444d1f..9cc90e50 100644 --- a/qubes/tools/qvm_clone.py +++ b/qubes/tools/qvm_clone.py @@ -1,5 +1,3 @@ -#!/usr/bin/python2 -# -*- encoding: utf8 -*- # # The Qubes OS Project, http://www.qubes-os.org # diff --git a/qubes/tools/qvm_create.py b/qubes/tools/qvm_create.py index acf2cbfa..b7e736d2 100644 --- a/qubes/tools/qvm_create.py +++ b/qubes/tools/qvm_create.py @@ -1,5 +1,3 @@ -#!/usr/bin/python2 -# -*- encoding: utf8 -*- # # The Qubes OS Project, http://www.qubes-os.org # diff --git a/qubes/tools/qvm_device.py b/qubes/tools/qvm_device.py index df20ad94..6f6a79a9 100644 --- a/qubes/tools/qvm_device.py +++ b/qubes/tools/qvm_device.py @@ -1,6 +1,5 @@ -#!/usr/bin/python2 -# coding=utf-8 # pylint: disable=C,R + # # The Qubes OS Project, http://www.qubes-os.org # @@ -194,7 +193,7 @@ def main(args=None): try: args.func(args) except qubes.exc.QubesException as e: - print(e.message, file=sys.stderr) + print(str(e), file=sys.stderr) return 1 return 0 diff --git a/qubes/tools/qvm_features.py b/qubes/tools/qvm_features.py index 9b135ea0..846e36d7 100644 --- a/qubes/tools/qvm_features.py +++ b/qubes/tools/qvm_features.py @@ -1,6 +1,3 @@ -#!/usr/bin/python2 -O -# vim: fileencoding=utf-8 - # # The Qubes OS Project, https://www.qubes-os.org/ # diff --git a/qubes/tools/qvm_firewall.py b/qubes/tools/qvm_firewall.py index 47e730dd..478406f3 100644 --- a/qubes/tools/qvm_firewall.py +++ b/qubes/tools/qvm_firewall.py @@ -1,5 +1,3 @@ -#!/usr/bin/python2 -# -*- encoding: utf8 -*- # # The Qubes OS Project, http://www.qubes-os.org # @@ -163,7 +161,7 @@ def main(args=None): if args.reload: vm.fire_event('firewall-changed') except qubes.exc.QubesException as e: - parser.print_error(e.message) + parser.print_error(str(e)) return 1 return 0 diff --git a/qubes/tools/qvm_kill.py b/qubes/tools/qvm_kill.py index 6bfbe6d1..b71050dd 100644 --- a/qubes/tools/qvm_kill.py +++ b/qubes/tools/qvm_kill.py @@ -1,6 +1,3 @@ -#!/usr/bin/python2 -O -# vim: fileencoding=utf-8 - # # The Qubes OS Project, https://www.qubes-os.org/ # diff --git a/qubes/tools/qvm_ls.py b/qubes/tools/qvm_ls.py index 9c222b2d..4748b3f0 100644 --- a/qubes/tools/qvm_ls.py +++ b/qubes/tools/qvm_ls.py @@ -1,5 +1,3 @@ -#!/usr/bin/python -O -# vim: fileencoding=utf-8 # pylint: disable=too-few-public-methods # @@ -28,7 +26,6 @@ from __future__ import print_function -import __builtin__ import argparse import collections import sys @@ -101,7 +98,7 @@ class Column(object): ret = None try: - if isinstance(self._attr, basestring): + if isinstance(self._attr, str): ret = vm for attrseg in self._attr.split('.'): ret = getattr(ret, attrseg) @@ -151,7 +148,7 @@ def column(width=0, head=None): def decorator(obj): # pylint: disable=missing-docstring # we keep hints on fget, so the order of decorators does not matter - holder = obj.fget if isinstance(obj, __builtin__.property) else obj + holder = obj.fget if isinstance(obj, property) else obj try: holder.ls_head = head or holder.__name__.replace('_', '-').upper() @@ -202,7 +199,7 @@ def process_class(cls): for klass in cls.__mro__: for prop in klass.__dict__.values(): holder = prop.fget \ - if isinstance(prop, __builtin__.property) \ + if isinstance(prop, property) \ else prop if not hasattr(holder, 'ls_head') or holder.ls_head is None: continue @@ -616,7 +613,7 @@ def main(args=None): try: args = parser.parse_args(args) except qubes.exc.QubesException as e: - parser.print_error(e.message) + parser.print_error(str(e)) return 1 if args.fields: diff --git a/qubes/tools/qvm_pause.py b/qubes/tools/qvm_pause.py index 5bb20abf..9dd6ea56 100644 --- a/qubes/tools/qvm_pause.py +++ b/qubes/tools/qvm_pause.py @@ -1,6 +1,3 @@ -#!/usr/bin/python2 -O -# vim: fileencoding=utf-8 - # # The Qubes OS Project, https://www.qubes-os.org/ # diff --git a/qubes/tools/qvm_pool.py b/qubes/tools/qvm_pool.py index ca289f6d..2c141988 100644 --- a/qubes/tools/qvm_pool.py +++ b/qubes/tools/qvm_pool.py @@ -1,6 +1,5 @@ -#!/usr/bin/python2 -# -*- encoding: utf8 -*- -# :pylint: disable=too-few-public-methods +# pylint: disable=too-few-public-methods + # # The Qubes OS Project, http://www.qubes-os.org # @@ -190,7 +189,7 @@ def main(args=None): try: args = parser.parse_args(args) except qubes.exc.QubesException as e: - parser.print_error(e.message) + parser.print_error(str(e)) return 1 if args.command is None or args.command == 'list': diff --git a/qubes/tools/qvm_prefs.py b/qubes/tools/qvm_prefs.py index 5a3d545c..9822df3a 100644 --- a/qubes/tools/qvm_prefs.py +++ b/qubes/tools/qvm_prefs.py @@ -1,5 +1,3 @@ -#!/usr/bin/python2 -# -*- encoding: utf8 -*- # # The Qubes OS Project, http://www.qubes-os.org # diff --git a/qubes/tools/qvm_remove.py b/qubes/tools/qvm_remove.py index 50f27a07..c1f6e6f1 100644 --- a/qubes/tools/qvm_remove.py +++ b/qubes/tools/qvm_remove.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python2 -# -*- encoding: utf8 -*- # # The Qubes OS Project, http://www.qubes-os.org # diff --git a/qubes/tools/qvm_run.py b/qubes/tools/qvm_run.py index 0fcd623e..fff33a0d 100644 --- a/qubes/tools/qvm_run.py +++ b/qubes/tools/qvm_run.py @@ -1,5 +1,3 @@ -#!/usr/bin/python2 -# -*- encoding: utf8 -*- # # The Qubes OS Project, http://www.qubes-os.org # diff --git a/qubes/tools/qvm_shutdown.py b/qubes/tools/qvm_shutdown.py index 6b82cfd1..e761ff5c 100644 --- a/qubes/tools/qvm_shutdown.py +++ b/qubes/tools/qvm_shutdown.py @@ -1,5 +1,3 @@ -#!/usr/bin/python2 -# vim: fileencoding=utf8 # # The Qubes OS Project, http://www.qubes-os.org # diff --git a/qubes/tools/qvm_start.py b/qubes/tools/qvm_start.py index 5e8bfd17..6c38123b 100644 --- a/qubes/tools/qvm_start.py +++ b/qubes/tools/qvm_start.py @@ -1,6 +1,3 @@ -#!/usr/bin/python2 -O -# vim: fileencoding=utf-8 - # # The Qubes OS Project, https://www.qubes-os.org/ # diff --git a/qubes/tools/qvm_tags.py b/qubes/tools/qvm_tags.py index 267b6361..ced269f3 100644 --- a/qubes/tools/qvm_tags.py +++ b/qubes/tools/qvm_tags.py @@ -1,6 +1,3 @@ -#!/usr/bin/python2 -O -# vim: fileencoding=utf-8 - # # The Qubes OS Project, https://www.qubes-os.org/ # diff --git a/qubes/tools/qvm_template_commit.py b/qubes/tools/qvm_template_commit.py index f89b148a..d7ff5aff 100644 --- a/qubes/tools/qvm_template_commit.py +++ b/qubes/tools/qvm_template_commit.py @@ -1,6 +1,3 @@ -#!/usr/bin/python2 -O -# vim: fileencoding=utf-8 - # # The Qubes OS Project, https://www.qubes-os.org/ # diff --git a/qubes/tools/qvm_template_postprocess.py b/qubes/tools/qvm_template_postprocess.py index 2535085d..e484a849 100644 --- a/qubes/tools/qvm_template_postprocess.py +++ b/qubes/tools/qvm_template_postprocess.py @@ -1,6 +1,3 @@ -#!/usr/bin/python2 -O -# vim: fileencoding=utf-8 - # # The Qubes OS Project, https://www.qubes-os.org/ # diff --git a/qubes/tools/qvm_unpause.py b/qubes/tools/qvm_unpause.py index b1694789..2000ea74 100644 --- a/qubes/tools/qvm_unpause.py +++ b/qubes/tools/qvm_unpause.py @@ -1,6 +1,3 @@ -#!/usr/bin/python2 -O -# vim: fileencoding=utf-8 - # # The Qubes OS Project, https://www.qubes-os.org/ # diff --git a/qubes/utils.py b/qubes/utils.py index d2170495..b20d3843 100644 --- a/qubes/utils.py +++ b/qubes/utils.py @@ -1,6 +1,3 @@ -#!/usr/bin/python2 -O -# vim: fileencoding=utf-8 - # # The Qubes OS Project, https://www.qubes-os.org/ # diff --git a/qubes/vm/__init__.py b/qubes/vm/__init__.py index 45312695..3a8ffc60 100644 --- a/qubes/vm/__init__.py +++ b/qubes/vm/__init__.py @@ -1,6 +1,3 @@ -#!/usr/bin/python2 -O -# vim: fileencoding=utf-8 - # # The Qubes OS Project, https://www.qubes-os.org/ # @@ -143,7 +140,7 @@ class BaseVMMeta(qubes.events.EmitterMeta): qubes.tools.qvm_ls.process_class(cls) -class BaseVM(qubes.PropertyHolder): +class BaseVM(qubes.PropertyHolder, metaclass=BaseVMMeta): '''Base class for all VMs :param app: Qubes application context @@ -157,8 +154,6 @@ class BaseVM(qubes.PropertyHolder): ''' # pylint: disable=no-member - __metaclass__ = BaseVMMeta - def __init__(self, app, xml, features=None, devices=None, tags=None, **kwargs): # pylint: disable=redefined-outer-name diff --git a/qubes/vm/adminvm.py b/qubes/vm/adminvm.py index f6b17df5..13671ff4 100644 --- a/qubes/vm/adminvm.py +++ b/qubes/vm/adminvm.py @@ -1,5 +1,3 @@ -#!/usr/bin/python2 -O -# vim: fileencoding=utf-8 # # The Qubes OS Project, https://www.qubes-os.org/ # diff --git a/qubes/vm/appvm.py b/qubes/vm/appvm.py index c8e63835..3733f6ce 100644 --- a/qubes/vm/appvm.py +++ b/qubes/vm/appvm.py @@ -1,5 +1,3 @@ -#!/usr/bin/python2 -O -# vim: fileencoding=utf-8 # # The Qubes OS Project, http://www.qubes-os.org # diff --git a/qubes/vm/dispvm.py b/qubes/vm/dispvm.py index 78124c2b..234626a3 100644 --- a/qubes/vm/dispvm.py +++ b/qubes/vm/dispvm.py @@ -1,5 +1,3 @@ -#!/usr/bin/python2 -O -# vim: fileencoding=utf-8 # # The Qubes OS Project, http://www.qubes-os.org # @@ -22,6 +20,7 @@ # ''' A disposable vm implementation ''' + import copy import qubes.vm.qubesvm diff --git a/qubes/vm/mix/net.py b/qubes/vm/mix/net.py index e7227faf..16b1f41d 100644 --- a/qubes/vm/mix/net.py +++ b/qubes/vm/mix/net.py @@ -1,5 +1,3 @@ -#!/usr/bin/python2 -O -# vim: fileencoding=utf-8 # # The Qubes OS Project, https://www.qubes-os.org/ # @@ -24,6 +22,7 @@ # ''' This module contains the NetVMMixin ''' + import os import re @@ -37,7 +36,7 @@ import qubes.exc def _setter_mac(self, prop, value): ''' Helper for setting the MAC address ''' # pylint: disable=unused-argument - if not isinstance(value, basestring): + if not isinstance(value, str): raise ValueError('MAC address must be a string') value = value.lower() if re.match(r"^([0-9a-f][0-9a-f]:){5}[0-9a-f][0-9a-f]$", value) is None: @@ -56,7 +55,7 @@ def _default_ip(self): def _setter_ip(self, prop, value): # pylint: disable=unused-argument - if not isinstance(value, basestring): + if not isinstance(value, str): raise ValueError('IP address must be a string') value = value.lower() if re.match(r"^([0-9]{1,3}.){3}[0-9]{1,3}$", value) is None: diff --git a/qubes/vm/qubesvm.py b/qubes/vm/qubesvm.py index 19646128..3a1346b5 100644 --- a/qubes/vm/qubesvm.py +++ b/qubes/vm/qubesvm.py @@ -1,5 +1,3 @@ -#!/usr/bin/python2 -O -# vim: fileencoding=utf-8 # # The Qubes OS Project, https://www.qubes-os.org/ # @@ -79,7 +77,7 @@ def _setter_qid(self, prop, value): def _setter_name(self, prop, value): ''' Helper for setting the domain name ''' - if not isinstance(value, basestring): + if not isinstance(value, str): raise TypeError('{} value must be string, {!r} found'.format( prop.__name__, type(value).__name__)) if len(value) > 31: @@ -135,7 +133,7 @@ def _setter_label(self, prop, value): # pylint: disable=unused-argument if isinstance(value, qubes.Label): return value - if isinstance(value, basestring) and value.startswith('label-'): + if isinstance(value, str) and value.startswith('label-'): return self.app.labels[int(value.split('-', 1)[1])] return self.app.get_label(value) @@ -673,6 +671,9 @@ class QubesVM(qubes.vm.mix.net.NetVMMixin, qubes.vm.BaseVM): def __hash__(self): return self.qid + def __lt__(self, other): + return self.name < other.name + def __xml__(self): element = super(QubesVM, self).__xml__() diff --git a/qubes/vm/standalonevm.py b/qubes/vm/standalonevm.py index bbbc9ec4..ef3b59d1 100644 --- a/qubes/vm/standalonevm.py +++ b/qubes/vm/standalonevm.py @@ -1,6 +1,3 @@ -#!/usr/bin/python2 -O -# vim: fileencoding=utf-8 - # # The Qubes OS Project, https://www.qubes-os.org/ # diff --git a/qubes/vm/templatevm.py b/qubes/vm/templatevm.py index fc172b98..400eea85 100644 --- a/qubes/vm/templatevm.py +++ b/qubes/vm/templatevm.py @@ -1,5 +1,3 @@ -#!/usr/bin/python2 -O -# vim: fileencoding=utf-8 # # The Qubes OS Project, http://www.qubes-os.org #