We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
update_stores and sync_stores should produce an error if the project doesn't exist
If a non-existent project is passed to `update_stores` or `sync_stores` there is no output. I would expect an error:

```
# pootle update_stores --project=nonexistent-project
# pootle sync_stores --project=nonexistent-project
#
```

--- 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/apps/pootle_app/management/commands/set_filetype.py`
Content:
```
1 # -*- coding: utf-8 -*-
2 #
3 # Copyright (C) Pootle contributors.
4 #
5 # This file is a part of the Pootle project. It is distributed under the GPL3
6 # or later license. See the LICENSE file for a copy of the license and the
7 # AUTHORS file for copyright and authorship information.
8 
9 import os
10 
11 os.environ['DJANGO_SETTINGS_MODULE'] = 'pootle.settings'
12 
13 from django.core.management.base import CommandError
14 
15 from pootle_format.models import Format
16 from pootle_project.models import Project
17 
18 from . import PootleCommand
19 
20 
21 class Command(PootleCommand):
22     help = "Manage Store formats."
23 
24     def add_arguments(self, parser):
25         super(Command, self).add_arguments(parser)
26         parser.add_argument(
27             'filetype',
28             action='store',
29             help="File type to set")
30         parser.add_argument(
31             '--from-filetype',
32             action='store',
33             help="Only convert Stores of this file type")
34         parser.add_argument(
35             '--matching',
36             action='store',
37             help="Glob match Store path excluding extension")
38 
39     def get_projects(self):
40         if not self.projects:
41             return Project.objects.all()
42         projects = []
43         for project in self.projects:
44             # ensure all projects are valid before proceeding
45             try:
46                 projects.append(Project.objects.get(code=project))
47             except Project.DoesNotExist:
48                 raise CommandError("Unrecognized project '%s'" % project)
49         return projects
50 
51     def get_filetype(self, name):
52         try:
53             return Format.objects.get(name=name)
54         except Format.DoesNotExist:
55             raise CommandError("Unrecognized filetype '%s'" % name)
56 
57     def handle_all(self, **options):
58         filetype = self.get_filetype(options["filetype"])
59         from_filetype = (
60             options["from_filetype"]
61             and self.get_filetype(options["from_filetype"])
62             or None)
63         for project in self.get_projects():
64             # add the filetype to project, and convert the stores
65             project.filetype_tool.add_filetype(filetype)
66             project.filetype_tool.set_filetypes(
67                 filetype,
68                 from_filetype=from_filetype,
69                 matching=options["matching"])
70
```

Path: `pootle/apps/pootle_app/management/commands/__init__.py`
Content:
```
1 # -*- coding: utf-8 -*-
2 #
3 # Copyright (C) Pootle contributors.
4 #
5 # This file is a part of the Pootle project. It is distributed under the GPL3
6 # or later license. See the LICENSE file for a copy of the license and the
7 # AUTHORS file for copyright and authorship information.
8 
9 import datetime
10 import logging
11 
12 from django.core.management.base import BaseCommand, CommandError
13 
14 from pootle.runner import set_sync_mode
15 from pootle_project.models import Project
16 
17 
18 class SkipChecksMixin(object):
19     def check(self, app_configs=None, tags=None, display_num_errors=False,
20               include_deployment_checks=False):
21         skip_tags = getattr(self, 'skip_system_check_tags', None)
22         if skip_tags is not None:
23             from django.core.checks.registry import registry
24             tags = registry.tags_available() - set(skip_tags)
25 
26         super(SkipChecksMixin, self).check(
27             app_configs=app_configs,
28             tags=tags,
29             display_num_errors=display_num_errors,
30             include_deployment_checks=include_deployment_checks)
31 
32 
33 class PootleCommand(BaseCommand):
34     """Base class for handling recursive pootle store management commands."""
35 
36     process_disabled_projects = False
37 
38     def add_arguments(self, parser):
39         parser.add_argument(
40             '--project',
41             action='append',
42             dest='projects',
43             help='Project to refresh',
44         )
45         parser.add_argument(
46             '--language',
47             action='append',
48             dest='languages',
49             help='Language to refresh',
50         )
51         parser.add_argument(
52             "--noinput",
53             action="store_true",
54             default=False,
55             help=u"Never prompt for input",
56         )
57         parser.add_argument(
58             "--no-rq",
59             action="store_true",
60             default=False,
61             help=(u"Run all jobs in a single process, without "
62                   "using rq workers"),
63         )
64 
65     def __init__(self, *args, **kwargs):
66         self.languages = []
67         self.projects = []
68         super(PootleCommand, self).__init__(*args, **kwargs)
69 
70     def do_translation_project(self, tp, **options):
71         if hasattr(self, "handle_translation_project"):
72             logging.info(u"Running %s over %s", self.name, tp)
73             if not self.handle_translation_project(tp, **options):
74                 return
75         if hasattr(self, "handle_all_stores"):
76             logging.info(u"Running %s over %s's files", self.name, tp)
77             self.handle_all_stores(tp, **options)
78         elif hasattr(self, "handle_store"):
79             store_query = tp.stores.live()
80             for store in store_query.iterator():
81                 logging.info(u"Running %s over %s",
82                              self.name, store.pootle_path)
83                 self.handle_store(store, **options)
84 
85     def handle(self, **options):
86         # adjust debug level to the verbosity option
87         debug_levels = {
88             0: logging.ERROR,
89             1: logging.WARNING,
90             2: logging.INFO,
91             3: logging.DEBUG
92         }
93         logging.getLogger().setLevel(
94             debug_levels.get(options['verbosity'], logging.DEBUG)
95         )
96 
97         # reduce size of parse pool early on
98         self.name = self.__class__.__module__.split('.')[-1]
99         from pootle_store.fields import TranslationStoreFieldFile
100         TranslationStoreFieldFile._store_cache.maxsize = 2
101         TranslationStoreFieldFile._store_cache.cullsize = 2
102 
103         self.projects = options.pop('projects', [])
104         self.languages = options.pop('languages', [])
105 
106         # info start
107         start = datetime.datetime.now()
108         logging.info('Start running of %s', self.name)
109 
110         try:
111             self.handle_all(**options)
112         except Exception as e:
113             raise CommandError(e)
114 
115         # info finish
116         end = datetime.datetime.now()
117         logging.info('All done for %s in %s', self.name, end - start)
118 
119     def handle_all(self, **options):
120         if options["no_rq"]:
121             set_sync_mode(options['noinput'])
122 
123         if self.process_disabled_projects:
124             project_query = Project.objects.all()
125         else:
126             project_query = Project.objects.enabled()
127 
128         if self.projects:
129             project_query = project_query.filter(code__in=self.projects)
130 
131         for project in project_query.iterator():
132             tp_query = project.translationproject_set.live() \
133                               .order_by('language__code')
134 
135             if self.languages:
136                 tp_query = tp_query.filter(language__code__in=self.languages)
137 
138             for tp in tp_query.iterator():
139                 self.do_translation_project(tp, **options)
140
```
--- 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/apps/pootle_app/management/commands/__init__.py b/pootle/apps/pootle_app/management/commands/__init__.py
--- a/pootle/apps/pootle_app/management/commands/__init__.py
+++ b/pootle/apps/pootle_app/management/commands/__init__.py
@@ -12,6 +12,7 @@
 from django.core.management.base import BaseCommand, CommandError
 
 from pootle.runner import set_sync_mode
+from pootle_language.models import Language
 from pootle_project.models import Project
 
 
@@ -82,6 +83,26 @@
                              self.name, store.pootle_path)
                 self.handle_store(store, **options)
 
+    def check_projects(self, project_codes):
+        existing_projects = Project.objects.filter(
+            code__in=project_codes
+        ).values_list("code", flat=True)
+        if len(existing_projects) != len(project_codes):
+            unrecognized_projects = list(set(project_codes) -
+                                         set(existing_projects))
+            raise CommandError("Unrecognized projects: %s" %
+                               unrecognized_projects)
+
+    def check_languages(self, language_codes):
+        existing_languages = Language.objects.filter(
+            code__in=language_codes
+        ).values_list("code", flat=True)
+        if len(existing_languages) != len(language_codes):
+            unrecognized_languages = list(set(language_codes) -
+                                          set(existing_languages))
+            raise CommandError("Unrecognized languages: %s" %
+                               unrecognized_languages)
+
     def handle(self, **options):
         # adjust debug level to the verbosity option
         debug_levels = {
@@ -102,6 +123,10 @@
 
         self.projects = options.pop('projects', [])
         self.languages = options.pop('languages', [])
+        if self.projects:
+            self.check_projects(self.projects)
+        if self.languages:
+            self.check_languages(self.languages)
 
         # info start
         start = datetime.datetime.now()
diff --git a/pootle/apps/pootle_app/management/commands/set_filetype.py b/pootle/apps/pootle_app/management/commands/set_filetype.py
--- a/pootle/apps/pootle_app/management/commands/set_filetype.py
+++ b/pootle/apps/pootle_app/management/commands/set_filetype.py
@@ -39,14 +39,8 @@
     def get_projects(self):
         if not self.projects:
             return Project.objects.all()
-        projects = []
-        for project in self.projects:
-            # ensure all projects are valid before proceeding
-            try:
-                projects.append(Project.objects.get(code=project))
-            except Project.DoesNotExist:
-                raise CommandError("Unrecognized project '%s'" % project)
-        return projects
+
+        return Project.objects.filter(code__in=self.projects)
 
     def get_filetype(self, name):
         try:

{"golden_diff": "diff --git a/pootle/apps/pootle_app/management/commands/__init__.py b/pootle/apps/pootle_app/management/commands/__init__.py\n--- a/pootle/apps/pootle_app/management/commands/__init__.py\n+++ b/pootle/apps/pootle_app/management/commands/__init__.py\n@@ -12,6 +12,7 @@\n from django.core.management.base import BaseCommand, CommandError\n \n from pootle.runner import set_sync_mode\n+from pootle_language.models import Language\n from pootle_project.models import Project\n \n \n@@ -82,6 +83,26 @@\n                              self.name, store.pootle_path)\n                 self.handle_store(store, **options)\n \n+    def check_projects(self, project_codes):\n+        existing_projects = Project.objects.filter(\n+            code__in=project_codes\n+        ).values_list(\"code\", flat=True)\n+        if len(existing_projects) != len(project_codes):\n+            unrecognized_projects = list(set(project_codes) -\n+                                         set(existing_projects))\n+            raise CommandError(\"Unrecognized projects: %s\" %\n+                               unrecognized_projects)\n+\n+    def check_languages(self, language_codes):\n+        existing_languages = Language.objects.filter(\n+            code__in=language_codes\n+        ).values_list(\"code\", flat=True)\n+        if len(existing_languages) != len(language_codes):\n+            unrecognized_languages = list(set(language_codes) -\n+                                          set(existing_languages))\n+            raise CommandError(\"Unrecognized languages: %s\" %\n+                               unrecognized_languages)\n+\n     def handle(self, **options):\n         # adjust debug level to the verbosity option\n         debug_levels = {\n@@ -102,6 +123,10 @@\n \n         self.projects = options.pop('projects', [])\n         self.languages = options.pop('languages', [])\n+        if self.projects:\n+            self.check_projects(self.projects)\n+        if self.languages:\n+            self.check_languages(self.languages)\n \n         # info start\n         start = datetime.datetime.now()\ndiff --git a/pootle/apps/pootle_app/management/commands/set_filetype.py b/pootle/apps/pootle_app/management/commands/set_filetype.py\n--- a/pootle/apps/pootle_app/management/commands/set_filetype.py\n+++ b/pootle/apps/pootle_app/management/commands/set_filetype.py\n@@ -39,14 +39,8 @@\n     def get_projects(self):\n         if not self.projects:\n             return Project.objects.all()\n-        projects = []\n-        for project in self.projects:\n-            # ensure all projects are valid before proceeding\n-            try:\n-                projects.append(Project.objects.get(code=project))\n-            except Project.DoesNotExist:\n-                raise CommandError(\"Unrecognized project '%s'\" % project)\n-        return projects\n+\n+        return Project.objects.filter(code__in=self.projects)\n \n     def get_filetype(self, name):\n         try:\n", "issue": "update_stores and sync_stores should produce an error if the project doesn't exist\nIf a non-existent project is passed to `update_stores` or `sync_stores` there is no output. I would expect an error:\r\n\r\n```\r\n# pootle update_stores --project=nonexistent-project\r\n# pootle sync_stores --project=nonexistent-project\r\n#\r\n```\n", "before_files": [{"content": "# -*- 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\nimport os\n\nos.environ['DJANGO_SETTINGS_MODULE'] = 'pootle.settings'\n\nfrom django.core.management.base import CommandError\n\nfrom pootle_format.models import Format\nfrom pootle_project.models import Project\n\nfrom . import PootleCommand\n\n\nclass Command(PootleCommand):\n    help = \"Manage Store formats.\"\n\n    def add_arguments(self, parser):\n        super(Command, self).add_arguments(parser)\n        parser.add_argument(\n            'filetype',\n            action='store',\n            help=\"File type to set\")\n        parser.add_argument(\n            '--from-filetype',\n            action='store',\n            help=\"Only convert Stores of this file type\")\n        parser.add_argument(\n            '--matching',\n            action='store',\n            help=\"Glob match Store path excluding extension\")\n\n    def get_projects(self):\n        if not self.projects:\n            return Project.objects.all()\n        projects = []\n        for project in self.projects:\n            # ensure all projects are valid before proceeding\n            try:\n                projects.append(Project.objects.get(code=project))\n            except Project.DoesNotExist:\n                raise CommandError(\"Unrecognized project '%s'\" % project)\n        return projects\n\n    def get_filetype(self, name):\n        try:\n            return Format.objects.get(name=name)\n        except Format.DoesNotExist:\n            raise CommandError(\"Unrecognized filetype '%s'\" % name)\n\n    def handle_all(self, **options):\n        filetype = self.get_filetype(options[\"filetype\"])\n        from_filetype = (\n            options[\"from_filetype\"]\n            and self.get_filetype(options[\"from_filetype\"])\n            or None)\n        for project in self.get_projects():\n            # add the filetype to project, and convert the stores\n            project.filetype_tool.add_filetype(filetype)\n            project.filetype_tool.set_filetypes(\n                filetype,\n                from_filetype=from_filetype,\n                matching=options[\"matching\"])\n", "path": "pootle/apps/pootle_app/management/commands/set_filetype.py"}, {"content": "# -*- 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\nimport datetime\nimport logging\n\nfrom django.core.management.base import BaseCommand, CommandError\n\nfrom pootle.runner import set_sync_mode\nfrom pootle_project.models import Project\n\n\nclass SkipChecksMixin(object):\n    def check(self, app_configs=None, tags=None, display_num_errors=False,\n              include_deployment_checks=False):\n        skip_tags = getattr(self, 'skip_system_check_tags', None)\n        if skip_tags is not None:\n            from django.core.checks.registry import registry\n            tags = registry.tags_available() - set(skip_tags)\n\n        super(SkipChecksMixin, self).check(\n            app_configs=app_configs,\n            tags=tags,\n            display_num_errors=display_num_errors,\n            include_deployment_checks=include_deployment_checks)\n\n\nclass PootleCommand(BaseCommand):\n    \"\"\"Base class for handling recursive pootle store management commands.\"\"\"\n\n    process_disabled_projects = False\n\n    def add_arguments(self, parser):\n        parser.add_argument(\n            '--project',\n            action='append',\n            dest='projects',\n            help='Project to refresh',\n        )\n        parser.add_argument(\n            '--language',\n            action='append',\n            dest='languages',\n            help='Language to refresh',\n        )\n        parser.add_argument(\n            \"--noinput\",\n            action=\"store_true\",\n            default=False,\n            help=u\"Never prompt for input\",\n        )\n        parser.add_argument(\n            \"--no-rq\",\n            action=\"store_true\",\n            default=False,\n            help=(u\"Run all jobs in a single process, without \"\n                  \"using rq workers\"),\n        )\n\n    def __init__(self, *args, **kwargs):\n        self.languages = []\n        self.projects = []\n        super(PootleCommand, self).__init__(*args, **kwargs)\n\n    def do_translation_project(self, tp, **options):\n        if hasattr(self, \"handle_translation_project\"):\n            logging.info(u\"Running %s over %s\", self.name, tp)\n            if not self.handle_translation_project(tp, **options):\n                return\n        if hasattr(self, \"handle_all_stores\"):\n            logging.info(u\"Running %s over %s's files\", self.name, tp)\n            self.handle_all_stores(tp, **options)\n        elif hasattr(self, \"handle_store\"):\n            store_query = tp.stores.live()\n            for store in store_query.iterator():\n                logging.info(u\"Running %s over %s\",\n                             self.name, store.pootle_path)\n                self.handle_store(store, **options)\n\n    def handle(self, **options):\n        # adjust debug level to the verbosity option\n        debug_levels = {\n            0: logging.ERROR,\n            1: logging.WARNING,\n            2: logging.INFO,\n            3: logging.DEBUG\n        }\n        logging.getLogger().setLevel(\n            debug_levels.get(options['verbosity'], logging.DEBUG)\n        )\n\n        # reduce size of parse pool early on\n        self.name = self.__class__.__module__.split('.')[-1]\n        from pootle_store.fields import TranslationStoreFieldFile\n        TranslationStoreFieldFile._store_cache.maxsize = 2\n        TranslationStoreFieldFile._store_cache.cullsize = 2\n\n        self.projects = options.pop('projects', [])\n        self.languages = options.pop('languages', [])\n\n        # info start\n        start = datetime.datetime.now()\n        logging.info('Start running of %s', self.name)\n\n        try:\n            self.handle_all(**options)\n        except Exception as e:\n            raise CommandError(e)\n\n        # info finish\n        end = datetime.datetime.now()\n        logging.info('All done for %s in %s', self.name, end - start)\n\n    def handle_all(self, **options):\n        if options[\"no_rq\"]:\n            set_sync_mode(options['noinput'])\n\n        if self.process_disabled_projects:\n            project_query = Project.objects.all()\n        else:\n            project_query = Project.objects.enabled()\n\n        if self.projects:\n            project_query = project_query.filter(code__in=self.projects)\n\n        for project in project_query.iterator():\n            tp_query = project.translationproject_set.live() \\\n                              .order_by('language__code')\n\n            if self.languages:\n                tp_query = tp_query.filter(language__code__in=self.languages)\n\n            for tp in tp_query.iterator():\n                self.do_translation_project(tp, **options)\n", "path": "pootle/apps/pootle_app/management/commands/__init__.py"}], "after_files": [{"content": "# -*- 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\nimport os\n\nos.environ['DJANGO_SETTINGS_MODULE'] = 'pootle.settings'\n\nfrom django.core.management.base import CommandError\n\nfrom pootle_format.models import Format\nfrom pootle_project.models import Project\n\nfrom . import PootleCommand\n\n\nclass Command(PootleCommand):\n    help = \"Manage Store formats.\"\n\n    def add_arguments(self, parser):\n        super(Command, self).add_arguments(parser)\n        parser.add_argument(\n            'filetype',\n            action='store',\n            help=\"File type to set\")\n        parser.add_argument(\n            '--from-filetype',\n            action='store',\n            help=\"Only convert Stores of this file type\")\n        parser.add_argument(\n            '--matching',\n            action='store',\n            help=\"Glob match Store path excluding extension\")\n\n    def get_projects(self):\n        if not self.projects:\n            return Project.objects.all()\n\n        return Project.objects.filter(code__in=self.projects)\n\n    def get_filetype(self, name):\n        try:\n            return Format.objects.get(name=name)\n        except Format.DoesNotExist:\n            raise CommandError(\"Unrecognized filetype '%s'\" % name)\n\n    def handle_all(self, **options):\n        filetype = self.get_filetype(options[\"filetype\"])\n        from_filetype = (\n            options[\"from_filetype\"]\n            and self.get_filetype(options[\"from_filetype\"])\n            or None)\n        for project in self.get_projects():\n            # add the filetype to project, and convert the stores\n            project.filetype_tool.add_filetype(filetype)\n            project.filetype_tool.set_filetypes(\n                filetype,\n                from_filetype=from_filetype,\n                matching=options[\"matching\"])\n", "path": "pootle/apps/pootle_app/management/commands/set_filetype.py"}, {"content": "# -*- 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\nimport datetime\nimport logging\n\nfrom django.core.management.base import BaseCommand, CommandError\n\nfrom pootle.runner import set_sync_mode\nfrom pootle_language.models import Language\nfrom pootle_project.models import Project\n\n\nclass SkipChecksMixin(object):\n    def check(self, app_configs=None, tags=None, display_num_errors=False,\n              include_deployment_checks=False):\n        skip_tags = getattr(self, 'skip_system_check_tags', None)\n        if skip_tags is not None:\n            from django.core.checks.registry import registry\n            tags = registry.tags_available() - set(skip_tags)\n\n        super(SkipChecksMixin, self).check(\n            app_configs=app_configs,\n            tags=tags,\n            display_num_errors=display_num_errors,\n            include_deployment_checks=include_deployment_checks)\n\n\nclass PootleCommand(BaseCommand):\n    \"\"\"Base class for handling recursive pootle store management commands.\"\"\"\n\n    process_disabled_projects = False\n\n    def add_arguments(self, parser):\n        parser.add_argument(\n            '--project',\n            action='append',\n            dest='projects',\n            help='Project to refresh',\n        )\n        parser.add_argument(\n            '--language',\n            action='append',\n            dest='languages',\n            help='Language to refresh',\n        )\n        parser.add_argument(\n            \"--noinput\",\n            action=\"store_true\",\n            default=False,\n            help=u\"Never prompt for input\",\n        )\n        parser.add_argument(\n            \"--no-rq\",\n            action=\"store_true\",\n            default=False,\n            help=(u\"Run all jobs in a single process, without \"\n                  \"using rq workers\"),\n        )\n\n    def __init__(self, *args, **kwargs):\n        self.languages = []\n        self.projects = []\n        super(PootleCommand, self).__init__(*args, **kwargs)\n\n    def do_translation_project(self, tp, **options):\n        if hasattr(self, \"handle_translation_project\"):\n            logging.info(u\"Running %s over %s\", self.name, tp)\n            if not self.handle_translation_project(tp, **options):\n                return\n        if hasattr(self, \"handle_all_stores\"):\n            logging.info(u\"Running %s over %s's files\", self.name, tp)\n            self.handle_all_stores(tp, **options)\n        elif hasattr(self, \"handle_store\"):\n            store_query = tp.stores.live()\n            for store in store_query.iterator():\n                logging.info(u\"Running %s over %s\",\n                             self.name, store.pootle_path)\n                self.handle_store(store, **options)\n\n    def check_projects(self, project_codes):\n        existing_projects = Project.objects.filter(\n            code__in=project_codes\n        ).values_list(\"code\", flat=True)\n        if len(existing_projects) != len(project_codes):\n            unrecognized_projects = list(set(project_codes) -\n                                         set(existing_projects))\n            raise CommandError(\"Unrecognized projects: %s\" %\n                               unrecognized_projects)\n\n    def check_languages(self, language_codes):\n        existing_languages = Language.objects.filter(\n            code__in=language_codes\n        ).values_list(\"code\", flat=True)\n        if len(existing_languages) != len(language_codes):\n            unrecognized_languages = list(set(language_codes) -\n                                          set(existing_languages))\n            raise CommandError(\"Unrecognized languages: %s\" %\n                               unrecognized_languages)\n\n    def handle(self, **options):\n        # adjust debug level to the verbosity option\n        debug_levels = {\n            0: logging.ERROR,\n            1: logging.WARNING,\n            2: logging.INFO,\n            3: logging.DEBUG\n        }\n        logging.getLogger().setLevel(\n            debug_levels.get(options['verbosity'], logging.DEBUG)\n        )\n\n        # reduce size of parse pool early on\n        self.name = self.__class__.__module__.split('.')[-1]\n        from pootle_store.fields import TranslationStoreFieldFile\n        TranslationStoreFieldFile._store_cache.maxsize = 2\n        TranslationStoreFieldFile._store_cache.cullsize = 2\n\n        self.projects = options.pop('projects', [])\n        self.languages = options.pop('languages', [])\n        if self.projects:\n            self.check_projects(self.projects)\n        if self.languages:\n            self.check_languages(self.languages)\n\n        # info start\n        start = datetime.datetime.now()\n        logging.info('Start running of %s', self.name)\n\n        try:\n            self.handle_all(**options)\n        except Exception as e:\n            raise CommandError(e)\n\n        # info finish\n        end = datetime.datetime.now()\n        logging.info('All done for %s in %s', self.name, end - start)\n\n    def handle_all(self, **options):\n        if options[\"no_rq\"]:\n            set_sync_mode(options['noinput'])\n\n        if self.process_disabled_projects:\n            project_query = Project.objects.all()\n        else:\n            project_query = Project.objects.enabled()\n\n        if self.projects:\n            project_query = project_query.filter(code__in=self.projects)\n\n        for project in project_query.iterator():\n            tp_query = project.translationproject_set.live() \\\n                              .order_by('language__code')\n\n            if self.languages:\n                tp_query = tp_query.filter(language__code__in=self.languages)\n\n            for tp in tp_query.iterator():\n                self.do_translation_project(tp, **options)\n", "path": "pootle/apps/pootle_app/management/commands/__init__.py"}]}