diff options
author | Chris St. Pierre <chris.a.st.pierre@gmail.com> | 2012-08-20 13:40:29 -0400 |
---|---|---|
committer | Chris St. Pierre <chris.a.st.pierre@gmail.com> | 2012-08-20 13:40:29 -0400 |
commit | 854aaf4986cd79b659fe4de0b1d319dbd5f9ac92 (patch) | |
tree | 0c83c562c23e4562e0b1a146e2b2753713495c76 | |
parent | 7cfa4498a417f6b52a0c159dbd680496b47e279e (diff) | |
download | bcfg2-854aaf4986cd79b659fe4de0b1d319dbd5f9ac92.tar.gz bcfg2-854aaf4986cd79b659fe4de0b1d319dbd5f9ac92.tar.bz2 bcfg2-854aaf4986cd79b659fe4de0b1d319dbd5f9ac92.zip |
added CmpMixin to provide __cmp__ functionality to py3k
-rw-r--r-- | src/lib/Bcfg2/Bcfg2Py3k.py | 22 | ||||
-rw-r--r-- | src/lib/Bcfg2/Server/Plugin.py | 5 | ||||
-rw-r--r-- | src/lib/Bcfg2/Server/SchemaUpdater/__init__.py | 5 |
3 files changed, 29 insertions, 3 deletions
diff --git a/src/lib/Bcfg2/Bcfg2Py3k.py b/src/lib/Bcfg2/Bcfg2Py3k.py index 7fce94789..784ac118f 100644 --- a/src/lib/Bcfg2/Bcfg2Py3k.py +++ b/src/lib/Bcfg2/Bcfg2Py3k.py @@ -92,3 +92,25 @@ try: from collections import MutableMapping except ImportError: from UserDict import DictMixin as MutableMapping + + +# in py3k __cmp__ is no longer magical, so we define a mixin that can +# be used to define the rich comparison operators from __cmp__ +class CmpMixin(object): + def __lt__(self, other): + return self.__cmp__(other) < 0 + + def __gt__(self, other): + return self.__cmp__(other) > 0 + + def __eq__(self, other): + return self.__cmp__(other) == 0 + + def __ne__(self, other): + return not self.__eq__(other) + + def __ge__(self, other): + return self.__gt__(other) or self.__eq__(other) + + def __le__(self, other): + return self.__lt__(other) or self.__eq__(other) diff --git a/src/lib/Bcfg2/Server/Plugin.py b/src/lib/Bcfg2/Server/Plugin.py index c6e626a5c..82162aa4a 100644 --- a/src/lib/Bcfg2/Server/Plugin.py +++ b/src/lib/Bcfg2/Server/Plugin.py @@ -10,7 +10,7 @@ import threading import lxml.etree import Bcfg2.Server import Bcfg2.Options -from Bcfg2.Bcfg2Py3k import ConfigParser +from Bcfg2.Bcfg2Py3k import ConfigParser, CmpMixin try: import django @@ -992,9 +992,10 @@ class SpecificityError(Exception): pass -class Specificity(object): +class Specificity(CmpMixin): def __init__(self, all=False, group=False, hostname=False, prio=0, delta=False): + CmpMixin.__init__(self) self.hostname = hostname self.all = all self.group = group diff --git a/src/lib/Bcfg2/Server/SchemaUpdater/__init__.py b/src/lib/Bcfg2/Server/SchemaUpdater/__init__.py index 1ea41c880..186f8797c 100644 --- a/src/lib/Bcfg2/Server/SchemaUpdater/__init__.py +++ b/src/lib/Bcfg2/Server/SchemaUpdater/__init__.py @@ -7,6 +7,7 @@ import re import sys import traceback +from Bcfg2.Py3k import CmpMixin from Bcfg2.Server.models import InternalDatabaseVersion from Bcfg2.Server.SchemaUpdater.Routines import UpdaterRoutineException, \ UpdaterRoutine @@ -50,10 +51,12 @@ def _release_to_version(release): return int("%02d%02d00" % (int(m.group(1)), int(m.group(2)))) -class Updater(object): +class Updater(CmpMixin): """Database updater to standardize updates""" def __init__(self, release): + CmpMixin.__init__(self) + self._cursor = None self._release = release try: |