From dc2bf58d2148d451e003ce132691880070352ba1 Mon Sep 17 00:00:00 2001 From: Tushar Gohad Date: Mon, 23 Jun 2014 13:27:48 -0700 Subject: [PATCH] ec_iface: Store PyECLibEnum objects in ECDriver .. also explicitly specify init() arguments Signed-off-by: Tushar Gohad --- src/python/pyeclib/core.py | 35 ++++++++++------------------------ src/python/pyeclib/ec_iface.py | 25 ++++++++++++++++++------ 2 files changed, 29 insertions(+), 31 deletions(-) diff --git a/src/python/pyeclib/core.py b/src/python/pyeclib/core.py index eb6a3bf..077cade 100644 --- a/src/python/pyeclib/core.py +++ b/src/python/pyeclib/core.py @@ -21,7 +21,6 @@ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -from ec_iface import PyECLib_EC_Types from ec_iface import PyECLib_HDRCHKSUM_Types import math import pyeclib_c @@ -29,11 +28,8 @@ import sys pyver = float('%s.%s' % sys.version_info[:2]) -# + # Generic ECPyECLibException -# - - class ECPyECLibException(Exception): def __init__(self, error_str): @@ -45,35 +41,24 @@ class ECPyECLibException(Exception): class ECPyECLibDriver(object): - def __init__(self, k, m, ec_type, chksum_type="none"): + def __init__(self, k, m, ec_type, + chksum_type=PyECLib_HDRCHKSUM_Types.inline): self.k = k self.m = m - - if PyECLib_EC_Types.is_member(ec_type): - self.ec_type = ec_type - else: - raise ECPyECLibException("%s is not a valid EC type for PyECLib!" % - ec_type) - - if PyECLib_HDRCHKSUM_Types.is_member(chksum_type): - self.chksum_type = chksum_type - else: - raise ECPyECLibException( - "%s is not a valid checksum type for PyECLib!") + self.ec_type = ec_type + self.chksum_type = chksum_type self.inline_chksum = 0 self.algsig_chksum = 0 - if self.chksum_type == PyECLib_HDRCHKSUM_Types.inline: + if self.chksum_type is PyECLib_HDRCHKSUM_Types.inline: self.inline_chksum = 1 - self.algsig_chksum = 0 - elif self.chksum_type == PyECLib_HDRCHKSUM_Types.algsig: - self.inline_chksum = 0 + elif self.chksum_type is PyECLib_HDRCHKSUM_Types.algsig: self.algsig_chksum = 1 self.handle = pyeclib_c.init( self.k, self.m, - self.ec_type, + self.ec_type.name, self.inline_chksum, self.algsig_chksum) @@ -140,7 +125,7 @@ class ECPyECLibDriver(object): class ECNullDriver(object): - def __init__(self, k, m): + def __init__(self, k, m, ec_type=None, chksum_type=None): self.k = k self.m = m @@ -173,7 +158,7 @@ class ECNullDriver(object): # class ECStripingDriver(object): - def __init__(self, k, m): + def __init__(self, k, m, ec_type=None, chksum_type=None): """Stripe an arbitrary-sized string into k fragments :param k: the number of data fragments to stripe :param m: the number of parity fragments to stripe diff --git a/src/python/pyeclib/ec_iface.py b/src/python/pyeclib/ec_iface.py index 40feed0..995bdd8 100644 --- a/src/python/pyeclib/ec_iface.py +++ b/src/python/pyeclib/ec_iface.py @@ -100,6 +100,8 @@ class ECDriver(object): def __init__(self, library_import_str, *args, **kwargs): self.k = -1 self.m = -1 + self.ec_type = None + self.chksum_type = None self.library_import_str = None for (key, value) in kwargs.items(): if key == "k": @@ -115,9 +117,19 @@ class ECDriver(object): raise ECDriverError( "Invalid number of data fragments (m)") elif key == "ec_type": - self.ec_type = value + if PyECLib_EC_Types.has_enum(value): + self.ec_type = \ + PyECLib_EC_Types.get_by_name(value) + else: + raise ECDriverError( + "%s is not a valid EC type for PyECLib!" % value) elif key == "chksum_type": - self.chksum_type = value + if PyECLib_HDRCHKSUM_Types.has_enum(value): + self.chksum_type = \ + PyECLib_HDRCHKSUM_Types.get_by_name(value) + else: + raise ECDriverError( + "%s is not a valid checksum type for PyECLib!" % value) if library_import_str is not None: self.library_import_str = library_import_str @@ -126,13 +138,14 @@ class ECDriver(object): "Library import string (library_import_str) was not specified " "and is a required argument!") # - # We require keyword arguments to prevent ambiguity between EC libs + # Instantiate EC backend driver # self.ec_lib_reference = create_instance( library_import_str, - *args, - **kwargs) - + k=self.k, + m=self.m, + ec_type=self.ec_type, + chksum_type=self.chksum_type) # # Verify that the imported library implements the required functions #