functions: Derive function name from module name
Prevents redundancy. The same thing is already done for plugins.
This commit is contained in:
parent
422f14b0be
commit
ceb1ae61b4
26 changed files with 31 additions and 28 deletions
|
|
@ -8,12 +8,15 @@ class Function(object):
|
|||
"""
|
||||
Built-in function
|
||||
"""
|
||||
def __init__(self, name, nargs_max, nargs_min = None):
|
||||
self._name = name
|
||||
def __init__(self, nargs_max, nargs_min = None):
|
||||
self._nargs_max = nargs_max
|
||||
self._nargs_min = nargs_min
|
||||
self._cmd = commands()
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
return self.__class__.__module__.split(".")[-1].split("_", 1)[1]
|
||||
|
||||
# checks arguments
|
||||
# nargs_max - maximal number of arguments, there mustn't be more arguments,
|
||||
# if nargs_max is 0, number of arguments is unlimited
|
||||
|
|
@ -30,5 +33,5 @@ class Function(object):
|
|||
if self._check_args(args, self._nargs_max, self._nargs_min):
|
||||
return True
|
||||
else:
|
||||
log.error("invalid number of arguments for builtin function '%s'" % self._name)
|
||||
log.error("invalid number of arguments for builtin function '%s'" % self.name)
|
||||
return False
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ class Assertion(base.Function):
|
|||
"""
|
||||
def __init__(self):
|
||||
# 3 arguments
|
||||
super(Assertion, self).__init__("assertion", 3, 3)
|
||||
super(Assertion, self).__init__(3, 3)
|
||||
|
||||
def execute(self, args):
|
||||
if not super(Assertion, self).execute(args):
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ class AssertionNonEqual(base.Function):
|
|||
"""
|
||||
def __init__(self):
|
||||
# 3 arguments
|
||||
super(AssertionNonEqual, self).__init__("assertion_non_equal", 3, 3)
|
||||
super(AssertionNonEqual, self).__init__(3, 3)
|
||||
|
||||
def execute(self, args):
|
||||
if not super(AssertionNonEqual, self).execute(args):
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ class CalcIsolatedCores(base.Function):
|
|||
"""
|
||||
def __init__(self):
|
||||
# max 1 argument
|
||||
super(CalcIsolatedCores, self).__init__("calc_isolated_cores", 1)
|
||||
super(CalcIsolatedCores, self).__init__(1)
|
||||
|
||||
def execute(self, args):
|
||||
if not super(CalcIsolatedCores, self).execute(args):
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ class CheckNetQueueCount(base.Function):
|
|||
"""
|
||||
def __init__(self):
|
||||
# 1 argument
|
||||
super(CheckNetQueueCount, self).__init__("check_net_queue_count", 1, 1)
|
||||
super(CheckNetQueueCount, self).__init__(1, 1)
|
||||
|
||||
def execute(self, args):
|
||||
if not super(CheckNetQueueCount, self).execute(args):
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ class CPUInfoCheck(base.Function):
|
|||
"""
|
||||
def __init__(self):
|
||||
# unlimited number of arguments, min 2 arguments
|
||||
super(CPUInfoCheck, self).__init__("cpuinfo_check", 0, 2)
|
||||
super(CPUInfoCheck, self).__init__(0, 2)
|
||||
|
||||
def execute(self, args):
|
||||
if not super(CPUInfoCheck, self).execute(args):
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ class CPUList2Devs(base.Function):
|
|||
"""
|
||||
def __init__(self):
|
||||
# arbitrary number of arguments
|
||||
super(CPUList2Devs, self).__init__("cpulist2devs", 0)
|
||||
super(CPUList2Devs, self).__init__(0)
|
||||
|
||||
def execute(self, args):
|
||||
if not super(CPUList2Devs, self).execute(args):
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ class CPUList2Hex(base.Function):
|
|||
"""
|
||||
def __init__(self):
|
||||
# arbitrary number of arguments
|
||||
super(CPUList2Hex, self).__init__("cpulist2hex", 0)
|
||||
super(CPUList2Hex, self).__init__(0)
|
||||
|
||||
def execute(self, args):
|
||||
if not super(CPUList2Hex, self).execute(args):
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ class CPUList2HexInvert(base.Function):
|
|||
"""
|
||||
def __init__(self):
|
||||
# arbitrary number of arguments
|
||||
super(CPUList2HexInvert, self).__init__("cpulist2hex_invert", 0)
|
||||
super(CPUList2HexInvert, self).__init__(0)
|
||||
|
||||
def execute(self, args):
|
||||
if not super(CPUList2HexInvert, self).execute(args):
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ class CPUListInvert(base.Function):
|
|||
"""
|
||||
def __init__(self):
|
||||
# arbitrary number of arguments
|
||||
super(CPUListInvert, self).__init__("cpulist_invert", 0)
|
||||
super(CPUListInvert, self).__init__(0)
|
||||
|
||||
def execute(self, args):
|
||||
if not super(CPUListInvert, self).execute(args):
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ class CPUListOnline(base.Function):
|
|||
"""
|
||||
def __init__(self):
|
||||
# arbitrary number of arguments
|
||||
super(CPUListOnline, self).__init__("cpulist_online", 0)
|
||||
super(CPUListOnline, self).__init__(0)
|
||||
|
||||
def execute(self, args):
|
||||
if not super(CPUListOnline, self).execute(args):
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ class CPUListPack(base.Function):
|
|||
"""
|
||||
def __init__(self):
|
||||
# arbitrary number of arguments
|
||||
super(CPUListPack, self).__init__("cpulist_pack", 0)
|
||||
super(CPUListPack, self).__init__(0)
|
||||
|
||||
def execute(self, args):
|
||||
if not super(CPUListPack, self).execute(args):
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ class CPUListPresent(base.Function):
|
|||
"""
|
||||
def __init__(self):
|
||||
# arbitrary number of arguments
|
||||
super(CPUListPresent, self).__init__("cpulist_present", 0)
|
||||
super(CPUListPresent, self).__init__(0)
|
||||
|
||||
def execute(self, args):
|
||||
if not super(CPUListPresent, self).execute(args):
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ class CPUListUnpack(base.Function):
|
|||
"""
|
||||
def __init__(self):
|
||||
# arbitrary number of arguments
|
||||
super(CPUListUnpack, self).__init__("cpulist_unpack", 0)
|
||||
super(CPUListUnpack, self).__init__(0)
|
||||
|
||||
def execute(self, args):
|
||||
if not super(CPUListUnpack, self).execute(args):
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ class Exec(base.Function):
|
|||
"""
|
||||
def __init__(self):
|
||||
# unlimited number of arguments, min 1 argument (the name of executable)
|
||||
super(Exec, self).__init__("exec", 0, 1)
|
||||
super(Exec, self).__init__(0, 1)
|
||||
|
||||
def execute(self, args):
|
||||
if not super(Exec, self).execute(args):
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ class Hex2CPUList(base.Function):
|
|||
"""
|
||||
def __init__(self):
|
||||
# 1 argument
|
||||
super(Hex2CPUList, self).__init__("hex2cpulist", 1, 1)
|
||||
super(Hex2CPUList, self).__init__(1, 1)
|
||||
|
||||
def execute(self, args):
|
||||
if not super(Hex2CPUList, self).execute(args):
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ class IntelRecommendedPState(base.Function):
|
|||
generation, Intel has fixed these issues.
|
||||
"""
|
||||
def __init__(self):
|
||||
super(IntelRecommendedPState, self).__init__("intel_recommended_pstate", 0)
|
||||
super(IntelRecommendedPState, self).__init__(0)
|
||||
|
||||
def execute(self, args):
|
||||
if not super(IntelRecommendedPState, self).execute(args):
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ class KB2S(base.Function):
|
|||
"""
|
||||
def __init__(self):
|
||||
# 1 argument
|
||||
super(KB2S, self).__init__("kb2s", 1, 1)
|
||||
super(KB2S, self).__init__(1, 1)
|
||||
|
||||
def execute(self, args):
|
||||
if not super(KB2S, self).execute(args):
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ class Log(base.Function):
|
|||
"""
|
||||
def __init__(self):
|
||||
# unlimited number of arguments, min 1 argument (the value to log)
|
||||
super(Log, self).__init__("log", 0, 1)
|
||||
super(Log, self).__init__(0, 1)
|
||||
|
||||
def execute(self, args):
|
||||
if not super(Log, self).execute(args):
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ class LSCPUCheck(base.Function):
|
|||
"""
|
||||
def __init__(self):
|
||||
# unlimited number of arguments, min 2 arguments
|
||||
super(LSCPUCheck, self).__init__("lscpu_check", 0, 2)
|
||||
super(LSCPUCheck, self).__init__(0, 2)
|
||||
|
||||
def execute(self, args):
|
||||
if not super(LSCPUCheck, self).execute(args):
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ class Package2CPUs(base.Function):
|
|||
"""
|
||||
|
||||
def __init__(self):
|
||||
super(Package2CPUs, self).__init__("package2cpus", 0)
|
||||
super(Package2CPUs, self).__init__(0)
|
||||
|
||||
def execute(self, args):
|
||||
if not super(Package2CPUs, self).execute(args):
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ class Package2Uncores(base.Function):
|
|||
"""
|
||||
|
||||
def __init__(self):
|
||||
super(Package2Uncores, self).__init__("package2uncores", 0)
|
||||
super(Package2Uncores, self).__init__(0)
|
||||
|
||||
def execute(self, args):
|
||||
if not super(Package2Uncores, self).execute(args):
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ class RegexSearchTernary(base.Function):
|
|||
"""
|
||||
def __init__(self):
|
||||
# 4 arguments
|
||||
super(RegexSearchTernary, self).__init__("regex_search_ternary", 4, 4)
|
||||
super(RegexSearchTernary, self).__init__(4, 4)
|
||||
|
||||
def execute(self, args):
|
||||
if not super(RegexSearchTernary, self).execute(args):
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ class S2KB(base.Function):
|
|||
"""
|
||||
def __init__(self):
|
||||
# 1 argument
|
||||
super(S2KB, self).__init__("s2kb", 1, 1)
|
||||
super(S2KB, self).__init__(1, 1)
|
||||
|
||||
def execute(self, args):
|
||||
if not super(S2KB, self).execute(args):
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ class Strip(base.Function):
|
|||
"""
|
||||
def __init__(self):
|
||||
# unlimited number of arguments, min 1 argument
|
||||
super(Strip, self).__init__("strip", 0, 1)
|
||||
super(Strip, self).__init__(0, 1)
|
||||
|
||||
def execute(self, args):
|
||||
if not super(Strip, self).execute(args):
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ class VirtCheck(base.Function):
|
|||
"""
|
||||
def __init__(self):
|
||||
# 2 arguments
|
||||
super(VirtCheck, self).__init__("virt_check", 2, 2)
|
||||
super(VirtCheck, self).__init__(2, 2)
|
||||
|
||||
def execute(self, args):
|
||||
if not super(VirtCheck, self).execute(args):
|
||||
|
|
|
|||
Loading…
Reference in a new issue