pvs_info.reverse()
pvlist = [ pv[1] for pv in pvs_info ]
- if compat.any(pvlist, lambda v: ":" in v):
+ if compat.any(":" in v for v in pvlist):
_ThrowError("Some of your PVs have the invalid character ':' in their"
" name, this is not supported - please filter them out"
" in lvm.conf using either 'filter' or 'preferred_names'")
"""
if (not cls._VALID_NAME_RE.match(name) or
name in cls._INVALID_NAMES or
- compat.any(cls._INVALID_SUBSTRINGS, lambda x: x in name)):
+ compat.any(substring in name for substring in cls._INVALID_SUBSTRINGS)):
_ThrowError("Invalid LVM name '%s'", name)
def Remove(self):
"""
return _TAnd(_TList,
- lambda lst: compat.all(lst, my_type))
+ lambda lst: compat.all(my_type(v) for v in lst))
def _TDictOf(key_type, val_type):
"""
return _TAnd(_TDict,
- lambda my_dict: (compat.all(my_dict.keys(), key_type) and
- compat.all(my_dict.values(), val_type)))
+ lambda my_dict: (compat.all(key_type(v) for v in my_dict.keys())
+ and compat.all(val_type(v)
+ for v in my_dict.values())))
# End types
remote_os = nresult.get(constants.NV_OSLIST, None)
test = (not isinstance(remote_os, list) or
- not compat.all(remote_os,
- lambda v: isinstance(v, list) and len(v) == 7))
+ not compat.all(isinstance(v, list) and len(v) == 7
+ for v in remote_os))
_ErrorIf(test, self.ENODEOS, node,
"node hasn't returned valid OS data")
"OS '%s' has multiple entries (first one shadows the rest): %s",
os_name, utils.CommaJoin([v[0] for v in os_data]))
# this will catched in backend too
- _ErrorIf(compat.any(f_api, lambda v: v >= constants.OS_API_V15)
+ _ErrorIf(compat.any(v >= constants.OS_API_V15 for v in f_api)
and not f_var, self.ENODEOS, node,
"OS %s with API at least %d does not declare any variant",
os_name, constants.OS_API_V15)
sha1_hash = sha.new
-def all(seq, pred=bool): # pylint: disable-msg=W0622
- """Returns True if pred(x) is True for every element in the iterable.
-
- Please note that this function provides a C{pred} parameter which isn't
- available in the version included in Python 2.5 and above.
+def _all(seq):
+ """Returns True if all elements in the iterable are True.
"""
- for _ in itertools.ifilterfalse(pred, seq):
+ for _ in itertools.ifilterfalse(bool, seq):
return False
return True
-
-def any(seq, pred=bool): # pylint: disable-msg=W0622
- """Returns True if pred(x) is True for at least one element in the iterable.
-
- Please note that this function provides a C{pred} parameter which isn't
- available in the version included in Python 2.5 and above.
+def _any(seq):
+ """Returns True if any element of the iterable are True.
"""
- for _ in itertools.ifilter(pred, seq):
+ for _ in itertools.ifilter(bool, seq):
return True
return False
+try:
+ all = all # pylint: disable-msg=W0622
+except NameError:
+ all = _all
+
+try:
+ any = any # pylint: disable-msg=W0622
+except NameError:
+ any = _any
def partition(seq, pred=bool): # pylint: disable-msg=W0622
"""Partition a list in two, based on the given predicate.
return newfunc
+if functools is None:
+ partial = _partial
+else:
+ partial = functools.partial
+
+
def TryToRoman(val, convert=True):
"""Try to convert a value to roman numerals
else:
return val
-
-if functools is None:
- partial = _partial
-else:
- partial = functools.partial
logging.exception("%s failed", diskie.MODE_TEXT)
diskie.Finalize(error=str(err))
- if not compat.any([diskie.active for diskie in self._queue]):
+ if not compat.any(diskie.active for diskie in self._queue):
break
# Wait a bit
ieloop.FinalizeAll()
assert len(all_dtp) == len(all_transfers)
- assert compat.all([(dtp.src_export is None or
+ assert compat.all((dtp.src_export is None or
dtp.src_export.success is not None) and
(dtp.dest_import is None or
dtp.dest_import.success is not None)
- for dtp in all_dtp]), \
+ for dtp in all_dtp), \
"Not all imports/exports are finalized"
return [bool(dtp.success) for dtp in all_dtp]
if missing:
for iname, ival in missing.iteritems():
- all_missing = compat.all(ival, lambda x: x[0] in bad_nodes)
+ all_missing = compat.all(x[0] in bad_nodes for x in ival)
if all_missing:
ToStdout("Instance %s cannot be verified as it lives on"
" broken nodes", iname)
self.BurnReplaceDisks2()
if (opts.disk_template in constants.DTS_GROWABLE and
- compat.any(self.disk_growth, lambda n: n > 0)):
+ compat.any(n > 0 for n in self.disk_growth)):
self.BurnGrowDisks()
if opts.do_failover and opts.disk_template in constants.DTS_NET_MIRROR: