from .idict import CaseInsensitiveDict
from .istringset import CaseInsensitiveStringSet
-__version__ = '0.8.8'
+__version__ = '0.8.9'
LOG = logging.getLogger(__name__)
CFG_BASENAME = 'ldap-migration.ini'
val = 0
if attribute in self.integer_attribute_types:
-
- if is_sequence(src_val):
- val = []
- for value in src_val:
- if isinstance(value, Number):
- val.append(value)
- continue
- try:
- mbytes = human2mbytes(value, as_float=True)
- val.append(int(mbytes * 1024 * 1024))
- except ValueError as e:
- msg = "Invalid value in attribute {attr!r} of item {dn!r}: {e}"
- msg = msg.format(attr=attribute, dn=src_dn, e=e)
- raise ReadLDAPItemError(msg)
- else:
- if isinstance(src_val, Number):
- val = src_val
- try:
- mbytes = human2mbytes(src_val, as_float=True)
- val = int(mbytes * 1024 * 1024)
- except ValueError as e:
- msg = "Invalid value in attribute {attr!r} of item {dn!r}: {e}"
- msg = msg.format(attr=attribute, dn=src_dn, e=e)
- raise ReadLDAPItemError(msg)
+ val = self._get_integer_value(src_val)
if self.verbose > 1:
msg = "Migrated integer value: {old!r} => {new!r}.".format(
return entry
+ # -------------------------------------------------------------------------
+ def _get_integer_value(self, src_val):
+
+ val = 0
+
+ if is_sequence(src_val):
+ val = []
+ for value in src_val:
+ if isinstance(value, Number):
+ val.append(value)
+ continue
+ try:
+ v_bytes = int(value)
+ val.append(v_bytes)
+ continue
+ except ValueError as e:
+ if self.verbose > 3:
+ msg = "Could not interprete {v!r} a an integer value: {e}".format(
+ v=value, e=e)
+ LOG.debug(msg)
+ try:
+ mbytes = human2mbytes(value, as_float=True)
+ val.append(int(mbytes * 1024 * 1024))
+ except ValueError as e:
+ msg = "Invalid value in attribute {attr!r} of item {dn!r}: {e}"
+ msg = msg.format(attr=attribute, dn=src_dn, e=e)
+ raise ReadLDAPItemError(msg)
+
+ return val
+
+ if isinstance(src_val, Number):
+ return src_val
+
+ try:
+ v_bytes = int(src_val)
+ return v_bytes
+
+ except ValueError as e:
+ pass
+
+ if self.verbose > 3:
+ msg = "Could not interprete {v!r} a an integer value: {e}".format(
+ v=src_val, e=e)
+ LOG.debug(msg)
+
+ try:
+ mbytes = human2mbytes(src_val, as_float=True)
+ val = int(mbytes * 1024 * 1024)
+ return val
+ except ValueError as e:
+ msg = "Invalid value in attribute {attr!r} of item {dn!r}: {e}"
+ msg = msg.format(attr=attribute, dn=src_dn, e=e)
+ raise ReadLDAPItemError(msg)
+
+ return 0
+
+
# -------------------------------------------------------------------------
def get_target_item(self, tgt_dn, with_acl=False):