Skip to content

Commit 5102868

Browse files
committed
[qa] Switched to double quotes (black formatter)
1 parent a9993c7 commit 5102868

File tree

137 files changed

+6456
-6458
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

137 files changed

+6456
-6458
lines changed

docs/developer/extending.rst

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,7 @@ Add the following to your ``settings.py``:
197197
MONITORING_ALERTSETTINGS_MODEL = "YOUR_MODULE_NAME.AlertSettings"
198198
# For extending device_monitoring app
199199
DEVICE_MONITORING_DEVICEDATA_MODEL = "YOUR_MODULE_NAME.DeviceData"
200-
DEVICE_MONITORING_DEVICEMONITORING_MODEL = (
201-
"YOUR_MODULE_NAME.DeviceMonitoring"
202-
)
200+
DEVICE_MONITORING_DEVICEMONITORING_MODEL = "YOUR_MODULE_NAME.DeviceMonitoring"
203201
DEVICE_MONITORING_WIFICLIENT_MODEL = "YOUR_MODULE_NAME.WifiClient"
204202
DEVICE_MONITORING_WIFISESSION_MODEL = "YOUR_MODULE_NAME.WifiSession"
205203

docs/developer/utils.rst

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,7 @@ An example usage has been shown below.
115115
"verbose_name": "Ping PROBLEM",
116116
"verb": "cannot be reached anymore",
117117
"level": "warning",
118-
"email_subject": _(
119-
"[{site.name}] {notification.target} is not reachable"
120-
),
118+
"email_subject": _("[{site.name}] {notification.target} is not reachable"),
121119
"message": _(
122120
"The device [{notification.target}] {notification.verb} anymore by our ping "
123121
"messages."

docs/user/settings.rst

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -495,9 +495,7 @@ do it:
495495

496496
.. code-block:: python
497497
498-
OPENWISP_MONITORING_CHARTS = {
499-
"traffic": {"colors": ["#000000", "#cccccc", "#111111"]}
500-
}
498+
OPENWISP_MONITORING_CHARTS = {"traffic": {"colors": ["#000000", "#cccccc", "#111111"]}}
501499
502500
Adaptive Size Charts
503501
~~~~~~~~~~~~~~~~~~~~

openwisp_monitoring/__init__.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
VERSION = (1, 2, 0, 'alpha')
1+
VERSION = (1, 2, 0, "alpha")
22
__version__ = VERSION # alias
33

44

55
def get_version():
6-
version = '%s.%s' % (VERSION[0], VERSION[1])
6+
version = "%s.%s" % (VERSION[0], VERSION[1])
77
if VERSION[2]:
8-
version = '%s.%s' % (version, VERSION[2])
9-
if VERSION[3:] == ('alpha', 0):
10-
version = '%s pre-alpha' % version
8+
version = "%s.%s" % (version, VERSION[2])
9+
if VERSION[3:] == ("alpha", 0):
10+
version = "%s pre-alpha" % version
1111
else:
12-
if VERSION[3] != 'final':
12+
if VERSION[3] != "final":
1313
try:
1414
rev = VERSION[4]
1515
except IndexError:
1616
rev = 0
17-
version = '%s%s%s' % (version, VERSION[3][0:1], rev)
17+
version = "%s%s%s" % (version, VERSION[3][0:1], rev)
1818
return version

openwisp_monitoring/check/admin.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33

44
from openwisp_utils.admin import TimeReadonlyAdminMixin
55

6-
Check = load_model('check', 'Check')
6+
Check = load_model("check", "Check")
77

88

99
@admin.register(Check)
1010
class CheckAdmin(TimeReadonlyAdminMixin, admin.ModelAdmin):
11-
list_display = ['__str__', 'check_type', 'created', 'modified']
12-
search_fields = ['name', 'object_id']
11+
list_display = ["__str__", "check_type", "created", "modified"]
12+
search_fields = ["name", "object_id"]
1313
# TODO: filters
1414
save_on_top = True

openwisp_monitoring/check/apps.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,18 @@
77

88

99
class CheckConfig(AppConfig):
10-
name = 'openwisp_monitoring.check'
11-
label = 'check'
12-
verbose_name = _('Network Monitoring Checks')
10+
name = "openwisp_monitoring.check"
11+
label = "check"
12+
verbose_name = _("Network Monitoring Checks")
1313

1414
def ready(self):
1515
self._connect_signals()
1616

1717
def _connect_signals(self):
18-
Check = load_model('check', 'Check')
18+
Check = load_model("check", "Check")
1919

2020
post_save.connect(
2121
Check.auto_create_check_receiver,
22-
sender=load_model('config', 'Device'),
23-
dispatch_uid='auto_create_check',
22+
sender=load_model("config", "Device"),
23+
dispatch_uid="auto_create_check",
2424
)

openwisp_monitoring/check/base/models.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,57 +18,57 @@
1818
class AbstractCheck(TimeStampedEditableModel):
1919
name = models.CharField(max_length=64, db_index=True)
2020
is_active = models.BooleanField(
21-
_('active'),
21+
_("active"),
2222
default=True,
2323
db_index=True,
2424
help_text=_(
25-
'whether the check should be run, related metrics collected and alerts sent'
25+
"whether the check should be run, related metrics collected and alerts sent"
2626
),
2727
)
28-
description = models.TextField(blank=True, help_text=_('Notes'))
28+
description = models.TextField(blank=True, help_text=_("Notes"))
2929
content_type = models.ForeignKey(
3030
ContentType, on_delete=models.CASCADE, null=True, blank=True
3131
)
3232
object_id = models.CharField(max_length=36, db_index=True, blank=True)
33-
content_object = GenericForeignKey('content_type', 'object_id')
33+
content_object = GenericForeignKey("content_type", "object_id")
3434
check_type = models.CharField(
35-
_('check type'),
35+
_("check type"),
3636
choices=app_settings.CHECK_CHOICES,
3737
db_index=True,
3838
max_length=128,
3939
)
4040
params = JSONField(
41-
_('parameters'),
41+
_("parameters"),
4242
default=dict,
4343
blank=True,
44-
help_text=_('parameters needed to perform the check'),
45-
load_kwargs={'object_pairs_hook': OrderedDict},
46-
dump_kwargs={'indent': 4},
44+
help_text=_("parameters needed to perform the check"),
45+
load_kwargs={"object_pairs_hook": OrderedDict},
46+
dump_kwargs={"indent": 4},
4747
)
4848

4949
class Meta:
5050
abstract = True
51-
unique_together = ('name', 'object_id', 'content_type')
51+
unique_together = ("name", "object_id", "content_type")
5252
indexes = [
5353
models.Index(
54-
fields=['content_type', 'object_id', 'is_active'],
55-
name='active_object_checks_idx',
54+
fields=["content_type", "object_id", "is_active"],
55+
name="active_object_checks_idx",
5656
)
5757
]
5858

5959
permissions = (
60-
('add_check_inline', 'Can add check inline'),
61-
('change_check_inline', 'Can change check inline'),
62-
('delete_check_inline', 'Can delete check inline'),
63-
('view_check_inline', 'Can view check inline'),
60+
("add_check_inline", "Can add check inline"),
61+
("change_check_inline", "Can change check inline"),
62+
("delete_check_inline", "Can delete check inline"),
63+
("view_check_inline", "Can view check inline"),
6464
)
6565

6666
def __str__(self):
6767
if not self.object_id or not self.content_type:
6868
return self.name
6969
obj = self.content_object
7070
model_name = obj.__class__.__name__
71-
return '{0} ({1}: {2})'.format(self.name, model_name, obj)
71+
return "{0} ({1}: {2})".format(self.name, model_name, obj)
7272

7373
def clean(self):
7474
self.check_instance.validate()
@@ -95,10 +95,10 @@ def check_instance(self):
9595
def perform_check(self, store=True):
9696
"""Initializes check instance and calls the check method."""
9797
if (
98-
hasattr(self.content_object, 'is_deactivated')
98+
hasattr(self.content_object, "is_deactivated")
9999
and self.content_object.is_deactivated()
100100
) or (
101-
hasattr(self.content_object, 'organization_id')
101+
hasattr(self.content_object, "organization_id")
102102
and self.content_object.organization.is_active is False
103103
):
104104
return

openwisp_monitoring/check/checks.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88
@register()
99
def check_wifi_clients_snooze_schedule(app_configs, **kwargs):
1010
errors = []
11-
setting_name = 'OPENWISP_MONITORING_WIFI_CLIENTS_CHECK_SNOOZE_SCHEDULE'
11+
setting_name = "OPENWISP_MONITORING_WIFI_CLIENTS_CHECK_SNOOZE_SCHEDULE"
1212
schedule = app_settings.WIFI_CLIENTS_CHECK_SNOOZE_SCHEDULE
1313

1414
if not isinstance(schedule, (list, tuple)):
1515
errors.append(
1616
Error(
17-
'Invalid schedule format',
18-
hint='Schedule must be a list of date-time ranges',
17+
"Invalid schedule format",
18+
hint="Schedule must be a list of date-time ranges",
1919
obj=setting_name,
2020
)
2121
)
@@ -25,8 +25,8 @@ def check_wifi_clients_snooze_schedule(app_configs, **kwargs):
2525
if not isinstance(item, (list, tuple)) or len(item) != 2:
2626
errors.append(
2727
Error(
28-
f'Invalid schedule entry format: {item}',
29-
hint='Each schedule entry must be a pair of start and end times',
28+
f"Invalid schedule entry format: {item}",
29+
hint="Each schedule entry must be a pair of start and end times",
3030
obj=setting_name,
3131
)
3232
)
@@ -36,7 +36,7 @@ def check_wifi_clients_snooze_schedule(app_configs, **kwargs):
3636
if not isinstance(start, str) or not isinstance(end, str):
3737
errors.append(
3838
Error(
39-
f'Invalid time format: {item}',
39+
f"Invalid time format: {item}",
4040
hint='Use format "MM-DD HH:MM", "MM-DD", or "HH:MM"',
4141
obj=setting_name,
4242
)
@@ -45,29 +45,29 @@ def check_wifi_clients_snooze_schedule(app_configs, **kwargs):
4545

4646
try:
4747
# Check if both are time format (HH:MM)
48-
if '-' not in start and '-' not in end:
49-
datetime.strptime(start, '%H:%M')
50-
datetime.strptime(end, '%H:%M')
48+
if "-" not in start and "-" not in end:
49+
datetime.strptime(start, "%H:%M")
50+
datetime.strptime(end, "%H:%M")
5151
# Check if both are date format (MM-DD)
52-
elif ':' not in start and ':' not in end:
53-
datetime.strptime(start, '%m-%d')
54-
datetime.strptime(end, '%m-%d')
52+
elif ":" not in start and ":" not in end:
53+
datetime.strptime(start, "%m-%d")
54+
datetime.strptime(end, "%m-%d")
5555
# Check if both are date-time format (MM-DD HH:MM)
5656
elif len(start.split()) == 2 and len(end.split()) == 2:
57-
datetime.strptime(start, '%m-%d %H:%M')
58-
datetime.strptime(end, '%m-%d %H:%M')
57+
datetime.strptime(start, "%m-%d %H:%M")
58+
datetime.strptime(end, "%m-%d %H:%M")
5959
else:
6060
errors.append(
6161
Error(
62-
f'Inconsistent format: {item}',
63-
hint='Both start and end must be in the same format (either both time or both date)',
62+
f"Inconsistent format: {item}",
63+
hint="Both start and end must be in the same format (either both time or both date)",
6464
obj=setting_name,
6565
)
6666
)
6767
except ValueError:
6868
errors.append(
6969
Error(
70-
f'Invalid date-time format: {item}',
70+
f"Invalid date-time format: {item}",
7171
hint='Use format "MM-DD HH:MM", "MM-DD", or "HH:MM"',
7272
obj=setting_name,
7373
)

openwisp_monitoring/check/classes/base.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77

88
logger = logging.getLogger(__name__)
99

10-
Check = load_model('check', 'Check')
11-
Metric = load_model('monitoring', 'Metric')
12-
Device = load_model('config', 'Device')
10+
Check = load_model("check", "Check")
11+
Metric = load_model("monitoring", "Metric")
12+
Device = load_model("config", "Device")
1313

1414

1515
class BaseCheck(object):
@@ -35,8 +35,8 @@ def validate_instance(self):
3535
# check instance is of type device
3636
obj = self.related_object
3737
if not obj or not isinstance(obj, Device):
38-
message = 'A related device is required to perform this operation'
39-
raise ValidationError({'content_type': message, 'object_id': message})
38+
message = "A related device is required to perform this operation"
39+
raise ValidationError({"content_type": message, "object_id": message})
4040

4141
def validate(self):
4242
self.validate_instance()
@@ -82,14 +82,14 @@ def timed_check(self, store=True):
8282
start_time = time.time()
8383
result = self.check(store=store)
8484
elapsed_time = time.time() - start_time
85-
if hasattr(self, '_store_result_elapsed_time'):
85+
if hasattr(self, "_store_result_elapsed_time"):
8686
elapsed_time -= self._store_result_elapsed_time
8787
logger.info(
8888
'Check "%s" executed in %.2fs, writing took %.2fs'
8989
% (
9090
self.check_instance,
9191
elapsed_time,
92-
getattr(self, '_store_result_elapsed_time', 0.0),
92+
getattr(self, "_store_result_elapsed_time", 0.0),
9393
),
9494
)
9595
return result

openwisp_monitoring/check/classes/config_applied.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,31 @@
77
from ..settings import CONFIG_CHECK_INTERVAL
88
from .base import BaseCheck
99

10-
AlertSettings = load_model('monitoring', 'AlertSettings')
10+
AlertSettings = load_model("monitoring", "AlertSettings")
1111

1212

1313
class ConfigApplied(BaseCheck):
1414
@classmethod
1515
def get_related_metrics(cls):
16-
return ('config_applied',)
16+
return ("config_applied",)
1717

1818
def check(self, store=True):
1919
# If the device is down or does not have a config
2020
# do not run config applied check
2121
if self.related_object.monitoring.status in [
22-
'critical',
23-
'unknown',
24-
] or not hasattr(self.related_object, 'config'):
22+
"critical",
23+
"unknown",
24+
] or not hasattr(self.related_object, "config"):
2525
return
2626
result = int(
27-
self.related_object.config.status == 'applied'
27+
self.related_object.config.status == "applied"
2828
or self.related_object.modified
2929
> timezone.now() - timedelta(minutes=CONFIG_CHECK_INTERVAL)
3030
)
3131
# If the device config is in error status we don't need to notify
3232
# the user (because that's already done by openwisp-controller)
3333
# but we need to ensure health status will be changed
34-
send_alert = self.related_object.config.status != 'error'
34+
send_alert = self.related_object.config.status != "error"
3535
if store:
3636
self.timed_store(result, send_alert)
3737
return result
@@ -42,7 +42,7 @@ def store(self, result, send_alert, **kwargs):
4242
)
4343

4444
def _get_metric(self):
45-
metric, created = self._get_or_create_metric(configuration='config_applied')
45+
metric, created = self._get_or_create_metric(configuration="config_applied")
4646
if created:
4747
self._create_alert_setting(metric)
4848
return metric

0 commit comments

Comments
 (0)