Skip to content

Commit

Permalink
Adding pylint support
Browse files Browse the repository at this point in the history
  • Loading branch information
ribalba committed Sep 21, 2023
1 parent 1373880 commit 2946a5a
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 14 deletions.
38 changes: 38 additions & 0 deletions .pylintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
[FORMAT]

# Maximum number of characters on a single line.
max-line-length=120


[MESSAGES CONTROL]

disable=missing-function-docstring,
missing-module-docstring,
missing-class-docstring,
too-few-public-methods,
duplicate-code,
too-many-nested-blocks,
line-too-long,
too-many-boolean-expressions,
too-many-nested-blocks,
line-too-long,
protected-access,
too-many-lines,
multiple-statements,
pointless-string-statement,
too-many-locals,
too-many-public-methods,
too-many-branches,
too-many-statements,
too-many-arguments,
invalid-name,
wrong-import-position,
too-many-return-statements,


# import-error

[MASTER]
ignore=env
ignore-patterns=^env.*
ignore-paths=^env.*$
27 changes: 13 additions & 14 deletions power_logger.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python3

# pylint: disable=W0603,W0602
import json
import subprocess
import time
Expand All @@ -12,18 +13,18 @@
import sys
import uuid
import os
import os.path
import stat
import urllib.request
import configparser
import os.path
import sqlite3
import http

import libs.caribou as caribou

from datetime import timezone
from pathlib import Path

from libs import caribou


# Shared variable to signal the thread to stop
stop_signal = False

Expand Down Expand Up @@ -129,7 +130,7 @@ def process_lines(lines, debug):
break

if filename:
with open(filename, 'r') as file:
with open(filename, 'r', encoding='utf-8') as file:
lines = file.readlines()
process_lines(lines, debug)
else:
Expand All @@ -138,11 +139,11 @@ def process_lines(lines, debug):
'-i', str(SETTINGS['powermetrics']),
'-f', 'plist']

process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, text=True)
process_lines(process.stdout, debug)
with subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, text=True) as process:
process_lines(process.stdout, debug)

if stop_signal:
process.terminate()
if stop_signal:
process.terminate()

# Make sure that all data has been uploaded when exiting
upload_data_to_endpoint()
Expand Down Expand Up @@ -229,9 +230,9 @@ def parse_powermetrics_output(output: str):
data=plistlib.loads(data)
data['timezone'] = time.tzname
data['timestamp'] = int(data['timestamp'].replace(tzinfo=timezone.utc).timestamp() * 1e3)
except xml.parsers.expat.ExpatError:
except xml.parsers.expat.ExpatError as exc:
print(data)
raise xml.parsers.expat.ExpatError
raise exc

compressed_data = zlib.compress(str(json.dumps(data)).encode())
compressed_data_str = base64.b64encode(compressed_data).decode()
Expand Down Expand Up @@ -268,7 +269,7 @@ def parse_powermetrics_output(output: str):
cpu_energy_data['ane_energy'],
cpu_energy_data['energy_impact']))

for key in stats.keys():
for key in stats:
stats[key] += cpu_energy_data[key]


Expand Down Expand Up @@ -354,5 +355,3 @@ def save_settings():
run_powermetrics(args.debug, args.file)

c.close()


0 comments on commit 2946a5a

Please sign in to comment.