We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Make redis version check CRITICAL
If the redis version is not sufficiently recent the site will fail.

Currently there is a CRITICAL check for the presence of redis, but the version check is only a WARNING - i think it should be CRITICAL

The hint should also say what the minimum redis version is


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `pootle/checks.py`
Content:
```
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 #
4 # Copyright (C) Pootle contributors.
5 #
6 # This file is a part of the Pootle project. It is distributed under the GPL3
7 # or later license. See the LICENSE file for a copy of the license and the
8 # AUTHORS file for copyright and authorship information.
9 
10 from django.core import checks
11 from django.utils.translation import ugettext as _
12 
13 
14 # Minimum Translate Toolkit version required for Pootle to run.
15 TTK_MINIMUM_REQUIRED_VERSION = (1, 13, 0)
16 
17 # Minimum Django version required for Pootle to run.
18 DJANGO_MINIMUM_REQUIRED_VERSION = (1, 7, 10)
19 
20 # Minimum lxml version required for Pootle to run.
21 LXML_MINIMUM_REQUIRED_VERSION = (2, 2, 2, 0)
22 
23 # Minimum Redis server version required.
24 # Initially set to some minimums based on:
25 # 1. Ubuntu 12.04LTS's version 2.8.4 (10.04LTS was too old for RQ)
26 # 2. RQ requires >= 2.6.0, and
27 # 3. Wanting to insist on at least the latest stable that devs are using i.e.
28 #    2.8.* versions of Redis
29 REDIS_MINIMUM_REQUIRED_VERSION = (2, 8, 4)
30 
31 
32 # XXX List of manage.py commands not to run the rqworker check on.
33 # Maybe tagging can improve this?
34 RQWORKER_WHITELIST = [
35     "start", "initdb", "revision", "sync_stores", "run_cherrypy",
36     "refresh_stats", "update_stores", "calculate_checks", "retry_failed_jobs",
37     "check", "runserver",
38 ]
39 
40 
41 def _version_to_string(version, significance=None):
42     if significance is not None:
43         version = version[significance:]
44     return '.'.join(str(n) for n in version)
45 
46 
47 @checks.register()
48 def check_library_versions(app_configs=None, **kwargs):
49     from django import VERSION as django_version
50     from lxml.etree import LXML_VERSION as lxml_version
51     from translate.__version__ import ver as ttk_version
52 
53     errors = []
54 
55     if django_version < DJANGO_MINIMUM_REQUIRED_VERSION:
56         errors.append(checks.Critical(
57             _("Your version of Django is too old."),
58             hint=_("Try pip install --upgrade 'Django==%s'" %
59                    _version_to_string(DJANGO_MINIMUM_REQUIRED_VERSION)),
60             id="pootle.C002",
61         ))
62 
63     if lxml_version < LXML_MINIMUM_REQUIRED_VERSION:
64         errors.append(checks.Warning(
65             _("Your version of lxml is too old."),
66             hint=_("Try pip install --upgrade lxml"),
67             id="pootle.W003",
68         ))
69 
70     if ttk_version < TTK_MINIMUM_REQUIRED_VERSION:
71         errors.append(checks.Critical(
72             _("Your version of Translate Toolkit is too old."),
73             hint=_("Try pip install --upgrade translate-toolkit"),
74             id="pootle.C003",
75         ))
76 
77     return errors
78 
79 
80 @checks.register()
81 def check_redis(app_configs=None, **kwargs):
82     from django_rq.queues import get_queue
83     from django_rq.workers import Worker
84 
85     errors = []
86 
87     try:
88         queue = get_queue()
89         workers = Worker.all(queue.connection)
90     except Exception as e:
91         conn_settings = queue.connection.connection_pool.connection_kwargs
92         errors.append(checks.Critical(_("Could not connect to Redis (%s)") % (e),
93             hint=_("Make sure Redis is running on %(host)s:%(port)s") % (conn_settings),
94             id="pootle.C001",
95         ))
96     else:
97         if len(queue.connection.smembers(Worker.redis_workers_keys)) == 0:
98             # We need to check we're not running manage.py rqworker right now..
99             import sys
100             if len(sys.argv) > 1 and sys.argv[1] in RQWORKER_WHITELIST:
101                 errors.append(checks.Warning(
102                     _("No RQ Worker running."),
103                     hint=_("Run new workers with manage.py rqworker"),
104                     id="pootle.W001",
105                 ))
106 
107         redis_version = queue.connection.info()["redis_version"].split(".")
108         if tuple(int(x) for x in redis_version) < REDIS_MINIMUM_REQUIRED_VERSION:
109             errors.append(checks.Warning(
110                 _("Your version of Redis is too old."),
111                 hint=_("Update your system's Redis server package"),
112                 id="pootle.W002",
113             ))
114 
115     return errors
116 
117 
118 @checks.register()
119 def check_settings(app_configs=None, **kwargs):
120     from django.conf import settings
121 
122     errors = []
123 
124     if "RedisCache" not in settings.CACHES.get("default", {}).get("BACKEND"):
125         errors.append(checks.Critical(
126             _("Cache backend is not set to Redis."),
127             hint=_("Set default cache backend to django_redis.cache.RedisCache\n"
128                    "Current settings: %r") % (settings.CACHES.get("default")),
129             id="pootle.C005",
130         ))
131     else:
132         from django_redis import get_redis_connection
133 
134         if not get_redis_connection():
135             errors.append(checks.Critical(
136                 _("Could not initiate a Redis cache connection"),
137                 hint=_("Double-check your CACHES settings"),
138                 id="pootle.C004",
139             ))
140 
141     if settings.DEBUG:
142         errors.append(checks.Warning(
143             _("DEBUG mode is on. Do not do this in production!"),
144             hint=_("Set DEBUG = False in Pootle settings"),
145             id="pootle.W005"
146         ))
147     elif "sqlite" in settings.DATABASES.get("default", {}).get("ENGINE"):
148         # We don't bother warning about sqlite in DEBUG mode.
149         errors.append(checks.Warning(
150             _("The sqlite database backend is unsupported"),
151             hint=_("Set your default database engine to postgresql_psycopg2 or mysql"),
152             id="pootle.W006",
153         ))
154 
155     if settings.SESSION_ENGINE.split(".")[-1] not in ("cache", "cached_db"):
156         errors.append(checks.Warning(
157             _("Not using cached_db as session engine"),
158             hint=_("Set SESSION_ENGINE to django.contrib.sessions.backend.cached_db\n"
159                    "Current settings: %r") % (settings.SESSION_ENGINE),
160             id="pootle.W007",
161         ))
162 
163     if not settings.POOTLE_CONTACT_EMAIL and settings.POOTLE_CONTACT_ENABLED:
164         errors.append(checks.Warning(
165             _("POOTLE_CONTACT_EMAIL is not set."),
166             hint=_("Set POOTLE_CONTACT_EMAIL to allow users to contact "
167                    "administrators through the Pootle contact form."),
168             id="pootle.W008",
169         ))
170 
171     if settings.POOTLE_CONTACT_EMAIL in ("info@YOUR_DOMAIN.com") \
172        and settings.POOTLE_CONTACT_ENABLED:
173         errors.append(checks.Warning(
174             _("POOTLE_CONTACT_EMAIL is using the following default "
175               "setting %r." % settings.POOTLE_CONTACT_EMAIL),
176             hint=_("POOTLE_CONTACT_EMAIL is the address that will receive "
177                    "messages sent by the contact form."),
178             id="pootle.W011",
179         ))
180 
181     if not settings.DEFAULT_FROM_EMAIL:
182         errors.append(checks.Warning(
183             _("DEFAULT_FROM_EMAIL is not set."),
184             hint=_("DEFAULT_FROM_EMAIL is used in all outgoing Pootle email.\n"
185                    "Don't forget to review your mail server settings."),
186             id="pootle.W009",
187         ))
188 
189     if settings.DEFAULT_FROM_EMAIL in ("info@YOUR_DOMAIN.com",
190                                        "webmaster@localhost"):
191         errors.append(checks.Warning(
192             _("DEFAULT_FROM_EMAIL is using the following default "
193               "setting %r." % settings.DEFAULT_FROM_EMAIL),
194             hint=_("DEFAULT_FROM_EMAIL is used in all outgoing Pootle email.\n"
195                    "Don't forget to review your mail server settings."),
196             id="pootle.W010",
197         ))
198 
199     try:
200         markup_filter, markup_kwargs = settings.POOTLE_MARKUP_FILTER
201     except AttributeError:
202         errors.append(checks.Warning(
203             _("POOTLE_MARKUP_FILTER is missing."),
204             hint=_("Set POOTLE_MARKUP_FILTER."),
205             id="pootle.W012",
206         ))
207     except (IndexError, TypeError, ValueError):
208         errors.append(checks.Warning(
209             _("Invalid value in POOTLE_MARKUP_FILTER."),
210             hint=_("Set a valid value for POOTLE_MARKUP_FILTER."),
211             id="pootle.W013",
212         ))
213     else:
214         if markup_filter is not None:
215             try:
216                 if markup_filter == 'textile':
217                     import textile
218                 elif markup_filter == 'markdown':
219                     import markdown
220                 elif markup_filter == 'restructuredtext':
221                     import docutils
222                 else:
223                     errors.append(checks.Warning(
224                         _("Invalid markup in POOTLE_MARKUP_FILTER."),
225                         hint=_("Set a valid markup for POOTLE_MARKUP_FILTER."),
226                         id="pootle.W014",
227                     ))
228             except ImportError:
229                 errors.append(checks.Warning(
230                     _("POOTLE_MARKUP_FILTER is set to '%s' markup, but the "
231                       "package that provides can't be found." % markup_filter),
232                     hint=_("Install the package or change "
233                            "POOTLE_MARKUP_FILTER."),
234                     id="pootle.W015",
235                 ))
236 
237     return errors
238 
239 
240 @checks.register()
241 def check_users(app_configs=None, **kwargs):
242     from django.contrib.auth import get_user_model
243     from django.db import ProgrammingError
244     from django.db.utils import OperationalError
245 
246     errors = []
247 
248     User = get_user_model()
249     try:
250         admin_user = User.objects.get(username='admin')
251     except (User.DoesNotExist, OperationalError, ProgrammingError):
252         pass
253     else:
254         if admin_user.check_password('admin'):
255             errors.append(checks.Warning(
256                 _("The default 'admin' user still has a password set to "
257                   "'admin'."),
258                 hint=_("Remove the 'admin' user or change its password."),
259                 id="pootle.W016",
260             ))
261 
262     return errors
263 
264 
265 @checks.register()
266 def check_db_transaction_on_commit(app_configs=None, **kwargs):
267     from django.db import connection
268     errors = []
269     try:
270         on_commit = connection.on_commit
271     except AttributeError:
272         errors.append(checks.Critical(
273             _("Database connection does not implement on_commit."),
274             hint=_("Set the DATABASES['default']['ENGINE'] to use a backend "
275                    "from transaction_hooks.backends."),
276             id="pootle.C006",
277         ))
278     return errors
279
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/pootle/checks.py b/pootle/checks.py
--- a/pootle/checks.py
+++ b/pootle/checks.py
@@ -94,6 +94,17 @@
             id="pootle.C001",
         ))
     else:
+        redis_version = tuple(int(x) for x
+                              in (queue.connection
+                                       .info()["redis_version"].split(".")))
+        if redis_version < REDIS_MINIMUM_REQUIRED_VERSION:
+            errors.append(checks.Critical(
+                _("Your version of Redis is too old."),
+                hint=_("Update your system's Redis server package to at least "
+                       "version %s" % str(REDIS_MINIMUM_REQUIRED_VERSION)),
+                id="pootle.C007",
+            ))
+
         if len(queue.connection.smembers(Worker.redis_workers_keys)) == 0:
             # We need to check we're not running manage.py rqworker right now..
             import sys
@@ -104,14 +115,6 @@
                     id="pootle.W001",
                 ))
 
-        redis_version = queue.connection.info()["redis_version"].split(".")
-        if tuple(int(x) for x in redis_version) < REDIS_MINIMUM_REQUIRED_VERSION:
-            errors.append(checks.Warning(
-                _("Your version of Redis is too old."),
-                hint=_("Update your system's Redis server package"),
-                id="pootle.W002",
-            ))
-
     return errors

{"golden_diff": "diff --git a/pootle/checks.py b/pootle/checks.py\n--- a/pootle/checks.py\n+++ b/pootle/checks.py\n@@ -94,6 +94,17 @@\n             id=\"pootle.C001\",\n         ))\n     else:\n+        redis_version = tuple(int(x) for x\n+                              in (queue.connection\n+                                       .info()[\"redis_version\"].split(\".\")))\n+        if redis_version < REDIS_MINIMUM_REQUIRED_VERSION:\n+            errors.append(checks.Critical(\n+                _(\"Your version of Redis is too old.\"),\n+                hint=_(\"Update your system's Redis server package to at least \"\n+                       \"version %s\" % str(REDIS_MINIMUM_REQUIRED_VERSION)),\n+                id=\"pootle.C007\",\n+            ))\n+\n         if len(queue.connection.smembers(Worker.redis_workers_keys)) == 0:\n             # We need to check we're not running manage.py rqworker right now..\n             import sys\n@@ -104,14 +115,6 @@\n                     id=\"pootle.W001\",\n                 ))\n \n-        redis_version = queue.connection.info()[\"redis_version\"].split(\".\")\n-        if tuple(int(x) for x in redis_version) < REDIS_MINIMUM_REQUIRED_VERSION:\n-            errors.append(checks.Warning(\n-                _(\"Your version of Redis is too old.\"),\n-                hint=_(\"Update your system's Redis server package\"),\n-                id=\"pootle.W002\",\n-            ))\n-\n     return errors\n", "issue": "Make redis version check CRITICAL\nIf the redis version is not sufficiently recent the site will fail.\n\nCurrently there is a CRITICAL check for the presence of redis, but the version check is only a WARNING - i think it should be CRITICAL\n\nThe hint should also say what the minimum redis version is\n\n", "before_files": [{"content": "#!/usr/bin/env python\n# -*- coding: utf-8 -*-\n#\n# Copyright (C) Pootle contributors.\n#\n# This file is a part of the Pootle project. It is distributed under the GPL3\n# or later license. See the LICENSE file for a copy of the license and the\n# AUTHORS file for copyright and authorship information.\n\nfrom django.core import checks\nfrom django.utils.translation import ugettext as _\n\n\n# Minimum Translate Toolkit version required for Pootle to run.\nTTK_MINIMUM_REQUIRED_VERSION = (1, 13, 0)\n\n# Minimum Django version required for Pootle to run.\nDJANGO_MINIMUM_REQUIRED_VERSION = (1, 7, 10)\n\n# Minimum lxml version required for Pootle to run.\nLXML_MINIMUM_REQUIRED_VERSION = (2, 2, 2, 0)\n\n# Minimum Redis server version required.\n# Initially set to some minimums based on:\n# 1. Ubuntu 12.04LTS's version 2.8.4 (10.04LTS was too old for RQ)\n# 2. RQ requires >= 2.6.0, and\n# 3. Wanting to insist on at least the latest stable that devs are using i.e.\n#    2.8.* versions of Redis\nREDIS_MINIMUM_REQUIRED_VERSION = (2, 8, 4)\n\n\n# XXX List of manage.py commands not to run the rqworker check on.\n# Maybe tagging can improve this?\nRQWORKER_WHITELIST = [\n    \"start\", \"initdb\", \"revision\", \"sync_stores\", \"run_cherrypy\",\n    \"refresh_stats\", \"update_stores\", \"calculate_checks\", \"retry_failed_jobs\",\n    \"check\", \"runserver\",\n]\n\n\ndef _version_to_string(version, significance=None):\n    if significance is not None:\n        version = version[significance:]\n    return '.'.join(str(n) for n in version)\n\n\n@checks.register()\ndef check_library_versions(app_configs=None, **kwargs):\n    from django import VERSION as django_version\n    from lxml.etree import LXML_VERSION as lxml_version\n    from translate.__version__ import ver as ttk_version\n\n    errors = []\n\n    if django_version < DJANGO_MINIMUM_REQUIRED_VERSION:\n        errors.append(checks.Critical(\n            _(\"Your version of Django is too old.\"),\n            hint=_(\"Try pip install --upgrade 'Django==%s'\" %\n                   _version_to_string(DJANGO_MINIMUM_REQUIRED_VERSION)),\n            id=\"pootle.C002\",\n        ))\n\n    if lxml_version < LXML_MINIMUM_REQUIRED_VERSION:\n        errors.append(checks.Warning(\n            _(\"Your version of lxml is too old.\"),\n            hint=_(\"Try pip install --upgrade lxml\"),\n            id=\"pootle.W003\",\n        ))\n\n    if ttk_version < TTK_MINIMUM_REQUIRED_VERSION:\n        errors.append(checks.Critical(\n            _(\"Your version of Translate Toolkit is too old.\"),\n            hint=_(\"Try pip install --upgrade translate-toolkit\"),\n            id=\"pootle.C003\",\n        ))\n\n    return errors\n\n\n@checks.register()\ndef check_redis(app_configs=None, **kwargs):\n    from django_rq.queues import get_queue\n    from django_rq.workers import Worker\n\n    errors = []\n\n    try:\n        queue = get_queue()\n        workers = Worker.all(queue.connection)\n    except Exception as e:\n        conn_settings = queue.connection.connection_pool.connection_kwargs\n        errors.append(checks.Critical(_(\"Could not connect to Redis (%s)\") % (e),\n            hint=_(\"Make sure Redis is running on %(host)s:%(port)s\") % (conn_settings),\n            id=\"pootle.C001\",\n        ))\n    else:\n        if len(queue.connection.smembers(Worker.redis_workers_keys)) == 0:\n            # We need to check we're not running manage.py rqworker right now..\n            import sys\n            if len(sys.argv) > 1 and sys.argv[1] in RQWORKER_WHITELIST:\n                errors.append(checks.Warning(\n                    _(\"No RQ Worker running.\"),\n                    hint=_(\"Run new workers with manage.py rqworker\"),\n                    id=\"pootle.W001\",\n                ))\n\n        redis_version = queue.connection.info()[\"redis_version\"].split(\".\")\n        if tuple(int(x) for x in redis_version) < REDIS_MINIMUM_REQUIRED_VERSION:\n            errors.append(checks.Warning(\n                _(\"Your version of Redis is too old.\"),\n                hint=_(\"Update your system's Redis server package\"),\n                id=\"pootle.W002\",\n            ))\n\n    return errors\n\n\n@checks.register()\ndef check_settings(app_configs=None, **kwargs):\n    from django.conf import settings\n\n    errors = []\n\n    if \"RedisCache\" not in settings.CACHES.get(\"default\", {}).get(\"BACKEND\"):\n        errors.append(checks.Critical(\n            _(\"Cache backend is not set to Redis.\"),\n            hint=_(\"Set default cache backend to django_redis.cache.RedisCache\\n\"\n                   \"Current settings: %r\") % (settings.CACHES.get(\"default\")),\n            id=\"pootle.C005\",\n        ))\n    else:\n        from django_redis import get_redis_connection\n\n        if not get_redis_connection():\n            errors.append(checks.Critical(\n                _(\"Could not initiate a Redis cache connection\"),\n                hint=_(\"Double-check your CACHES settings\"),\n                id=\"pootle.C004\",\n            ))\n\n    if settings.DEBUG:\n        errors.append(checks.Warning(\n            _(\"DEBUG mode is on. Do not do this in production!\"),\n            hint=_(\"Set DEBUG = False in Pootle settings\"),\n            id=\"pootle.W005\"\n        ))\n    elif \"sqlite\" in settings.DATABASES.get(\"default\", {}).get(\"ENGINE\"):\n        # We don't bother warning about sqlite in DEBUG mode.\n        errors.append(checks.Warning(\n            _(\"The sqlite database backend is unsupported\"),\n            hint=_(\"Set your default database engine to postgresql_psycopg2 or mysql\"),\n            id=\"pootle.W006\",\n        ))\n\n    if settings.SESSION_ENGINE.split(\".\")[-1] not in (\"cache\", \"cached_db\"):\n        errors.append(checks.Warning(\n            _(\"Not using cached_db as session engine\"),\n            hint=_(\"Set SESSION_ENGINE to django.contrib.sessions.backend.cached_db\\n\"\n                   \"Current settings: %r\") % (settings.SESSION_ENGINE),\n            id=\"pootle.W007\",\n        ))\n\n    if not settings.POOTLE_CONTACT_EMAIL and settings.POOTLE_CONTACT_ENABLED:\n        errors.append(checks.Warning(\n            _(\"POOTLE_CONTACT_EMAIL is not set.\"),\n            hint=_(\"Set POOTLE_CONTACT_EMAIL to allow users to contact \"\n                   \"administrators through the Pootle contact form.\"),\n            id=\"pootle.W008\",\n        ))\n\n    if settings.POOTLE_CONTACT_EMAIL in (\"info@YOUR_DOMAIN.com\") \\\n       and settings.POOTLE_CONTACT_ENABLED:\n        errors.append(checks.Warning(\n            _(\"POOTLE_CONTACT_EMAIL is using the following default \"\n              \"setting %r.\" % settings.POOTLE_CONTACT_EMAIL),\n            hint=_(\"POOTLE_CONTACT_EMAIL is the address that will receive \"\n                   \"messages sent by the contact form.\"),\n            id=\"pootle.W011\",\n        ))\n\n    if not settings.DEFAULT_FROM_EMAIL:\n        errors.append(checks.Warning(\n            _(\"DEFAULT_FROM_EMAIL is not set.\"),\n            hint=_(\"DEFAULT_FROM_EMAIL is used in all outgoing Pootle email.\\n\"\n                   \"Don't forget to review your mail server settings.\"),\n            id=\"pootle.W009\",\n        ))\n\n    if settings.DEFAULT_FROM_EMAIL in (\"info@YOUR_DOMAIN.com\",\n                                       \"webmaster@localhost\"):\n        errors.append(checks.Warning(\n            _(\"DEFAULT_FROM_EMAIL is using the following default \"\n              \"setting %r.\" % settings.DEFAULT_FROM_EMAIL),\n            hint=_(\"DEFAULT_FROM_EMAIL is used in all outgoing Pootle email.\\n\"\n                   \"Don't forget to review your mail server settings.\"),\n            id=\"pootle.W010\",\n        ))\n\n    try:\n        markup_filter, markup_kwargs = settings.POOTLE_MARKUP_FILTER\n    except AttributeError:\n        errors.append(checks.Warning(\n            _(\"POOTLE_MARKUP_FILTER is missing.\"),\n            hint=_(\"Set POOTLE_MARKUP_FILTER.\"),\n            id=\"pootle.W012\",\n        ))\n    except (IndexError, TypeError, ValueError):\n        errors.append(checks.Warning(\n            _(\"Invalid value in POOTLE_MARKUP_FILTER.\"),\n            hint=_(\"Set a valid value for POOTLE_MARKUP_FILTER.\"),\n            id=\"pootle.W013\",\n        ))\n    else:\n        if markup_filter is not None:\n            try:\n                if markup_filter == 'textile':\n                    import textile\n                elif markup_filter == 'markdown':\n                    import markdown\n                elif markup_filter == 'restructuredtext':\n                    import docutils\n                else:\n                    errors.append(checks.Warning(\n                        _(\"Invalid markup in POOTLE_MARKUP_FILTER.\"),\n                        hint=_(\"Set a valid markup for POOTLE_MARKUP_FILTER.\"),\n                        id=\"pootle.W014\",\n                    ))\n            except ImportError:\n                errors.append(checks.Warning(\n                    _(\"POOTLE_MARKUP_FILTER is set to '%s' markup, but the \"\n                      \"package that provides can't be found.\" % markup_filter),\n                    hint=_(\"Install the package or change \"\n                           \"POOTLE_MARKUP_FILTER.\"),\n                    id=\"pootle.W015\",\n                ))\n\n    return errors\n\n\n@checks.register()\ndef check_users(app_configs=None, **kwargs):\n    from django.contrib.auth import get_user_model\n    from django.db import ProgrammingError\n    from django.db.utils import OperationalError\n\n    errors = []\n\n    User = get_user_model()\n    try:\n        admin_user = User.objects.get(username='admin')\n    except (User.DoesNotExist, OperationalError, ProgrammingError):\n        pass\n    else:\n        if admin_user.check_password('admin'):\n            errors.append(checks.Warning(\n                _(\"The default 'admin' user still has a password set to \"\n                  \"'admin'.\"),\n                hint=_(\"Remove the 'admin' user or change its password.\"),\n                id=\"pootle.W016\",\n            ))\n\n    return errors\n\n\n@checks.register()\ndef check_db_transaction_on_commit(app_configs=None, **kwargs):\n    from django.db import connection\n    errors = []\n    try:\n        on_commit = connection.on_commit\n    except AttributeError:\n        errors.append(checks.Critical(\n            _(\"Database connection does not implement on_commit.\"),\n            hint=_(\"Set the DATABASES['default']['ENGINE'] to use a backend \"\n                   \"from transaction_hooks.backends.\"),\n            id=\"pootle.C006\",\n        ))\n    return errors\n", "path": "pootle/checks.py"}], "after_files": [{"content": "#!/usr/bin/env python\n# -*- coding: utf-8 -*-\n#\n# Copyright (C) Pootle contributors.\n#\n# This file is a part of the Pootle project. It is distributed under the GPL3\n# or later license. See the LICENSE file for a copy of the license and the\n# AUTHORS file for copyright and authorship information.\n\nfrom django.core import checks\nfrom django.utils.translation import ugettext as _\n\n\n# Minimum Translate Toolkit version required for Pootle to run.\nTTK_MINIMUM_REQUIRED_VERSION = (1, 13, 0)\n\n# Minimum Django version required for Pootle to run.\nDJANGO_MINIMUM_REQUIRED_VERSION = (1, 7, 10)\n\n# Minimum lxml version required for Pootle to run.\nLXML_MINIMUM_REQUIRED_VERSION = (2, 2, 2, 0)\n\n# Minimum Redis server version required.\n# Initially set to some minimums based on:\n# 1. Ubuntu 12.04LTS's version 2.8.4 (10.04LTS was too old for RQ)\n# 2. RQ requires >= 2.6.0, and\n# 3. Wanting to insist on at least the latest stable that devs are using i.e.\n#    2.8.* versions of Redis\nREDIS_MINIMUM_REQUIRED_VERSION = (2, 8, 4)\n\n\n# XXX List of manage.py commands not to run the rqworker check on.\n# Maybe tagging can improve this?\nRQWORKER_WHITELIST = [\n    \"start\", \"initdb\", \"revision\", \"sync_stores\", \"run_cherrypy\",\n    \"refresh_stats\", \"update_stores\", \"calculate_checks\", \"retry_failed_jobs\",\n    \"check\", \"runserver\",\n]\n\n\ndef _version_to_string(version, significance=None):\n    if significance is not None:\n        version = version[significance:]\n    return '.'.join(str(n) for n in version)\n\n\n@checks.register()\ndef check_library_versions(app_configs=None, **kwargs):\n    from django import VERSION as django_version\n    from lxml.etree import LXML_VERSION as lxml_version\n    from translate.__version__ import ver as ttk_version\n\n    errors = []\n\n    if django_version < DJANGO_MINIMUM_REQUIRED_VERSION:\n        errors.append(checks.Critical(\n            _(\"Your version of Django is too old.\"),\n            hint=_(\"Try pip install --upgrade 'Django==%s'\" %\n                   _version_to_string(DJANGO_MINIMUM_REQUIRED_VERSION)),\n            id=\"pootle.C002\",\n        ))\n\n    if lxml_version < LXML_MINIMUM_REQUIRED_VERSION:\n        errors.append(checks.Warning(\n            _(\"Your version of lxml is too old.\"),\n            hint=_(\"Try pip install --upgrade lxml\"),\n            id=\"pootle.W003\",\n        ))\n\n    if ttk_version < TTK_MINIMUM_REQUIRED_VERSION:\n        errors.append(checks.Critical(\n            _(\"Your version of Translate Toolkit is too old.\"),\n            hint=_(\"Try pip install --upgrade translate-toolkit\"),\n            id=\"pootle.C003\",\n        ))\n\n    return errors\n\n\n@checks.register()\ndef check_redis(app_configs=None, **kwargs):\n    from django_rq.queues import get_queue\n    from django_rq.workers import Worker\n\n    errors = []\n\n    try:\n        queue = get_queue()\n        workers = Worker.all(queue.connection)\n    except Exception as e:\n        conn_settings = queue.connection.connection_pool.connection_kwargs\n        errors.append(checks.Critical(_(\"Could not connect to Redis (%s)\") % (e),\n            hint=_(\"Make sure Redis is running on %(host)s:%(port)s\") % (conn_settings),\n            id=\"pootle.C001\",\n        ))\n    else:\n        redis_version = tuple(int(x) for x\n                              in (queue.connection\n                                       .info()[\"redis_version\"].split(\".\")))\n        if redis_version < REDIS_MINIMUM_REQUIRED_VERSION:\n            errors.append(checks.Critical(\n                _(\"Your version of Redis is too old.\"),\n                hint=_(\"Update your system's Redis server package to at least \"\n                       \"version %s\" % str(REDIS_MINIMUM_REQUIRED_VERSION)),\n                id=\"pootle.C007\",\n            ))\n\n        if len(queue.connection.smembers(Worker.redis_workers_keys)) == 0:\n            # We need to check we're not running manage.py rqworker right now..\n            import sys\n            if len(sys.argv) > 1 and sys.argv[1] in RQWORKER_WHITELIST:\n                errors.append(checks.Warning(\n                    _(\"No RQ Worker running.\"),\n                    hint=_(\"Run new workers with manage.py rqworker\"),\n                    id=\"pootle.W001\",\n                ))\n\n    return errors\n\n\n@checks.register()\ndef check_settings(app_configs=None, **kwargs):\n    from django.conf import settings\n\n    errors = []\n\n    if \"RedisCache\" not in settings.CACHES.get(\"default\", {}).get(\"BACKEND\"):\n        errors.append(checks.Critical(\n            _(\"Cache backend is not set to Redis.\"),\n            hint=_(\"Set default cache backend to django_redis.cache.RedisCache\\n\"\n                   \"Current settings: %r\") % (settings.CACHES.get(\"default\")),\n            id=\"pootle.C005\",\n        ))\n    else:\n        from django_redis import get_redis_connection\n\n        if not get_redis_connection():\n            errors.append(checks.Critical(\n                _(\"Could not initiate a Redis cache connection\"),\n                hint=_(\"Double-check your CACHES settings\"),\n                id=\"pootle.C004\",\n            ))\n\n    if settings.DEBUG:\n        errors.append(checks.Warning(\n            _(\"DEBUG mode is on. Do not do this in production!\"),\n            hint=_(\"Set DEBUG = False in Pootle settings\"),\n            id=\"pootle.W005\"\n        ))\n    elif \"sqlite\" in settings.DATABASES.get(\"default\", {}).get(\"ENGINE\"):\n        # We don't bother warning about sqlite in DEBUG mode.\n        errors.append(checks.Warning(\n            _(\"The sqlite database backend is unsupported\"),\n            hint=_(\"Set your default database engine to postgresql_psycopg2 or mysql\"),\n            id=\"pootle.W006\",\n        ))\n\n    if settings.SESSION_ENGINE.split(\".\")[-1] not in (\"cache\", \"cached_db\"):\n        errors.append(checks.Warning(\n            _(\"Not using cached_db as session engine\"),\n            hint=_(\"Set SESSION_ENGINE to django.contrib.sessions.backend.cached_db\\n\"\n                   \"Current settings: %r\") % (settings.SESSION_ENGINE),\n            id=\"pootle.W007\",\n        ))\n\n    if not settings.POOTLE_CONTACT_EMAIL and settings.POOTLE_CONTACT_ENABLED:\n        errors.append(checks.Warning(\n            _(\"POOTLE_CONTACT_EMAIL is not set.\"),\n            hint=_(\"Set POOTLE_CONTACT_EMAIL to allow users to contact \"\n                   \"administrators through the Pootle contact form.\"),\n            id=\"pootle.W008\",\n        ))\n\n    if settings.POOTLE_CONTACT_EMAIL in (\"info@YOUR_DOMAIN.com\") \\\n       and settings.POOTLE_CONTACT_ENABLED:\n        errors.append(checks.Warning(\n            _(\"POOTLE_CONTACT_EMAIL is using the following default \"\n              \"setting %r.\" % settings.POOTLE_CONTACT_EMAIL),\n            hint=_(\"POOTLE_CONTACT_EMAIL is the address that will receive \"\n                   \"messages sent by the contact form.\"),\n            id=\"pootle.W011\",\n        ))\n\n    if not settings.DEFAULT_FROM_EMAIL:\n        errors.append(checks.Warning(\n            _(\"DEFAULT_FROM_EMAIL is not set.\"),\n            hint=_(\"DEFAULT_FROM_EMAIL is used in all outgoing Pootle email.\\n\"\n                   \"Don't forget to review your mail server settings.\"),\n            id=\"pootle.W009\",\n        ))\n\n    if settings.DEFAULT_FROM_EMAIL in (\"info@YOUR_DOMAIN.com\",\n                                       \"webmaster@localhost\"):\n        errors.append(checks.Warning(\n            _(\"DEFAULT_FROM_EMAIL is using the following default \"\n              \"setting %r.\" % settings.DEFAULT_FROM_EMAIL),\n            hint=_(\"DEFAULT_FROM_EMAIL is used in all outgoing Pootle email.\\n\"\n                   \"Don't forget to review your mail server settings.\"),\n            id=\"pootle.W010\",\n        ))\n\n    try:\n        markup_filter, markup_kwargs = settings.POOTLE_MARKUP_FILTER\n    except AttributeError:\n        errors.append(checks.Warning(\n            _(\"POOTLE_MARKUP_FILTER is missing.\"),\n            hint=_(\"Set POOTLE_MARKUP_FILTER.\"),\n            id=\"pootle.W012\",\n        ))\n    except (IndexError, TypeError, ValueError):\n        errors.append(checks.Warning(\n            _(\"Invalid value in POOTLE_MARKUP_FILTER.\"),\n            hint=_(\"Set a valid value for POOTLE_MARKUP_FILTER.\"),\n            id=\"pootle.W013\",\n        ))\n    else:\n        if markup_filter is not None:\n            try:\n                if markup_filter == 'textile':\n                    import textile\n                elif markup_filter == 'markdown':\n                    import markdown\n                elif markup_filter == 'restructuredtext':\n                    import docutils\n                else:\n                    errors.append(checks.Warning(\n                        _(\"Invalid markup in POOTLE_MARKUP_FILTER.\"),\n                        hint=_(\"Set a valid markup for POOTLE_MARKUP_FILTER.\"),\n                        id=\"pootle.W014\",\n                    ))\n            except ImportError:\n                errors.append(checks.Warning(\n                    _(\"POOTLE_MARKUP_FILTER is set to '%s' markup, but the \"\n                      \"package that provides can't be found.\" % markup_filter),\n                    hint=_(\"Install the package or change \"\n                           \"POOTLE_MARKUP_FILTER.\"),\n                    id=\"pootle.W015\",\n                ))\n\n    return errors\n\n\n@checks.register()\ndef check_users(app_configs=None, **kwargs):\n    from django.contrib.auth import get_user_model\n    from django.db import ProgrammingError\n    from django.db.utils import OperationalError\n\n    errors = []\n\n    User = get_user_model()\n    try:\n        admin_user = User.objects.get(username='admin')\n    except (User.DoesNotExist, OperationalError, ProgrammingError):\n        pass\n    else:\n        if admin_user.check_password('admin'):\n            errors.append(checks.Warning(\n                _(\"The default 'admin' user still has a password set to \"\n                  \"'admin'.\"),\n                hint=_(\"Remove the 'admin' user or change its password.\"),\n                id=\"pootle.W016\",\n            ))\n\n    return errors\n\n\n@checks.register()\ndef check_db_transaction_on_commit(app_configs=None, **kwargs):\n    from django.db import connection\n    errors = []\n    try:\n        on_commit = connection.on_commit\n    except AttributeError:\n        errors.append(checks.Critical(\n            _(\"Database connection does not implement on_commit.\"),\n            hint=_(\"Set the DATABASES['default']['ENGINE'] to use a backend \"\n                   \"from transaction_hooks.backends.\"),\n            id=\"pootle.C006\",\n        ))\n    return errors\n", "path": "pootle/checks.py"}]}