Skip to content

Commit

Permalink
ci: fix pylint warnings relating to use-before-init in py tools
Browse files Browse the repository at this point in the history
  • Loading branch information
natoscott committed Nov 20, 2023
1 parent 2035607 commit e309a6b
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 52 deletions.
11 changes: 6 additions & 5 deletions src/pcp/buddyinfo/pcp-buddyinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,11 @@ def names(self):
return data.keys()

class BuddyinfoReport(pmcc.MetricGroupPrinter):
def __init__(self,samples,group,context):
self.samples = samples
def __init__(self,opts,group):
self.opts=opts
self.group=group
self.context=context
self.context=opts.context
self.samples=opts.samples

def __get_ncpu(self, group):
return group['hinv.ncpu'].netValues[0][2]
Expand Down Expand Up @@ -151,7 +152,7 @@ def __print_buddy_status():

def report(self, manager):
group = manager["sysinfo"]
self.samples=opts.pmGetOptionSamples()
self.samples=self.opts.pmGetOptionSamples()
t_s = group.contextCache.pmLocaltime(int(group.timestamp))
timestamp = time.strftime(BuddyinfoOptions.timefmt, t_s.struct_time())
header_indentation = " " if len(timestamp) < 9 else (len(timestamp) - 7) * " "
Expand Down Expand Up @@ -183,7 +184,7 @@ def __init__(self):
mngr["buddyinfo"] = BUDDYSTAT_METRICS
mngr["sysinfo"] = SYS_MECTRICS
mngr["allinfo"]=ALL_METRICS
mngr.printer = BuddyinfoReport(opts.samples,mngr,opts.context)
mngr.printer = BuddyinfoReport(opts,mngr)
sts = mngr.run()
sys.exit(sts)
except pmapi.pmErr as error:
Expand Down
15 changes: 6 additions & 9 deletions src/pcp/meminfo/pcp-meminfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,9 @@
ALL_METRICS = METRICS + SYS_METRICS

class MeminfoReport(pmcc.MetricGroupPrinter):
samples = 0
Machine_info_count = 0
def __init__(self, opts):
self.opts = opts
self.Machine_info_count = 0

def __get_ncpu(self, group):
return group['hinv.ncpu'].netValues[0][2]
Expand All @@ -149,9 +150,6 @@ def __print_machine_info(self, group, context):

print("%s (%s CPU)" % (header_string, self.__get_ncpu(group)))

def __init__(self, samples):
self.samples = samples

def getMetricName(self, idx):
metric_name = ""
units = ""
Expand All @@ -174,7 +172,7 @@ def report(self, manager):

group = manager["meminfo"]

opts.pmGetOptionSamples()
self.opts.pmGetOptionSamples()

t_s = group.contextCache.pmLocaltime(int(group.timestamp))
time_string = time.strftime(MeminfoOptions.timefmt, t_s.struct_time())
Expand All @@ -197,13 +195,12 @@ def report(self, manager):
idx += 1
print("")

if MeminfoOptions.context is not PM_CONTEXT_ARCHIVE and opts.pmGetOptionSamples() is None:
if MeminfoOptions.context is not PM_CONTEXT_ARCHIVE and self.opts.pmGetOptionSamples() is None:
sys.exit(0)

class MeminfoOptions(pmapi.pmOptions):
context = None
timefmt = "%H:%M:%S"
samples = 0

def __init__(self):
pmapi.pmOptions.__init__(self, "a:s:S:T:z:A:t:")
Expand All @@ -224,7 +221,7 @@ def __init__(self):

mngr["meminfo"] = METRICS
mngr["sysinfo"] = SYS_METRICS
mngr.printer = MeminfoReport(opts.samples)
mngr.printer = MeminfoReport(opts)
sts = mngr.run()
sys.exit(sts)

Expand Down
13 changes: 7 additions & 6 deletions src/pcp/netstat/pcp-netstat.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,10 @@

MISSING_METRICS = []

class NestatReport(pmcc.MetricGroupPrinter):
Machine_info_count = 0
class NetstatReport(pmcc.MetricGroupPrinter):
def __init__(self, opts):
self.opts = opts
self.Machine_info_count = 0

def __get_ncpu(self, group):
return group['hinv.ncpu'].netValues[0][2]
Expand Down Expand Up @@ -375,7 +377,7 @@ def report(self, manager):
return

group = manager["netstat"]
opts.pmGetOptionSamples()
self.opts.pmGetOptionSamples()

t_s = group.contextCache.pmLocaltime(int(group.timestamp))
time_string = time.strftime(NetstatOptions.timefmt, t_s.struct_time())
Expand Down Expand Up @@ -431,13 +433,12 @@ def report(self, manager):

print(ifstats_str)

if NetstatOptions.context is not PM_CONTEXT_ARCHIVE and opts.pmGetOptionSamples() is None:
if NetstatOptions.context is not PM_CONTEXT_ARCHIVE and self.opts.pmGetOptionSamples() is None:
sys.exit(0)

class NetstatOptions(pmapi.pmOptions):
context = None
timefmt = "%H:%M:%S"
samples = 0
all_stats_flag = False
filter_protocol_flag = False
filter_protocol = None
Expand Down Expand Up @@ -492,7 +493,7 @@ def __init__(self):

mngr["netstat"] = METRICS + IFACE_METRICS
mngr["sysinfo"] = SYS_METRICS
mngr.printer = NestatReport()
mngr.printer = NetstatReport(opts)
sts = mngr.run()
sys.exit(sts)

Expand Down
31 changes: 17 additions & 14 deletions src/pcp/ps/pcp-ps.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,9 @@ def __matches_process_name(self, process):


class ProcessStatusUtil:
def __init__(self, instance, delta_time, metrics_repository):
def __init__(self, instance, manager, delta_time, metrics_repository):
self.instance = instance
self.manager = manager
self.__delta_time = delta_time
self.__metric_repository = metrics_repository

Expand Down Expand Up @@ -294,7 +295,7 @@ def stime(self):

def start(self):
s_time = self.__metric_repository.current_value('proc.psinfo.start_time', self.instance)
group = manager['psstat']
group = self.manager['psstat']
kernel_boottime = group['kernel.all.boottime'].netValues[0][2]
ts = group.contextCache.pmLocaltime(int(kernel_boottime + (s_time / 1000)))
if group.timestamp.tv_sec - (kernel_boottime + s_time / 1000) >= 24*60*60:
Expand Down Expand Up @@ -362,11 +363,13 @@ def policy(self):


class ProcessStatus:
def __init__(self, metric_repository):
def __init__(self, manager, metric_repository):
self.__manager = manager
self.__metric_repository = metric_repository

def get_processes(self, delta_time):
return map((lambda pid: (ProcessStatusUtil(pid, delta_time, self.__metric_repository))), self.__pids())
return map(lambda pid:
(ProcessStatusUtil(pid, self.__manager, delta_time, self.__metric_repository)), self.__pids())

def __pids(self):
pid_dict = self.__metric_repository.current_values('proc.psinfo.pid')
Expand Down Expand Up @@ -527,7 +530,7 @@ def print_report(self, timestamp, header_indentation, value_indentation):
process.total_time(), command))


class ProcessstatReport(pmcc.MetricGroupPrinter):
class ProcessStatReport(pmcc.MetricGroupPrinter):
Machine_info_count = 0

def timeStampDelta(self, group):
Expand Down Expand Up @@ -585,7 +588,7 @@ def report(self, manager):

# ================================================================
if ProcessStatOptions.show_all_process:
process_report = ProcessStatus(metric_repository)
process_report = ProcessStatus(manager, metric_repository)
process_filter = ProcessFilter(ProcessStatOptions)
stdout = StdoutPrinter()
printdecorator = NoneHandlingPrinterDecorator(stdout)
Expand All @@ -594,7 +597,7 @@ def report(self, manager):
report.print_report(timestamp, header_indentation, value_indentation)

if ProcessStatOptions.empty_arg_flag:
process_report = ProcessStatus(metric_repository)
process_report = ProcessStatus(manager, metric_repository)
process_filter = ProcessFilter(ProcessStatOptions)
stdout = StdoutPrinter()
printdecorator = NoneHandlingPrinterDecorator(stdout)
Expand All @@ -603,15 +606,15 @@ def report(self, manager):
report.print_report(timestamp, header_indentation, value_indentation)

if ProcessStatOptions.pid_filter_flag:
process_report = ProcessStatus(metric_repository)
process_report = ProcessStatus(manager, metric_repository)
process_filter = ProcessFilter(ProcessStatOptions)
stdout = StdoutPrinter()
printdecorator = NoneHandlingPrinterDecorator(stdout)
report = ProcessStatusReporter(process_report, process_filter, interval_in_seconds,
printdecorator.Print, ProcessStatOptions)
report.print_report(timestamp, header_indentation, value_indentation)
if ProcessStatOptions.ppid_filter_flag:
process_report = ProcessStatus(metric_repository)
process_report = ProcessStatus(manager, metric_repository)
process_filter = ProcessFilter(ProcessStatOptions)
stdout = StdoutPrinter()
printdecorator = NoneHandlingPrinterDecorator(stdout)
Expand All @@ -620,7 +623,7 @@ def report(self, manager):
report.print_report(timestamp, header_indentation, value_indentation)

if ProcessStatOptions.command_filter_flag:
process_report = ProcessStatus(metric_repository)
process_report = ProcessStatus(manager, metric_repository)
process_filter = ProcessFilter(ProcessStatOptions)
stdout = StdoutPrinter()
printdecorator = NoneHandlingPrinterDecorator(stdout)
Expand All @@ -629,7 +632,7 @@ def report(self, manager):
report.print_report(timestamp, header_indentation, value_indentation)

if ProcessStatOptions.user_oriented_format:
process_report = ProcessStatus(metric_repository)
process_report = ProcessStatus(manager, metric_repository)
process_filter = ProcessFilter(ProcessStatOptions)
stdout = StdoutPrinter()
printdecorator = NoneHandlingPrinterDecorator(stdout)
Expand All @@ -638,7 +641,7 @@ def report(self, manager):
report.print_report(timestamp, header_indentation, value_indentation)

if ProcessStatOptions.username_filter_flag:
process_report = ProcessStatus(metric_repository)
process_report = ProcessStatus(manager, metric_repository)
process_filter = ProcessFilter(ProcessStatOptions)
stdout = StdoutPrinter()
printdecorator = NoneHandlingPrinterDecorator(stdout)
Expand All @@ -648,7 +651,7 @@ def report(self, manager):

# ================================================================
if ProcessStatOptions.selective_colum_flag:
process_report = ProcessStatus(metric_repository)
process_report = ProcessStatus(manager, metric_repository)
process_filter = ProcessFilter(ProcessStatOptions)
stdout = StdoutPrinter()
printdecorator = NoneHandlingPrinterDecorator(stdout)
Expand Down Expand Up @@ -812,7 +815,7 @@ def checkOptions():
sys.stderr.write('Error: not all required metrics are available\nMissing %s\n' % missing)
sys.exit(1)
manager['psstat'] = PSSTAT_METRICS
manager.printer = ProcessstatReport()
manager.printer = ProcessStatReport()
sts = manager.run()
sys.exit(sts)
except pmapi.pmErr as pmerror:
Expand Down
13 changes: 7 additions & 6 deletions src/pcp/slabinfo/pcp-slabinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,11 @@ def names(self):
return data.keys()

class SlabinfoReport(pmcc.MetricGroupPrinter):
def __init__(self,samples,group,context):
self.samples = samples
self.group=group
self.context=context
def __init__(self,opts,group):
self.opts = opts
self.group = group
self.samples = opts.samples
self.context = opts.context

def __get_ncpu(self, group):
return group['hinv.ncpu'].netValues[0][2]
Expand Down Expand Up @@ -162,7 +163,7 @@ def __print_slab_status():

def report(self, manager):
group = manager["sysinfo"]
self.samples=opts.pmGetOptionSamples()
self.samples = self.opts.pmGetOptionSamples()
t_s = group.contextCache.pmLocaltime(int(group.timestamp))
timestamp = time.strftime(SlabinfoOptions.timefmt, t_s.struct_time())
header_indentation = " " if len(timestamp) < 9 else (len(timestamp) - 7) * " "
Expand Down Expand Up @@ -194,7 +195,7 @@ def __init__(self):
mngr["slabinfo"] = SLABSTAT_METRICS
mngr["sysinfo"] = SYS_MECTRICS
mngr["allinfo"]=ALL_METRICS
mngr.printer = SlabinfoReport(opts.samples,mngr,opts.context)
mngr.printer = SlabinfoReport(opts,mngr)
sts = mngr.run()
sys.exit(sts)
except pmapi.pmErr as error:
Expand Down
25 changes: 13 additions & 12 deletions src/pcp/zoneinfo/pcp-zoneinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,16 +147,17 @@ def current_value(self, metric):


class ZoneStatUtil:
def __init__(self, metrics_repository):
def __init__(self, metrics_repository, all_metrics_repository):
self.__metric_repository = metrics_repository
self.__all_metrics_repository = all_metrics_repository
self.report = ReportingMetricRepository(self.__metric_repository)

def names(self):
data = self.report.current_value('mem.zoneinfo.present')
return sorted(data.keys())

def metric_value(self, metric, node):
if metric in ALL_METRICS:
if metric in self.__all_metrics_repository:
data = self.report.current_value(metric)
data = data.get(node, "0")
if data != "0":
Expand All @@ -179,10 +180,11 @@ def protection_names(self, node_name):


class ZoneinfoReport(pmcc.MetricGroupPrinter):
def __init__(self, samples, group, context):
self.samples = samples
def __init__(self, opts, group):
self.opts = opts
self.group = group
self.context = context
self.samples = opts.samples
self.context = opts.context

def __get_ncpu(self, group):
return group['hinv.ncpu'].netValues[0][2]
Expand Down Expand Up @@ -269,9 +271,9 @@ def __print_values(self, manager):
except IndexError:
print("Got some error while printing values for zoneinfo")

def print_report(self, group, timestamp, manager_zoneinfo):
def print_report(self, group, timestamp, manager_zoneinfo, manager_all):
def __print_zone_status():
zonestatus = ZoneStatUtil(manager_zoneinfo)
zonestatus = ZoneStatUtil(manager_zoneinfo, manager_all)
if zonestatus.names():
try:
self.__print_machine_info(group)
Expand Down Expand Up @@ -299,10 +301,10 @@ def __print_zone_status():

def report(self, manager):
group = manager["sysinfo"]
self.samples = opts.pmGetOptionSamples()
self.samples = self.opts.pmGetOptionSamples()
t_s = group.contextCache.pmLocaltime(int(group.timestamp))
timestamp = time.strftime(ZoneinfoOptions.timefmt, t_s.struct_time())
self.print_report(group, timestamp, manager['zoneinfo'])
self.print_report(group, timestamp, manager['zoneinfo'], manager['allinfo'])


class ZoneinfoOptions(pmapi.pmOptions):
Expand Down Expand Up @@ -347,7 +349,6 @@ def updateZoneinfoDataToBeFetched():
del ZONEINFO_PER_NODE[key]



if __name__ == '__main__':
try:
opts = ZoneinfoOptions()
Expand All @@ -360,7 +361,7 @@ def updateZoneinfoDataToBeFetched():
elif opts.context == PM_CONTEXT_ARCHIVE:
context = pmapi.pmContext.fromOptions(opts,sys.argv)
try:
metric_ids =context.pmLookupName(ZONESTAT_METRICS)
metric_ids = context.pmLookupName(ZONESTAT_METRICS)
descs= context.pmLookupDescs(metric_ids)
except pmapi.pmErr as error:
newVersionFlag = False
Expand All @@ -371,7 +372,7 @@ def updateZoneinfoDataToBeFetched():
mngr["zoneinfo"] = ZONESTAT_METRICS
mngr["sysinfo"] = SYS_METRICS
mngr["allinfo"] = ALL_METRICS
mngr.printer = ZoneinfoReport(opts.samples, mngr, opts.context)
mngr.printer = ZoneinfoReport(opts, mngr)
sts = mngr.run()
sys.exit(sts)
except pmapi.pmErr as error:
Expand Down

0 comments on commit e309a6b

Please sign in to comment.