Skip to content

Commit

Permalink
Format python files
Browse files Browse the repository at this point in the history
This is the result of the execution of "ruff format" command.
  • Loading branch information
pgiraud committed Aug 14, 2024
1 parent d11242c commit 92f65b8
Show file tree
Hide file tree
Showing 24 changed files with 4,199 additions and 2,966 deletions.
27 changes: 14 additions & 13 deletions powa/collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Dashboard for the powa-collector summary page, and other infrastructure for the
collector handling.
"""

from __future__ import absolute_import

import json
Expand All @@ -28,12 +29,12 @@ def post_process(self, data, server, **kwargs):
row = self.execute(sql, params={"server": server})

# unexisting server, bail out
if (len(row) != 1):
if len(row) != 1:
data["messages"] = {"alert": ["This server does not exists"]}
return data

status = "unknown"
if (server == "0"):
if server == "0":
status = self.execute("""SELECT
CASE WHEN count(*) = 1 THEN 'running'
ELSE 'stopped'
Expand All @@ -45,24 +46,24 @@ def post_process(self, data, server, **kwargs):

status = None
# did we receive a valid answer?
if (len(raw) != 0 and "OK" in raw[0]):
if len(raw) != 0 and "OK" in raw[0]:
# just keep the first one
tmp = raw[0]["OK"]
if (server in tmp):
if server in tmp:
status = json.loads(tmp)[server]

if (status is None):
return {"messages": {"warning": ["Could not get status for this "
"instance"]},
"data": []}
if status is None:
return {
"messages": {"warning": ["Could not get status for this " "instance"]},
"data": [],
}

msg = "Collector status for this instance: " + status
level = "alert"
if (status == "running"):
if status == "running":
level = "success"

return {"messages": {level: [msg]},
"data": []}
return {"messages": {level: [msg]}, "data": []}


class CollectorReloadHandler(AuthHandler):
Expand All @@ -76,7 +77,7 @@ def get(self):
# iterate over the results. If at least one OK is received, report
# success, otherwise failure
for a in answers:
if ("OK" in a):
if "OK" in a:
res = True
break

Expand All @@ -99,7 +100,7 @@ def post(self):
payload = json.loads(self.request.body.decode("utf8"))
nb_db = len(payload["dbnames"])
args = [payload["srvid"], str(nb_db)]
if (nb_db > 0):
if nb_db > 0:
args.extend(payload["dbnames"])

answers = self.notify_collector("REFRESH_DB_CAT", args)
Expand Down
9 changes: 8 additions & 1 deletion powa/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
http://pypi.python.org/pypi/six/
"""

from __future__ import absolute_import

import json
Expand All @@ -17,20 +18,26 @@
if psycopg2_version < ("2", "5"):
JSON_OID = 114
newtype = extensions.new_type(
(JSON_OID,), "JSON", lambda data, cursor: json.loads(data))
(JSON_OID,), "JSON", lambda data, cursor: json.loads(data)
)
extensions.register_type(newtype)


def with_metaclass(meta, *bases):
"""Create a base class with a metaclass."""

# This requires a bit of explanation: the basic idea is to make a dummy
# metaclass for one level of class instantiation that replaces itself with
# the actual metaclass.
class metaclass(meta):
"""The actual metaclass."""

def __new__(cls, name, _, d):
return meta(name, bases, d)

return type.__new__(metaclass, "temporary_class", (), {})


class classproperty(object):
"""
A descriptor similar to property, but using the class.
Expand Down
Loading

0 comments on commit 92f65b8

Please sign in to comment.