Skip to content

Commit ee3684b

Browse files
committed
style: changed style formatting and removed mutable default agruments
1 parent 60bcc57 commit ee3684b

File tree

5 files changed

+35
-36
lines changed

5 files changed

+35
-36
lines changed

mamonsu/tools/report/format.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,9 @@ def key_val_h2(key, val, delim=': '):
9898
TermColor.BOLD, TermColor.BLUE, key, TermColor.END, delim, val)
9999

100100

101-
def topline_h1(arr=[], delim=" \t"):
101+
def topline_h1(arr=None, delim=" \t"):
102+
if arr is None:
103+
arr = []
102104
result = "{0}{1}".format(TermColor.BOLD, TermColor.BLUE)
103105
for x in arr:
104106
result = "{0}{1}{2}".format(result, delim, x)

mamonsu/tools/report/pgsql.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,7 @@ def _collect_query(self, query_desc):
283283
return result
284284

285285
def _collect_rate(self):
286-
result = {}
287-
result['_TPS'], result['_ROLLBACKS'] = '', ''
286+
result = {'_TPS': '', '_ROLLBACKS': ''}
288287
try:
289288
result['row_1'] = Pooler.query(self.QueryRate)[0]
290289
time.sleep(2)

mamonsu/tools/report/start.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from mamonsu.plugins.pgsql.driver.checks import is_conn_to_db
1313

1414
from mamonsu.tools.report.pgsql import PostgresInfo
15+
1516
if platform.LINUX:
1617
from mamonsu.tools.report.os_linux import SystemInfo
1718
else:
@@ -142,10 +143,10 @@ def _auto_host_is_working(self):
142143
def test_db(self, host_pre):
143144
logging.debug('Test host: {0}'.format(host_pre))
144145
if is_conn_to_db(
145-
host=host_pre,
146-
db=self.args.dbname,
147-
port=self.args.port,
148-
user=self.args.username,
146+
host=host_pre,
147+
db=self.args.dbname,
148+
port=self.args.port,
149+
user=self.args.username,
149150
paswd=self.args.password):
150151
self.args.hostname = host_pre
151152
os.environ['PGHOST'] = self.args.hostname
@@ -176,7 +177,6 @@ def __getattr__(self, name):
176177

177178

178179
def run_report():
179-
180180
args = Args()
181181

182182
if args.run_system:

mamonsu/tools/sysinfo/linux.py

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,9 @@ def sysctl_fetch(self, key):
213213
def _pci_storage_devices(self):
214214
result = []
215215
for line in self.lspci_raw.split("\n"):
216-
if re.search(r'(Fibre Channel|RAID bus controller|Mass storage controller|SCSI storage controller|SATA controller|Serial Attached SCSI controller)', line, re.M):
216+
if re.search(
217+
r'(Fibre Channel|RAID bus controller|Mass storage controller|SCSI storage controller|SATA controller|Serial Attached SCSI controller)',
218+
line, re.M):
217219
line = line[8:]
218220
result.append(line)
219221
return result
@@ -240,12 +242,9 @@ def _dmidecode(self, key):
240242
return self._shell_out('dmidecode -s \'{0}\''.format(key), sudo=True)
241243

242244
def _dmi_info(self):
243-
result = {}
244-
result['vendor'] = self._dmidecode('system-manufacturer')
245-
result['product'] = self._dmidecode('system-product-name')
246-
result['version'] = self._dmidecode('system-version')
247-
result['chassis'] = self._dmidecode('chassis-type')
248-
result['SERIAL'] = self._dmidecode('system-serial-number')
245+
result = {'vendor': self._dmidecode('system-manufacturer'), 'product': self._dmidecode('system-product-name'),
246+
'version': self._dmidecode('system-version'), 'chassis': self._dmidecode('chassis-type'),
247+
'SERIAL': self._dmidecode('system-serial-number')}
249248
result['TOTAL'] = '{0}; {1}; {2} ({3})'.format(
250249
result['vendor'], result['product'],
251250
result['chassis'], result['version'])
@@ -305,22 +304,22 @@ def fetch_first(reg, info):
305304
result['_FLAGS_IMPORTANT'] = ', '.join(flags)
306305
result['speed'] = fetch_first(
307306
r'^cpu MHz\s+\:\s+(\d+\.\d+)$', info) + ' MHz'
308-
result['_TOTAL'] = 'physical = {0}, cores = {1}, '\
309-
'virtual = {2}, hyperthreading = {3}'.format(
310-
result['physical'], result['cores'],
311-
result['virtual'], result['hyperthreading']
307+
result['_TOTAL'] = 'physical = {0}, cores = {1}, ' \
308+
'virtual = {2}, hyperthreading = {3}'.format(
309+
result['physical'], result['cores'],
310+
result['virtual'], result['hyperthreading']
312311
)
313312
return result
314313

315314
def _meminfo(self):
316315

317316
data, result = self._read_file('/proc/meminfo'), {}
318317
for key in [
319-
'_RAW', '_TOTAL', '_COMMITED', '_COMMITEDLIMIT',
320-
'_FREE', '_SWAPUSED', '_SLAB'
321-
'_SWAPTOTAL', '_CACHED', '_DIRTY', '_BUFFERS',
322-
'_HUGEPAGES_SIZE', '_HUGEPAGES_FREE',
323-
'_SHMEM', '_PAGETABLES']:
318+
'_RAW', '_TOTAL', '_COMMITED', '_COMMITEDLIMIT',
319+
'_FREE', '_SWAPUSED', '_SLAB'
320+
'_SWAPTOTAL', '_CACHED', '_DIRTY', '_BUFFERS',
321+
'_HUGEPAGES_SIZE', '_HUGEPAGES_FREE',
322+
'_SHMEM', '_PAGETABLES']:
324323
result[key] = NA
325324

326325
if self.is_empty(data):
@@ -472,35 +471,35 @@ def _raid(self):
472471
controllers = []
473472
if not self.is_empty(self.lspci_raw):
474473
if re.search(
475-
r'RAID bus controller: LSI Logic / Symbios Logic MegaRAID SAS',
474+
r'RAID bus controller: LSI Logic / Symbios Logic MegaRAID SAS',
476475
self.lspci_raw, re.I):
477476
controllers.append(RAID_LSI)
478477
if re.search(
479-
r'RAID bus controller: LSI Logic / Symbios Logic LSI MegaSAS',
478+
r'RAID bus controller: LSI Logic / Symbios Logic LSI MegaSAS',
480479
self.lspci_raw, re.I):
481480
controllers.append(RAID_LSI)
482481
if re.search(
483-
r'Fusion-MPT SAS',
482+
r'Fusion-MPT SAS',
484483
self.lspci_raw, re.I):
485484
controllers.append(RAID_FUSION_SAS)
486485
if re.search(
487-
r'RAID bus controller: LSI Logic / Symbios Logic Unknown',
486+
r'RAID bus controller: LSI Logic / Symbios Logic Unknown',
488487
self.lspci_raw, re.I):
489488
controllers.append(RAID_LSI)
490489
if re.search(
491-
r'RAID bus controller: Adaptec AAC-RAID',
490+
r'RAID bus controller: Adaptec AAC-RAID',
492491
self.lspci_raw, re.I):
493492
controllers.append(RAID_ADAPTEC)
494493
if re.search(
495-
r'3ware [0-9]* Storage Controller',
494+
r'3ware [0-9]* Storage Controller',
496495
self.lspci_raw, re.I):
497496
controllers.append(RAID_3WARE)
498497
if re.search(
499-
r'Hewlett-Packard Company Smart Array',
498+
r'Hewlett-Packard Company Smart Array',
500499
self.lspci_raw, re.I):
501500
controllers.append(RAID_HP_SMART)
502501
if re.search(
503-
r'Hewlett-Packard Company Smart Array',
502+
r'Hewlett-Packard Company Smart Array',
504503
self.lspci_raw, re.I):
505504
controllers.append(RAID_HP_SMART)
506505
if not self.is_empty(self.dmesg_raw):
@@ -511,7 +510,7 @@ def _raid(self):
511510
if re.search(r'scsi[0-9].*: .*aacraid', self.dmesg_raw, re.I):
512511
controllers.append(RAID_ADAPTEC)
513512
if re.search(
514-
r'scsi[0-9].*: .*3ware [0-9]* Storage Controller',
513+
r'scsi[0-9].*: .*3ware [0-9]* Storage Controller',
515514
self.dmesg_raw, re.I):
516515
controllers.append(RAID_3WARE)
517516
if len(controllers) == 0:

mamonsu/tools/sysinfo/linux_shell.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,10 @@ def is_sudo_working():
3434

3535

3636
class Shell(object):
37-
3837
# exit status of timeout code
3938
TimeoutCode = -1
4039
# local var
41-
_sudo_result = None # type: bool
40+
_sudo_result = None # type: bool
4241

4342
def __init__(self, cmd, timeout=10, sudo=False):
4443
self.status = self.TimeoutCode
@@ -63,7 +62,7 @@ def __init__(self, cmd, timeout=10, sudo=False):
6362
line = p.stderr.read()
6463
if not line == '':
6564
self.stderr += line.decode('utf-8', 'replace')
66-
if self.wait_time > 0 and self.exec_time >= self.wait_time:
65+
if 0 < self.wait_time <= self.exec_time:
6766
return
6867
self.status = p.returncode
6968
for line in p.stdout.readlines():

0 commit comments

Comments
 (0)