management: Refactor checkconfig code to live in library.

This makes it possible to call this from other management commands.
This commit is contained in:
Tim Abbott
2018-05-03 16:04:12 -07:00
parent d1b9e06cb4
commit f2e84f25a0
3 changed files with 21 additions and 10 deletions

View File

@@ -3,6 +3,7 @@
import sys
from argparse import ArgumentParser
from django.conf import settings
from django.core.exceptions import MultipleObjectsReturned
from django.core.management.base import BaseCommand, CommandError
from typing import Any, Dict, Optional, Text, List
@@ -16,6 +17,16 @@ def is_integer_string(val: str) -> bool:
except ValueError:
return False
def check_config() -> None:
for (setting_name, default) in settings.REQUIRED_SETTINGS:
try:
if settings.__getattr__(setting_name) != default:
continue
except AttributeError:
pass
raise CommandError("Error: You must set %s in /etc/zulip/settings.py." % (setting_name,))
class ZulipBaseCommand(BaseCommand):
def add_realm_args(self, parser: ArgumentParser, required: bool=False,
help: Optional[str]=None) -> None: