diff options
author | Christian Heimes <cheimes@redhat.com> | 2016-02-26 17:18:57 +0100 |
---|---|---|
committer | Christian Heimes <cheimes@redhat.com> | 2016-02-26 20:14:10 +0100 |
commit | d5360c915761773e93333b6894df4bd8ac8a2f13 (patch) | |
tree | c3d0157de1d3dbd8c35fd855bcc28c1e61024e06 /base/server/python | |
parent | 0dadf421c327bc32d220405208031a9f7e1bb097 (diff) | |
download | pki-d5360c915761773e93333b6894df4bd8ac8a2f13.tar.gz pki-d5360c915761773e93333b6894df4bd8ac8a2f13.tar.xz pki-d5360c915761773e93333b6894df4bd8ac8a2f13.zip |
Implement total ordering for PKISubsystem and PKIInstance
In Python 3 subclasses no longer implement automatic ordering. To
provide ordering for sort() and custom comparison, __eq__ and __lt__ are
required.
https://fedorahosted.org/pki/ticket/2216
Diffstat (limited to 'base/server/python')
-rw-r--r-- | base/server/python/pki/server/__init__.py | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/base/server/python/pki/server/__init__.py b/base/server/python/pki/server/__init__.py index e308a5033..2364131c6 100644 --- a/base/server/python/pki/server/__init__.py +++ b/base/server/python/pki/server/__init__.py @@ -20,6 +20,7 @@ from __future__ import absolute_import from lxml import etree +import functools import getpass import grp import io @@ -59,6 +60,7 @@ class PKIServer(object): return instances +@functools.total_ordering class PKISubsystem(object): def __init__(self, instance, subsystem_name): @@ -92,6 +94,29 @@ class PKISubsystem(object): # custom subsystem location self.doc_base = os.path.join(self.base_dir, 'webapps', self.name) + def __eq__(self, other): + if not isinstance(other, PKISubsystem): + return NotImplemented + return (self.name == other.name and + self.instance == other.instance and + self.type == other.type) + + def __ne__(self, other): + if not isinstance(other, PKISubsystem): + return NotImplemented + return not self.__eq__(other) + + def __lt__(self, other): + if not isinstance(other, PKISubsystem): + return NotImplemented + self_type = self.type if self.type is not None else '' + other_type = other.type if other.type is not None else '' + return (self.name < other.name or + self.instance < other.instance or + self_type < other_type) + + __hash__ = None + def load(self): self.config.clear() @@ -335,6 +360,7 @@ class PKISubsystem(object): return str(self.instance) + '/' + self.name +@functools.total_ordering class PKIInstance(object): def __init__(self, name, instanceType=10): # nopep8 @@ -371,6 +397,25 @@ class PKIInstance(object): self.subsystems = [] + def __eq__(self, other): + if not isinstance(other, PKIInstance): + return NotImplemented + return (self.name == other.name and + self.type == other.type) + + def __ne__(self, other): + if not isinstance(other, PKIInstance): + return NotImplemented + return not self.__eq__(other) + + def __lt__(self, other): + if not isinstance(other, PKIInstance): + return NotImplemented + return (self.name < other.name or + self.type < other.type) + + __hash__ = None + def is_valid(self): return os.path.exists(self.conf_dir) |