Skip to content

Commit a9f7bcf

Browse files
committed
ref(load_db_state): move saving to separate def
Reduces cyclomatic complexity enough to make flake8 happy.
1 parent bab3632 commit a9f7bcf

1 file changed

Lines changed: 19 additions & 14 deletions

File tree

rootfs/api/management/commands/load_db_state_to_k8s.py

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,8 @@ class Command(BaseCommand):
1212
def handle(self, *args, **options):
1313
"""Publishes Deis platform state from the database to kubernetes."""
1414
print("Publishing DB state to kubernetes...")
15-
for app in App.objects.all():
16-
try:
17-
app.save()
18-
app.config_set.latest().save()
19-
except DeisException as error:
20-
print('ERROR: Problem saving to model {} for {}'
21-
'due to {}'.format(str(App.__name__), str(app), str(error)))
22-
for model in (Key, Domain, Certificate):
23-
for obj in model.objects.all():
24-
try:
25-
obj.save()
26-
except DeisException as error:
27-
print('ERROR: Problem saving to model {} for {}'
28-
'due to {}'.format(str(model.__name__), str(obj), str(error)))
15+
16+
self.save_apps()
2917

3018
# certificates have to be attached to domains to create k8s secrets
3119
for cert in Certificate.objects.all():
@@ -53,3 +41,20 @@ def handle(self, *args, **options):
5341
'due to {}'.format(application, str(error)))
5442

5543
print("Done Publishing DB state to kubernetes.")
44+
45+
def save_apps(self):
46+
"""Saves important Django data models to the database."""
47+
for app in App.objects.all():
48+
try:
49+
app.save()
50+
app.config_set.latest().save()
51+
except DeisException as error:
52+
print('ERROR: Problem saving to model {} for {}'
53+
'due to {}'.format(str(App.__name__), str(app), str(error)))
54+
for model in (Key, Domain, Certificate):
55+
for obj in model.objects.all():
56+
try:
57+
obj.save()
58+
except DeisException as error:
59+
print('ERROR: Problem saving to model {} for {}'
60+
'due to {}'.format(str(model.__name__), str(obj), str(error)))

0 commit comments

Comments
 (0)