Ejemplo n.º 1
0
 def process_third_parties(self, settings_dict):
     result = []
     for k, v in self.common_third_parties.items():
         package_name = v.partition(".")[0]
         if not settings_dict[k]:
             continue
         elif not is_package_present(package_name):
             settings_check_results.append(missing_package(package_name, ""))
             continue
         result.append(v)
     return result
Ejemplo n.º 2
0
def pipeline_check(app_configs, **kwargs):
    """Check if dependencies used by `django-pipeline` are installed.
    """
    check_results = []
    requirements = get_pipeline_requirements()
    for name in requirements["all"]:
        if not find_executable(name):
            check_results.append(
                Error(
                    "'%s' is required by 'django-pipeline' and is not found in PATH."
                    % name,
                    obj="configuration",
                ))
    for name, package in requirements["pip"]:
        if not is_package_present(name):
            check_results.append(
                missing_package(package, " by 'django-pipeline'"))
    return check_results
Ejemplo n.º 3
0
def pipeline_check(app_configs, **kwargs):
    """Check if dependencies used by `django-pipeline` are installed.
    """
    check_results = []
    requirements = get_pipeline_requirements()
    for name in requirements["all"]:
        if not find_executable(name):
            check_results.append(
                Error(
                    "'%s' is required by 'django-pipeline' and is not found in PATH."
                    % name,
                    obj="configuration",
                )
            )
    for name, package in requirements["pip"]:
        if not is_package_present(name):
            check_results.append(missing_package(package, " by 'django-pipeline'"))
    return check_results
Ejemplo n.º 4
0
__author__ = "Matthieu Gallet"

# ######################################################################################################################
#
# detect if some external packages are available, to automatically customize some settings
#
# ######################################################################################################################
try:
    import django_redis  # does not work with is_package_present (???)

    USE_REDIS_CACHE = True
except ImportError:
    django_redis = None
    USE_REDIS_CACHE = False
USE_CELERY = is_package_present("celery")
USE_REDIS_SESSIONS = is_package_present("redis_sessions")
USE_PIPELINE = is_package_present("pipeline")
USE_DEBUG_TOOLBAR = is_package_present("debug_toolbar")
USE_REST_FRAMEWORK = is_package_present("rest_framework")
USE_ALL_AUTH = is_package_present("allauth")

# ######################################################################################################################
#
# settings that could be kept as-is for most projects
# of course, you can override them in your default settings
#
# ######################################################################################################################
ADMINS = (("admin", "{ADMIN_EMAIL}"), )
ALLOWED_HOSTS = CallableSetting(allowed_hosts)
CACHE_URL = CallableSetting(cache_redis_url)
Ejemplo n.º 5
0
    def __call__(self, settings_dict, argv=None):
        if argv is None:
            argv = sys.argv
        self.module_name = settings_dict["DF_MODULE_NAME"]
        self.server_name = settings_dict["SERVER_NAME"]
        self.server_port = settings_dict["SERVER_PORT"]
        self.excluded_commands = settings_dict["LOG_EXCLUDED_COMMANDS"]
        if settings_dict["LOG_LEVEL"]:
            log_level = settings_dict["LOG_LEVEL"].upper()
        elif settings_dict["DEBUG"]:
            log_level = "DEBUG"
        else:
            log_level = "WARN"
        self.formatters = self.get_default_formatters()
        self.filters = self.get_default_filters()
        self.loggers = self.get_default_loggers()
        self.handlers = self.get_default_handlers()
        self.root = self.get_default_root()
        self.log_suffix = self.get_smart_command_name(
            self.module_name,
            settings_dict["SCRIPT_NAME"],
            argv,
            self.excluded_commands,
        )
        self.log_directory = settings_dict["LOG_DIRECTORY"]
        config = {
            "version": 1,
            "disable_existing_loggers": True,
            "formatters": self.formatters,
            "filters": self.filters,
            "handlers": self.handlers,
            "loggers": self.loggers,
            "root": self.root,
        }
        self.root["level"] = log_level
        for logger, levels in self.problem_loggers.items():
            self.loggers[logger]["level"] = levels.get(log_level, log_level)
        for logger, levels in self.access_loggers.items():
            self.loggers[logger]["level"] = levels.get(log_level, log_level)

        if settings_dict["DEBUG"]:
            warnings.simplefilter("always", DeprecationWarning)
            logging.captureWarnings(True)
            self.add_handler("ROOT",
                             "stdout",
                             level="INFO",
                             formatter="colorized")
            for logger in self.access_loggers:
                self.add_handler(logger,
                                 "stderr",
                                 level="DEBUG",
                                 formatter="django.server")
            return config

        has_handler = False

        if settings_dict["RAVEN_DSN"] and is_package_present("raven"):
            self.handlers["sentry"] = {
                "level": "ERROR",
                "class":
                "raven.contrib.django.raven_compat.handlers.SentryHandler",
                "tags": {
                    "application": self.log_suffix
                },
            }
            self.root["handlers"].append("sentry")
            has_handler = True

        if self.log_directory and self.log_suffix:
            self.add_handler("ROOT", "root", level=log_level)
            for logger in self.access_loggers:
                self.add_handler(logger,
                                 "access",
                                 level="DEBUG",
                                 formatter="nocolor")
            has_handler = True

        has_handler = has_handler or self.add_remote_collector(
            settings_dict["LOG_REMOTE_URL"],
            settings_dict["LOG_REMOTE_ACCESS"])
        if not has_handler or not self.log_suffix:
            # (no file or interactive command) and no logd/syslog => we print to the console (like the debug mode)
            self.add_handler("ROOT",
                             "stdout",
                             level=log_level,
                             formatter="colorized")
            for logger in self.access_loggers:
                self.add_handler(logger,
                                 "stderr",
                                 formatter="django.server",
                                 level=log_level)
        self.root["handlers"].append("mail_admins")
        return config
Ejemplo n.º 6
0
__author__ = "Matthieu Gallet"

# ######################################################################################################################
#
# detect if some external packages are available, to automatically customize some settings
#
# ######################################################################################################################
try:
    import django_redis  # does not work with is_package_present (???)

    USE_REDIS_CACHE = True
except ImportError:
    django_redis = None
    USE_REDIS_CACHE = False
USE_CELERY = is_package_present("celery")
USE_REDIS_SESSIONS = is_package_present("redis_sessions")
USE_PIPELINE = is_package_present("pipeline")
USE_DEBUG_TOOLBAR = is_package_present("debug_toolbar")
USE_REST_FRAMEWORK = is_package_present("rest_framework")
USE_ALL_AUTH = is_package_present("allauth")

# ######################################################################################################################
#
# settings that could be kept as-is for most projects
# of course, you can override them in your default settings
#
# ######################################################################################################################
ADMINS = (("admin", "{ADMIN_EMAIL}"),)
ALLOWED_HOSTS = CallableSetting(allowed_hosts)
CACHE_URL = CallableSetting(cache_redis_url)
Ejemplo n.º 7
0
    def __call__(self, settings_dict):
        self.module_name = settings_dict["DF_MODULE_NAME"]
        self.server_name = settings_dict["SERVER_NAME"]
        self.server_port = settings_dict["SERVER_PORT"]
        self.excluded_commands = settings_dict["LOG_EXCLUDED_COMMANDS"]
        self.formatters = self.get_default_formatters()
        self.filters = self.get_default_filters()
        self.loggers = self.get_default_loggers()
        self.handlers = self.get_default_handlers()
        self.root = self.get_default_root()
        self.log_suffix = self.get_smart_command_name(
            self.module_name,
            settings_dict["SCRIPT_NAME"],
            sys.argv,
            self.excluded_commands,
        )
        self.log_directory = settings_dict["LOG_DIRECTORY"]
        config = {
            "version": 1,
            "disable_existing_loggers": True,
            "formatters": self.formatters,
            "filters": self.filters,
            "handlers": self.handlers,
            "loggers": self.loggers,
            "root": self.root,
        }

        if settings_dict["DEBUG"]:
            warnings.simplefilter("always", DeprecationWarning)
            logging.captureWarnings(True)
            self.loggers["django.request"]["level"] = "DEBUG"
            self.loggers["py.warnings"]["level"] = "DEBUG"
            self.loggers["djangofloor.signals"]["level"] = "DEBUG"
            self.root["level"] = "DEBUG"
            self.add_handler("ROOT", "stdout", level="INFO", formatter="colorized")
            for logger in self.request_loggers:
                self.add_handler(
                    logger, "stderr", level="INFO", formatter="django.server"
                )
            return config
        if settings_dict["RAVEN_DSN"] and is_package_present("raven"):
            self.handlers["sentry"] = {
                "level": "ERROR",
                "class": "raven.contrib.django.raven_compat.handlers.SentryHandler",
                "tags": {"application": self.log_suffix},
            }
            self.root["handlers"].append("sentry")
        has_handler = False
        if self.log_directory and self.log_suffix:
            self.add_handler("ROOT", "warning", level="WARN")
            self.add_handler("ROOT", "error", level="ERROR")
            for logger in self.request_loggers:
                self.add_handler(logger, "access", level="INFO", formatter="nocolor")
            has_handler = True
        has_handler = has_handler or self.add_remote_collector(
            settings_dict["LOG_REMOTE_URL"], settings_dict["LOG_REMOTE_ACCESS"]
        )
        if not has_handler or not self.log_suffix:
            # (no file or interactive command) and no logd/syslog => we print to the console (like the debug mode)
            self.add_handler("ROOT", "stdout", level="WARN", formatter="colorized")
            for logger in self.request_loggers:
                self.add_handler(logger, "stderr", formatter="django.server")
        self.root["handlers"].append("mail_admins")
        return config