Commit eb62069e authored by Iustin Pop's avatar Iustin Pop
Browse files

Add two more compat functions



operator.itemgetter(0) → fst
operator.itemgetter(1) → snd

snd is not used yet, but it makes sense to add both.
Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarGuido Trotter <ultrotter@google.com>
parent 7c070961
......@@ -44,7 +44,7 @@ from ganeti import rapi
import ganeti.rapi.rlib2 # pylint: disable-msg=W0611
COMMON_PARAM_NAMES = map(operator.itemgetter(0), opcodes.OpCode.OP_PARAMS)
COMMON_PARAM_NAMES = map(compat.fst, opcodes.OpCode.OP_PARAMS)
#: Namespace for evaluating expressions
EVAL_NS = dict(compat=compat, constants=constants, utils=utils, errors=errors,
......@@ -98,7 +98,7 @@ def _BuildOpcodeParams(op_id, include, exclude, alias):
params_with_alias = \
utils.NiceSort([(alias.get(name, name), name, default, test, doc)
for (name, default, test, doc) in op_cls.GetAllParams()],
key=operator.itemgetter(0))
key=compat.fst)
for (rapi_name, name, default, test, doc) in params_with_alias:
# Hide common parameters if not explicitely included
......@@ -227,7 +227,7 @@ def BuildQueryFields(fields):
"""
for (_, (fdef, _, _, _)) in utils.NiceSort(fields.items(),
key=operator.itemgetter(0)):
key=compat.fst):
assert len(fdef.doc.splitlines()) == 1
yield "``%s``" % fdef.name
yield " %s" % fdef.doc
......
#
#
# Copyright (C) 2010 Google Inc.
# Copyright (C) 2010, 2011 Google Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
......@@ -24,6 +24,7 @@
"""
import itertools
import operator
try:
# pylint: disable-msg=F0401
......@@ -143,3 +144,8 @@ def TryToRoman(val, convert=True):
else:
return val
#: returns the first element of a list-like value
fst = operator.itemgetter(0)
#: returns the second element of a list-like value
snd = operator.itemgetter(1)
#
#
# Copyright (C) 2006, 2007, 2008, 2009, 2010 Google Inc.
# Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 Google Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
......@@ -1729,7 +1729,7 @@ class LockMonitor(object):
key=_MonitorSortKey)
# Extract lock information and build query data
return (qobj, query.LockQueryData(map(operator.itemgetter(0), lockinfo)))
return (qobj, query.LockQueryData(map(compat.fst, lockinfo)))
def QueryLocks(self, fields):
"""Queries information from all locks.
......
......@@ -37,6 +37,7 @@ import logging
import re
import operator
from ganeti import compat
from ganeti import constants
from ganeti import errors
from ganeti import ht
......@@ -135,7 +136,7 @@ _OPID_RE = re.compile("([a-z])([A-Z])")
#: Utility function for L{OpClusterSetParams}
_TestClusterOsList = ht.TOr(ht.TNone,
ht.TListOf(ht.TAnd(ht.TList, ht.TIsLength(2),
ht.TMap(ht.WithDesc("GetFirstItem")(operator.itemgetter(0)),
ht.TMap(ht.WithDesc("GetFirstItem")(compat.fst),
ht.TElemOf(constants.DDMS_VALUES)))))
......
......@@ -2018,8 +2018,7 @@ def _BuildOsFields():
None, 0, _ConvWrap(sorted, _GetItemAttr("api_versions"))),
(_MakeField("parameters", "Parameters", QFT_OTHER,
"Operating system parameters"),
None, 0, _ConvWrap(compat.partial(utils.NiceSort,
key=operator.itemgetter(0)),
None, 0, _ConvWrap(compat.partial(utils.NiceSort, key=compat.fst),
_GetItemAttr("parameters"))),
(_MakeField("node_status", "NodeStatus", QFT_OTHER,
"Status from node"),
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment