1
0
Fork 0

functions: Use CapWords for function classes

This is the standard in Python and it prevents
the issue of using reserved/existing names, e.g.,
in the case of the `exec` or `log` function.
This commit is contained in:
Pavol Žáčik 2025-04-01 13:38:26 +02:00
parent cb0261e3e6
commit 87f0f99bb5
No known key found for this signature in database
GPG key ID: B3029C97EB97E3E4
25 changed files with 75 additions and 75 deletions

View file

@ -6,7 +6,7 @@ from tuned.profiles.exceptions import InvalidProfileException
log = tuned.logs.get()
class assertion(base.Function):
class Assertion(base.Function):
"""
Compares the second argument and the third argument.
If they _do not match_, the function logs the text from
@ -22,10 +22,10 @@ class assertion(base.Function):
"""
def __init__(self):
# 3 arguments
super(assertion, self).__init__("assertion", 3, 3)
super(Assertion, self).__init__("assertion", 3, 3)
def execute(self, args):
if not super(assertion, self).execute(args):
if not super(Assertion, self).execute(args):
return None
if args[1] != args[2]:
log.error("assertion '%s' failed: '%s' != '%s'" % (args[0], args[1], args[2]))

View file

@ -6,7 +6,7 @@ from tuned.profiles.exceptions import InvalidProfileException
log = tuned.logs.get()
class assertion_non_equal(base.Function):
class AssertionNonEqual(base.Function):
"""
Compares the second argument and the third argument.
If they _match_, the function logs the text from
@ -21,10 +21,10 @@ class assertion_non_equal(base.Function):
"""
def __init__(self):
# 3 arguments
super(assertion_non_equal, self).__init__("assertion_non_equal", 3, 3)
super(AssertionNonEqual, self).__init__("assertion_non_equal", 3, 3)
def execute(self, args):
if not super(assertion_non_equal, self).execute(args):
if not super(AssertionNonEqual, self).execute(args):
return None
if args[1] == args[2]:
log.error("assertion '%s' failed: '%s' == '%s'" % (args[0], args[1], args[2]))

View file

@ -8,7 +8,7 @@ from tuned.utils.commands import commands
log = tuned.logs.get()
cmd = commands()
class calc_isolated_cores(base.Function):
class CalcIsolatedCores(base.Function):
"""
Calculates and returns a list of isolated cores. The argument
specifies how many cores per socket should be reserved for housekeeping.
@ -23,10 +23,10 @@ class calc_isolated_cores(base.Function):
"""
def __init__(self):
# max 1 argument
super(calc_isolated_cores, self).__init__("calc_isolated_cores", 1)
super(CalcIsolatedCores, self).__init__("calc_isolated_cores", 1)
def execute(self, args):
if not super(calc_isolated_cores, self).execute(args):
if not super(CalcIsolatedCores, self).execute(args):
return None
cpus_reserve = 1
if len(args) > 0:

View file

@ -3,17 +3,17 @@ from . import base
log = tuned.logs.get()
class check_net_queue_count(base.Function):
class CheckNetQueueCount(base.Function):
"""
Checks whether the first argument is a valid queue count for net devices.
If yes, returns it, otherwise returns the number of housekeeping CPUs.
"""
def __init__(self):
# 1 argument
super(check_net_queue_count, self).__init__("check_net_queue_count", 1, 1)
super(CheckNetQueueCount, self).__init__("check_net_queue_count", 1, 1)
def execute(self, args):
if not super(check_net_queue_count, self).execute(args):
if not super(CheckNetQueueCount, self).execute(args):
return None
if args[0].isdigit():
return args[0]

View file

@ -4,7 +4,7 @@ from . import base
log = tuned.logs.get()
class cpuinfo_check(base.Function):
class CPUInfoCheck(base.Function):
"""
Checks regexes against the content of `/proc/cpuinfo`.
@ -20,10 +20,10 @@ class cpuinfo_check(base.Function):
"""
def __init__(self):
# unlimited number of arguments, min 2 arguments
super(cpuinfo_check, self).__init__("cpuinfo_check", 0, 2)
super(CPUInfoCheck, self).__init__("cpuinfo_check", 0, 2)
def execute(self, args):
if not super(cpuinfo_check, self).execute(args):
if not super(CPUInfoCheck, self).execute(args):
return None
cpuinfo = self._cmd.read_file("/proc/cpuinfo")
for i in range(0, len(args), 2):

View file

@ -3,7 +3,7 @@ from . import base
log = tuned.logs.get()
class cpulist2devs(base.Function):
class CPUList2Devs(base.Function):
"""
Converts a CPU list into a comma-separated list of device names.
@ -16,9 +16,9 @@ class cpulist2devs(base.Function):
"""
def __init__(self):
# arbitrary number of arguments
super(cpulist2devs, self).__init__("cpulist2devs", 0)
super(CPUList2Devs, self).__init__("cpulist2devs", 0)
def execute(self, args):
if not super(cpulist2devs, self).execute(args):
if not super(CPUList2Devs, self).execute(args):
return None
return self._cmd.cpulist2string(self._cmd.cpulist_unpack(",".join(args)), prefix = "cpu")

View file

@ -5,7 +5,7 @@ from tuned.utils.commands import commands
log = tuned.logs.get()
class cpulist2hex(base.Function):
class CPUList2Hex(base.Function):
"""
Converts a CPU list into a hexadecimal CPU mask.
@ -18,9 +18,9 @@ class cpulist2hex(base.Function):
"""
def __init__(self):
# arbitrary number of arguments
super(cpulist2hex, self).__init__("cpulist2hex", 0)
super(CPUList2Hex, self).__init__("cpulist2hex", 0)
def execute(self, args):
if not super(cpulist2hex, self).execute(args):
if not super(CPUList2Hex, self).execute(args):
return None
return self._cmd.cpulist2hex(",,".join(args))

View file

@ -5,7 +5,7 @@ from tuned.utils.commands import commands
log = tuned.logs.get()
class cpulist2hex_invert(base.Function):
class CPUList2HexInvert(base.Function):
"""
Converts a CPU list into a hexadecimal CPU mask and inverts it.
@ -19,10 +19,10 @@ class cpulist2hex_invert(base.Function):
"""
def __init__(self):
# arbitrary number of arguments
super(cpulist2hex_invert, self).__init__("cpulist2hex_invert", 0)
super(CPUList2HexInvert, self).__init__("cpulist2hex_invert", 0)
def execute(self, args):
if not super(cpulist2hex_invert, self).execute(args):
if not super(CPUList2HexInvert, self).execute(args):
return None
# current implementation inverts the CPU list and then converts it to hexmask
return self._cmd.cpulist2hex(",".join(str(v) for v in self._cmd.cpulist_invert(",,".join(args))))

View file

@ -5,7 +5,7 @@ from tuned.utils.commands import commands
log = tuned.logs.get()
class cpulist_invert(base.Function):
class CPUListInvert(base.Function):
"""
Inverts a CPU list, i.e., returns its complement. The complement is
computed from the list of online CPUs in `/sys/devices/system/cpu/online`.
@ -19,9 +19,9 @@ class cpulist_invert(base.Function):
"""
def __init__(self):
# arbitrary number of arguments
super(cpulist_invert, self).__init__("cpulist_invert", 0)
super(CPUListInvert, self).__init__("cpulist_invert", 0)
def execute(self, args):
if not super(cpulist_invert, self).execute(args):
if not super(CPUListInvert, self).execute(args):
return None
return ",".join(str(v) for v in self._cmd.cpulist_invert(",,".join(args)))

View file

@ -5,7 +5,7 @@ from tuned.utils.commands import commands
log = tuned.logs.get()
class cpulist_online(base.Function):
class CPUListOnline(base.Function):
"""
Returns a CPU list containing the online CPUs from the given CPU list.
@ -19,10 +19,10 @@ class cpulist_online(base.Function):
"""
def __init__(self):
# arbitrary number of arguments
super(cpulist_online, self).__init__("cpulist_online", 0)
super(CPUListOnline, self).__init__("cpulist_online", 0)
def execute(self, args):
if not super(cpulist_online, self).execute(args):
if not super(CPUListOnline, self).execute(args):
return None
cpus = self._cmd.cpulist_unpack(",".join(args))
online = self._cmd.cpulist_unpack(self._cmd.read_file("/sys/devices/system/cpu/online"))

View file

@ -5,7 +5,7 @@ from tuned.utils.commands import commands
log = tuned.logs.get()
class cpulist_pack(base.Function):
class CPUListPack(base.Function):
"""
Packs a CPU list into the most succint form.
@ -18,9 +18,9 @@ class cpulist_pack(base.Function):
"""
def __init__(self):
# arbitrary number of arguments
super(cpulist_pack, self).__init__("cpulist_pack", 0)
super(CPUListPack, self).__init__("cpulist_pack", 0)
def execute(self, args):
if not super(cpulist_pack, self).execute(args):
if not super(CPUListPack, self).execute(args):
return None
return ",".join(str(v) for v in self._cmd.cpulist_pack(",,".join(args)))

View file

@ -5,17 +5,17 @@ from tuned.utils.commands import commands
log = tuned.logs.get()
class cpulist_present(base.Function):
class CPUListPresent(base.Function):
"""
Checks whether the CPUs from a given CPU list are present on the system.
Returns a CPU list containing only the present CPUs from the given list.
"""
def __init__(self):
# arbitrary number of arguments
super(cpulist_present, self).__init__("cpulist_present", 0)
super(CPUListPresent, self).__init__("cpulist_present", 0)
def execute(self, args):
if not super(cpulist_present, self).execute(args):
if not super(CPUListPresent, self).execute(args):
return None
cpus = self._cmd.cpulist_unpack(",,".join(args))
present = self._cmd.cpulist_unpack(self._cmd.read_file("/sys/devices/system/cpu/present"))

View file

@ -5,7 +5,7 @@ from tuned.utils.commands import commands
log = tuned.logs.get()
class cpulist_unpack(base.Function):
class CPUListUnpack(base.Function):
"""
Unpacks a CPU list into a form with no ranges.
@ -18,9 +18,9 @@ class cpulist_unpack(base.Function):
"""
def __init__(self):
# arbitrary number of arguments
super(cpulist_unpack, self).__init__("cpulist_unpack", 0)
super(CPUListUnpack, self).__init__("cpulist_unpack", 0)
def execute(self, args):
if not super(cpulist_unpack, self).execute(args):
if not super(CPUListUnpack, self).execute(args):
return None
return ",".join(str(v) for v in self._cmd.cpulist_unpack(",,".join(args)))

View file

@ -3,7 +3,7 @@ import tuned.logs
from . import base
from tuned.utils.commands import commands
class execute(base.Function):
class Exec(base.Function):
"""
Executes a process and returns its output.
@ -16,10 +16,10 @@ class execute(base.Function):
"""
def __init__(self):
# unlimited number of arguments, min 1 argument (the name of executable)
super(execute, self).__init__("exec", 0, 1)
super(Exec, self).__init__("exec", 0, 1)
def execute(self, args):
if not super(execute, self).execute(args):
if not super(Exec, self).execute(args):
return None
(ret, out) = self._cmd.execute(args)
if ret == 0:

View file

@ -5,7 +5,7 @@ from tuned.utils.commands import commands
log = tuned.logs.get()
class hex2cpulist(base.Function):
class Hex2CPUList(base.Function):
"""
Converts a hexadecimal CPU mask into a CPU list.
@ -18,9 +18,9 @@ class hex2cpulist(base.Function):
"""
def __init__(self):
# 1 argument
super(hex2cpulist, self).__init__("hex2cpulist", 1, 1)
super(Hex2CPUList, self).__init__("hex2cpulist", 1, 1)
def execute(self, args):
if not super(hex2cpulist, self).execute(args):
if not super(Hex2CPUList, self).execute(args):
return None
return ",".join(str(v) for v in self._cmd.hex2cpulist(args[0]))

View file

@ -10,7 +10,7 @@ PMU_PATH = "/sys/devices/cpu/caps/pmu_name"
ACTIVE = "active"
DISABLE = "disable"
class intel_recommended_pstate(base.Function):
class IntelRecommendedPState(base.Function):
"""
Returns the recommended intel_pstate CPUFreq driver mode
based on the CPU generation.
@ -23,10 +23,10 @@ class intel_recommended_pstate(base.Function):
generation, Intel has fixed these issues.
"""
def __init__(self):
super(intel_recommended_pstate, self).__init__("intel_recommended_pstate", 0)
super(IntelRecommendedPState, self).__init__("intel_recommended_pstate", 0)
def execute(self, args):
if not super(intel_recommended_pstate, self).execute(args):
if not super(IntelRecommendedPState, self).execute(args):
return None
current_processor_name = self._cmd.read_file(PMU_PATH).strip()

View file

@ -3,16 +3,16 @@ import tuned.logs
from . import base
from tuned.utils.commands import commands
class kb2s(base.Function):
class KB2S(base.Function):
"""
Converts kilobytes to disk sectors.
"""
def __init__(self):
# 1 argument
super(kb2s, self).__init__("kb2s", 1, 1)
super(KB2S, self).__init__("kb2s", 1, 1)
def execute(self, args):
if not super(kb2s, self).execute(args):
if not super(KB2S, self).execute(args):
return None
try:
return str(int(args[0]) * 2)

View file

@ -3,7 +3,7 @@ from . import base
log = tuned.logs.get()
class execute(base.Function):
class Log(base.Function):
"""
Returns the concatenation of its arguments and also logs the return value,
which is useful for debugging.
@ -20,10 +20,10 @@ class execute(base.Function):
"""
def __init__(self):
# unlimited number of arguments, min 1 argument (the value to log)
super(execute, self).__init__("log", 0, 1)
super(Log, self).__init__("log", 0, 1)
def execute(self, args):
if not super(execute, self).execute(args):
if not super(Log, self).execute(args):
return None
s = "".join(args)
log.info(s)

View file

@ -4,7 +4,7 @@ from . import base
log = tuned.logs.get()
class lscpu_check(base.Function):
class LSCPUCheck(base.Function):
"""
Checks regexes against the output of `lscpu`.
@ -20,10 +20,10 @@ class lscpu_check(base.Function):
"""
def __init__(self):
# unlimited number of arguments, min 2 arguments
super(lscpu_check, self).__init__("lscpu_check", 0, 2)
super(LSCPUCheck, self).__init__("lscpu_check", 0, 2)
def execute(self, args):
if not super(lscpu_check, self).execute(args):
if not super(LSCPUCheck, self).execute(args):
return None
# Stdout is the 2nd result from the execute call
_, lscpu = self._cmd.execute("lscpu")

View file

@ -10,7 +10,7 @@ cmd = commands()
SYSFS_DIR = "/sys/devices/system/cpu/"
class package2cpus(base.Function):
class Package2CPUs(base.Function):
"""
Returns a comma-separated list of CPU devices for a package (socket).
Multiple socket numbers can be specified in separate arguments.
@ -25,10 +25,10 @@ class package2cpus(base.Function):
"""
def __init__(self):
super(package2cpus, self).__init__("package2cpus", 0)
super(Package2CPUs, self).__init__("package2cpus", 0)
def execute(self, args):
if not super(package2cpus, self).execute(args):
if not super(Package2CPUs, self).execute(args):
return None
if len(args) <= 0:

View file

@ -10,7 +10,7 @@ cmd = commands()
SYSFS_DIR = "/sys/devices/system/cpu/intel_uncore_frequency/"
class package2uncores(base.Function):
class Package2Uncores(base.Function):
"""
Returns a comma-separated list of uncore devices for a package (socket).
Multiple socket numbers can be specified in separate arguments.
@ -25,10 +25,10 @@ class package2uncores(base.Function):
"""
def __init__(self):
super(package2uncores, self).__init__("package2uncores", 0)
super(Package2Uncores, self).__init__("package2uncores", 0)
def execute(self, args):
if not super(package2uncores, self).execute(args):
if not super(Package2Uncores, self).execute(args):
return None
if len(args) <= 0:

View file

@ -1,7 +1,7 @@
import re
from . import base
class regex_search_ternary(base.Function):
class RegexSearchTernary(base.Function):
"""
Ternary regex operator.
@ -12,10 +12,10 @@ class regex_search_ternary(base.Function):
"""
def __init__(self):
# 4 arguments
super(regex_search_ternary, self).__init__("regex_search_ternary", 4, 4)
super(RegexSearchTernary, self).__init__("regex_search_ternary", 4, 4)
def execute(self, args):
if not super(regex_search_ternary, self).execute(args):
if not super(RegexSearchTernary, self).execute(args):
return None
if re.search(args[1], args[0]):
return args[2]

View file

@ -3,16 +3,16 @@ import tuned.logs
from . import base
from tuned.utils.commands import commands
class s2kb(base.Function):
class S2KB(base.Function):
"""
Converts disk sectors to kilobytes.
"""
def __init__(self):
# 1 argument
super(s2kb, self).__init__("s2kb", 1, 1)
super(S2KB, self).__init__("s2kb", 1, 1)
def execute(self, args):
if not super(s2kb, self).execute(args):
if not super(S2KB, self).execute(args):
return None
try:
return str(int(round(int(args[0]) / 2)))

View file

@ -3,7 +3,7 @@ import tuned.logs
from . import base
from tuned.utils.commands import commands
class strip(base.Function):
class Strip(base.Function):
"""
Creates a string by concatenating all arguments,
stripping any leading or trailing whitespace from
@ -18,9 +18,9 @@ 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__("strip", 0, 1)
def execute(self, args):
if not super(strip, self).execute(args):
if not super(Strip, self).execute(args):
return None
return "".join(args).strip()

View file

@ -3,7 +3,7 @@ import tuned.logs
from . import base
from tuned.utils.commands import commands
class virt_check(base.Function):
class VirtCheck(base.Function):
"""
Checks whether *TuneD* is running inside a virtual machine (VM) or on bare metal.
@ -19,10 +19,10 @@ class virt_check(base.Function):
"""
def __init__(self):
# 2 arguments
super(virt_check, self).__init__("virt_check", 2, 2)
super(VirtCheck, self).__init__("virt_check", 2, 2)
def execute(self, args):
if not super(virt_check, self).execute(args):
if not super(VirtCheck, self).execute(args):
return None
(ret, out) = self._cmd.execute(["virt-what"])
if ret == 0 and len(out) > 0: