We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
[BUG] invoke: too many arguments
When running any invoke-command in an WSL-Enviroment I get the following error:
`/bin/bash: line 0: cd: too many arguments`

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `tasks.py`
Content:
```
1 # -*- coding: utf-8 -*-
2 
3 from shutil import copyfile
4 import os
5 import json
6 import sys
7 
8 try:
9     from invoke import ctask as task
10 except:
11     from invoke import task
12 
13 
14 def apps():
15     """
16     Returns a list of installed apps
17     """
18 
19     return [
20         'barcode',
21         'build',
22         'common',
23         'company',
24         'label',
25         'order',
26         'part',
27         'report',
28         'stock',
29         'InvenTree',
30         'users',
31     ]
32 
33 
34 def localDir():
35     """
36     Returns the directory of *THIS* file.
37     Used to ensure that the various scripts always run
38     in the correct directory.
39     """
40     return os.path.dirname(os.path.abspath(__file__))
41 
42 
43 def managePyDir():
44     """
45     Returns the directory of the manage.py file
46     """
47 
48     return os.path.join(localDir(), 'InvenTree')
49 
50 
51 def managePyPath():
52     """
53     Return the path of the manage.py file
54     """
55 
56     return os.path.join(managePyDir(), 'manage.py')
57 
58 
59 def manage(c, cmd, pty=False):
60     """
61     Runs a given command against django's "manage.py" script.
62 
63     Args:
64         c - Command line context
65         cmd - django command to run
66     """
67 
68     c.run('cd {path} && python3 manage.py {cmd}'.format(
69         path=managePyDir(),
70         cmd=cmd
71     ), pty=pty)
72 
73 
74 @task
75 def install(c):
76     """
77     Installs required python packages
78     """
79 
80     # Install required Python packages with PIP
81     c.run('pip3 install -U -r requirements.txt')
82 
83     # If a config.yaml file does not exist, copy from the template!
84     CONFIG_FILE = os.path.join(localDir(), 'InvenTree', 'config.yaml')
85     CONFIG_TEMPLATE_FILE = os.path.join(localDir(), 'InvenTree', 'config_template.yaml')
86 
87     if not os.path.exists(CONFIG_FILE):
88         print("Config file 'config.yaml' does not exist - copying from template.")
89         copyfile(CONFIG_TEMPLATE_FILE, CONFIG_FILE)
90 
91 
92 @task
93 def shell(c):
94     """
95     Open a python shell with access to the InvenTree database models.
96     """
97 
98     manage(c, 'shell', pty=True)
99 
100 @task
101 def worker(c):
102     """
103     Run the InvenTree background worker process
104     """
105 
106     manage(c, 'qcluster', pty=True)
107 
108 @task
109 def superuser(c):
110     """
111     Create a superuser (admin) account for the database.
112     """
113 
114     manage(c, 'createsuperuser', pty=True)
115 
116 @task
117 def check(c):
118     """
119     Check validity of django codebase
120     """
121 
122     manage(c, "check")
123 
124 @task
125 def wait(c):
126     """
127     Wait until the database connection is ready
128     """
129 
130     manage(c, "wait_for_db")
131 
132 @task
133 def migrate(c):
134     """
135     Performs database migrations.
136     This is a critical step if the database schema have been altered!
137     """
138 
139     print("Running InvenTree database migrations...")
140     print("========================================")
141 
142     manage(c, "makemigrations")
143     manage(c, "migrate")
144     manage(c, "migrate --run-syncdb")
145     manage(c, "check")
146 
147     print("========================================")
148     print("InvenTree database migrations completed!")
149 
150 
151 @task
152 def static(c):
153     """
154     Copies required static files to the STATIC_ROOT directory,
155     as per Django requirements.
156     """
157 
158     manage(c, "prerender")
159     manage(c, "collectstatic --no-input")
160 
161 
162 @task(pre=[install, migrate, static])
163 def update(c):
164     """
165     Update InvenTree installation.
166 
167     This command should be invoked after source code has been updated,
168     e.g. downloading new code from GitHub.
169 
170     The following tasks are performed, in order:
171 
172     - install
173     - migrate
174     - static
175     """
176     pass
177 
178 @task(post=[static])
179 def translate(c):
180     """
181     Regenerate translation files.
182 
183     Run this command after added new translatable strings,
184     or after adding translations for existing strings.
185     """
186 
187     # Translate applicable .py / .html / .js files
188     manage(c, "makemessages --all -e py,html,js")
189     manage(c, "compilemessages")
190 
191     path = os.path.join('InvenTree', 'script', 'translation_stats.py')
192 
193     c.run(f'python {path}')
194 
195 @task
196 def style(c):
197     """
198     Run PEP style checks against InvenTree sourcecode
199     """
200 
201     print("Running PEP style checks...")
202     c.run('flake8 InvenTree')
203 
204 @task
205 def test(c, database=None):
206     """
207     Run unit-tests for InvenTree codebase.
208     """
209     # Run sanity check on the django install
210     manage(c, 'check')
211 
212     # Run coverage tests
213     manage(c, 'test', pty=True)
214 
215 @task
216 def coverage(c):
217     """
218     Run code-coverage of the InvenTree codebase,
219     using the 'coverage' code-analysis tools.
220 
221     Generates a code coverage report (available in the htmlcov directory)
222     """
223 
224     # Run sanity check on the django install
225     manage(c, 'check')
226 
227     # Run coverage tests
228     c.run('coverage run {manage} test {apps}'.format(
229         manage=managePyPath(),
230         apps=' '.join(apps())
231     ))
232 
233     # Generate coverage report
234     c.run('coverage html')
235 
236 
237 def content_excludes():
238     """
239     Returns a list of content types to exclude from import/export
240     """
241 
242     excludes = [
243         "contenttypes",
244         "sessions.session",
245         "auth.permission",
246         "error_report.error",
247         "admin.logentry",
248         "django_q.schedule",
249         "django_q.task",
250         "django_q.ormq",
251         "users.owner",
252     ]
253 
254     output = ""
255 
256     for e in excludes:
257         output += f"--exclude {e} "
258 
259     return output
260 
261 
262 @task(help={'filename': "Output filename (default = 'data.json')"})
263 def export_records(c, filename='data.json'):
264     """
265     Export all database records to a file
266     """
267 
268     # Get an absolute path to the file
269     if not os.path.isabs(filename):
270         filename = os.path.join(localDir(), filename)
271         filename = os.path.abspath(filename) 
272 
273     print(f"Exporting database records to file '{filename}'")
274 
275     if os.path.exists(filename):
276         response = input("Warning: file already exists. Do you want to overwrite? [y/N]: ")
277         response = str(response).strip().lower()
278 
279         if response not in ['y', 'yes']:
280             print("Cancelled export operation")
281             sys.exit(1)
282 
283     tmpfile = f"{filename}.tmp"
284 
285     cmd = f"dumpdata --indent 2 --output {tmpfile} {content_excludes()}"
286 
287     # Dump data to temporary file
288     manage(c, cmd, pty=True)
289 
290     print("Running data post-processing step...")
291 
292     # Post-process the file, to remove any "permissions" specified for a user or group
293     with open(tmpfile, "r") as f_in:
294         data = json.loads(f_in.read())
295 
296     for entry in data:
297         if "model" in entry:
298             
299             # Clear out any permissions specified for a group
300             if entry["model"] == "auth.group":
301                 entry["fields"]["permissions"] = []
302 
303             # Clear out any permissions specified for a user
304             if entry["model"] == "auth.user":
305                 entry["fields"]["user_permissions"] = []
306 
307     # Write the processed data to file
308     with open(filename, "w") as f_out:
309         f_out.write(json.dumps(data, indent=2))
310 
311     print("Data export completed")
312 
313 
314 @task(help={'filename': 'Input filename'})
315 def import_records(c, filename='data.json'):
316     """
317     Import database records from a file
318     """
319 
320     # Get an absolute path to the supplied filename
321     if not os.path.isabs(filename):
322         filename = os.path.join(localDir(), filename)
323 
324     if not os.path.exists(filename):
325         print(f"Error: File '{filename}' does not exist")
326         sys.exit(1)
327 
328     print(f"Importing database records from '{filename}'")
329 
330     # Pre-process the data, to remove any "permissions" specified for a user or group
331     tmpfile = f"{filename}.tmp.json"
332 
333     with open(filename, "r") as f_in:
334         data = json.loads(f_in.read())
335 
336     for entry in data:
337         if "model" in entry:
338             
339             # Clear out any permissions specified for a group
340             if entry["model"] == "auth.group":
341                 entry["fields"]["permissions"] = []
342 
343             # Clear out any permissions specified for a user
344             if entry["model"] == "auth.user":
345                 entry["fields"]["user_permissions"] = []
346 
347     # Write the processed data to the tmp file
348     with open(tmpfile, "w") as f_out:
349         f_out.write(json.dumps(data, indent=2))
350 
351     cmd = f"loaddata {tmpfile} -i {content_excludes()}"
352 
353     manage(c, cmd, pty=True)
354 
355     print("Data import completed")
356 
357 @task
358 def import_fixtures(c):
359     """
360     Import fixture data into the database.
361 
362     This command imports all existing test fixture data into the database.
363 
364     Warning:
365         - Intended for testing / development only!
366         - Running this command may overwrite existing database data!!
367         - Don't say you were not warned...
368     """
369 
370     fixtures = [
371         # Build model
372         'build',
373         
374         # Common models
375         'settings',
376 
377         # Company model
378         'company',
379         'price_breaks',
380         'supplier_part',
381 
382         # Order model
383         'order',
384 
385         # Part model
386         'bom',
387         'category',
388         'params',
389         'part',
390         'test_templates',
391 
392         # Stock model
393         'location',
394         'stock_tests',
395         'stock',
396 
397         # Users
398         'users'
399     ]
400 
401     command = 'loaddata ' + ' '.join(fixtures)
402 
403     manage(c, command, pty=True)
404 
405 
406 @task(help={'address': 'Server address:port (default=127.0.0.1:8000)'})
407 def server(c, address="127.0.0.1:8000"):
408     """
409     Launch a (deveopment) server using Django's in-built webserver.
410 
411     Note: This is *not* sufficient for a production installation.
412     """
413 
414     manage(c, "runserver {address}".format(address=address), pty=True)
415
```
--- 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/tasks.py b/tasks.py
--- a/tasks.py
+++ b/tasks.py
@@ -65,7 +65,7 @@
         cmd - django command to run
     """
 
-    c.run('cd {path} && python3 manage.py {cmd}'.format(
+    c.run('cd "{path}" && python3 manage.py {cmd}'.format(
         path=managePyDir(),
         cmd=cmd
     ), pty=pty)

{"golden_diff": "diff --git a/tasks.py b/tasks.py\n--- a/tasks.py\n+++ b/tasks.py\n@@ -65,7 +65,7 @@\n         cmd - django command to run\n     \"\"\"\n \n-    c.run('cd {path} && python3 manage.py {cmd}'.format(\n+    c.run('cd \"{path}\" && python3 manage.py {cmd}'.format(\n         path=managePyDir(),\n         cmd=cmd\n     ), pty=pty)\n", "issue": "[BUG] invoke: too many arguments\nWhen running any invoke-command in an WSL-Enviroment I get the following error:\r\n`/bin/bash: line 0: cd: too many arguments`\n", "before_files": [{"content": "# -*- coding: utf-8 -*-\n\nfrom shutil import copyfile\nimport os\nimport json\nimport sys\n\ntry:\n    from invoke import ctask as task\nexcept:\n    from invoke import task\n\n\ndef apps():\n    \"\"\"\n    Returns a list of installed apps\n    \"\"\"\n\n    return [\n        'barcode',\n        'build',\n        'common',\n        'company',\n        'label',\n        'order',\n        'part',\n        'report',\n        'stock',\n        'InvenTree',\n        'users',\n    ]\n\n\ndef localDir():\n    \"\"\"\n    Returns the directory of *THIS* file.\n    Used to ensure that the various scripts always run\n    in the correct directory.\n    \"\"\"\n    return os.path.dirname(os.path.abspath(__file__))\n\n\ndef managePyDir():\n    \"\"\"\n    Returns the directory of the manage.py file\n    \"\"\"\n\n    return os.path.join(localDir(), 'InvenTree')\n\n\ndef managePyPath():\n    \"\"\"\n    Return the path of the manage.py file\n    \"\"\"\n\n    return os.path.join(managePyDir(), 'manage.py')\n\n\ndef manage(c, cmd, pty=False):\n    \"\"\"\n    Runs a given command against django's \"manage.py\" script.\n\n    Args:\n        c - Command line context\n        cmd - django command to run\n    \"\"\"\n\n    c.run('cd {path} && python3 manage.py {cmd}'.format(\n        path=managePyDir(),\n        cmd=cmd\n    ), pty=pty)\n\n\n@task\ndef install(c):\n    \"\"\"\n    Installs required python packages\n    \"\"\"\n\n    # Install required Python packages with PIP\n    c.run('pip3 install -U -r requirements.txt')\n\n    # If a config.yaml file does not exist, copy from the template!\n    CONFIG_FILE = os.path.join(localDir(), 'InvenTree', 'config.yaml')\n    CONFIG_TEMPLATE_FILE = os.path.join(localDir(), 'InvenTree', 'config_template.yaml')\n\n    if not os.path.exists(CONFIG_FILE):\n        print(\"Config file 'config.yaml' does not exist - copying from template.\")\n        copyfile(CONFIG_TEMPLATE_FILE, CONFIG_FILE)\n\n\n@task\ndef shell(c):\n    \"\"\"\n    Open a python shell with access to the InvenTree database models.\n    \"\"\"\n\n    manage(c, 'shell', pty=True)\n\n@task\ndef worker(c):\n    \"\"\"\n    Run the InvenTree background worker process\n    \"\"\"\n\n    manage(c, 'qcluster', pty=True)\n\n@task\ndef superuser(c):\n    \"\"\"\n    Create a superuser (admin) account for the database.\n    \"\"\"\n\n    manage(c, 'createsuperuser', pty=True)\n\n@task\ndef check(c):\n    \"\"\"\n    Check validity of django codebase\n    \"\"\"\n\n    manage(c, \"check\")\n\n@task\ndef wait(c):\n    \"\"\"\n    Wait until the database connection is ready\n    \"\"\"\n\n    manage(c, \"wait_for_db\")\n\n@task\ndef migrate(c):\n    \"\"\"\n    Performs database migrations.\n    This is a critical step if the database schema have been altered!\n    \"\"\"\n\n    print(\"Running InvenTree database migrations...\")\n    print(\"========================================\")\n\n    manage(c, \"makemigrations\")\n    manage(c, \"migrate\")\n    manage(c, \"migrate --run-syncdb\")\n    manage(c, \"check\")\n\n    print(\"========================================\")\n    print(\"InvenTree database migrations completed!\")\n\n\n@task\ndef static(c):\n    \"\"\"\n    Copies required static files to the STATIC_ROOT directory,\n    as per Django requirements.\n    \"\"\"\n\n    manage(c, \"prerender\")\n    manage(c, \"collectstatic --no-input\")\n\n\n@task(pre=[install, migrate, static])\ndef update(c):\n    \"\"\"\n    Update InvenTree installation.\n\n    This command should be invoked after source code has been updated,\n    e.g. downloading new code from GitHub.\n\n    The following tasks are performed, in order:\n\n    - install\n    - migrate\n    - static\n    \"\"\"\n    pass\n\n@task(post=[static])\ndef translate(c):\n    \"\"\"\n    Regenerate translation files.\n\n    Run this command after added new translatable strings,\n    or after adding translations for existing strings.\n    \"\"\"\n\n    # Translate applicable .py / .html / .js files\n    manage(c, \"makemessages --all -e py,html,js\")\n    manage(c, \"compilemessages\")\n\n    path = os.path.join('InvenTree', 'script', 'translation_stats.py')\n\n    c.run(f'python {path}')\n\n@task\ndef style(c):\n    \"\"\"\n    Run PEP style checks against InvenTree sourcecode\n    \"\"\"\n\n    print(\"Running PEP style checks...\")\n    c.run('flake8 InvenTree')\n\n@task\ndef test(c, database=None):\n    \"\"\"\n    Run unit-tests for InvenTree codebase.\n    \"\"\"\n    # Run sanity check on the django install\n    manage(c, 'check')\n\n    # Run coverage tests\n    manage(c, 'test', pty=True)\n\n@task\ndef coverage(c):\n    \"\"\"\n    Run code-coverage of the InvenTree codebase,\n    using the 'coverage' code-analysis tools.\n\n    Generates a code coverage report (available in the htmlcov directory)\n    \"\"\"\n\n    # Run sanity check on the django install\n    manage(c, 'check')\n\n    # Run coverage tests\n    c.run('coverage run {manage} test {apps}'.format(\n        manage=managePyPath(),\n        apps=' '.join(apps())\n    ))\n\n    # Generate coverage report\n    c.run('coverage html')\n\n\ndef content_excludes():\n    \"\"\"\n    Returns a list of content types to exclude from import/export\n    \"\"\"\n\n    excludes = [\n        \"contenttypes\",\n        \"sessions.session\",\n        \"auth.permission\",\n        \"error_report.error\",\n        \"admin.logentry\",\n        \"django_q.schedule\",\n        \"django_q.task\",\n        \"django_q.ormq\",\n        \"users.owner\",\n    ]\n\n    output = \"\"\n\n    for e in excludes:\n        output += f\"--exclude {e} \"\n\n    return output\n\n\n@task(help={'filename': \"Output filename (default = 'data.json')\"})\ndef export_records(c, filename='data.json'):\n    \"\"\"\n    Export all database records to a file\n    \"\"\"\n\n    # Get an absolute path to the file\n    if not os.path.isabs(filename):\n        filename = os.path.join(localDir(), filename)\n        filename = os.path.abspath(filename) \n\n    print(f\"Exporting database records to file '{filename}'\")\n\n    if os.path.exists(filename):\n        response = input(\"Warning: file already exists. Do you want to overwrite? [y/N]: \")\n        response = str(response).strip().lower()\n\n        if response not in ['y', 'yes']:\n            print(\"Cancelled export operation\")\n            sys.exit(1)\n\n    tmpfile = f\"{filename}.tmp\"\n\n    cmd = f\"dumpdata --indent 2 --output {tmpfile} {content_excludes()}\"\n\n    # Dump data to temporary file\n    manage(c, cmd, pty=True)\n\n    print(\"Running data post-processing step...\")\n\n    # Post-process the file, to remove any \"permissions\" specified for a user or group\n    with open(tmpfile, \"r\") as f_in:\n        data = json.loads(f_in.read())\n\n    for entry in data:\n        if \"model\" in entry:\n            \n            # Clear out any permissions specified for a group\n            if entry[\"model\"] == \"auth.group\":\n                entry[\"fields\"][\"permissions\"] = []\n\n            # Clear out any permissions specified for a user\n            if entry[\"model\"] == \"auth.user\":\n                entry[\"fields\"][\"user_permissions\"] = []\n\n    # Write the processed data to file\n    with open(filename, \"w\") as f_out:\n        f_out.write(json.dumps(data, indent=2))\n\n    print(\"Data export completed\")\n\n\n@task(help={'filename': 'Input filename'})\ndef import_records(c, filename='data.json'):\n    \"\"\"\n    Import database records from a file\n    \"\"\"\n\n    # Get an absolute path to the supplied filename\n    if not os.path.isabs(filename):\n        filename = os.path.join(localDir(), filename)\n\n    if not os.path.exists(filename):\n        print(f\"Error: File '{filename}' does not exist\")\n        sys.exit(1)\n\n    print(f\"Importing database records from '{filename}'\")\n\n    # Pre-process the data, to remove any \"permissions\" specified for a user or group\n    tmpfile = f\"{filename}.tmp.json\"\n\n    with open(filename, \"r\") as f_in:\n        data = json.loads(f_in.read())\n\n    for entry in data:\n        if \"model\" in entry:\n            \n            # Clear out any permissions specified for a group\n            if entry[\"model\"] == \"auth.group\":\n                entry[\"fields\"][\"permissions\"] = []\n\n            # Clear out any permissions specified for a user\n            if entry[\"model\"] == \"auth.user\":\n                entry[\"fields\"][\"user_permissions\"] = []\n\n    # Write the processed data to the tmp file\n    with open(tmpfile, \"w\") as f_out:\n        f_out.write(json.dumps(data, indent=2))\n\n    cmd = f\"loaddata {tmpfile} -i {content_excludes()}\"\n\n    manage(c, cmd, pty=True)\n\n    print(\"Data import completed\")\n\n@task\ndef import_fixtures(c):\n    \"\"\"\n    Import fixture data into the database.\n\n    This command imports all existing test fixture data into the database.\n\n    Warning:\n        - Intended for testing / development only!\n        - Running this command may overwrite existing database data!!\n        - Don't say you were not warned...\n    \"\"\"\n\n    fixtures = [\n        # Build model\n        'build',\n        \n        # Common models\n        'settings',\n\n        # Company model\n        'company',\n        'price_breaks',\n        'supplier_part',\n\n        # Order model\n        'order',\n\n        # Part model\n        'bom',\n        'category',\n        'params',\n        'part',\n        'test_templates',\n\n        # Stock model\n        'location',\n        'stock_tests',\n        'stock',\n\n        # Users\n        'users'\n    ]\n\n    command = 'loaddata ' + ' '.join(fixtures)\n\n    manage(c, command, pty=True)\n\n\n@task(help={'address': 'Server address:port (default=127.0.0.1:8000)'})\ndef server(c, address=\"127.0.0.1:8000\"):\n    \"\"\"\n    Launch a (deveopment) server using Django's in-built webserver.\n\n    Note: This is *not* sufficient for a production installation.\n    \"\"\"\n\n    manage(c, \"runserver {address}\".format(address=address), pty=True)\n", "path": "tasks.py"}], "after_files": [{"content": "# -*- coding: utf-8 -*-\n\nfrom shutil import copyfile\nimport os\nimport json\nimport sys\n\ntry:\n    from invoke import ctask as task\nexcept:\n    from invoke import task\n\n\ndef apps():\n    \"\"\"\n    Returns a list of installed apps\n    \"\"\"\n\n    return [\n        'barcode',\n        'build',\n        'common',\n        'company',\n        'label',\n        'order',\n        'part',\n        'report',\n        'stock',\n        'InvenTree',\n        'users',\n    ]\n\n\ndef localDir():\n    \"\"\"\n    Returns the directory of *THIS* file.\n    Used to ensure that the various scripts always run\n    in the correct directory.\n    \"\"\"\n    return os.path.dirname(os.path.abspath(__file__))\n\n\ndef managePyDir():\n    \"\"\"\n    Returns the directory of the manage.py file\n    \"\"\"\n\n    return os.path.join(localDir(), 'InvenTree')\n\n\ndef managePyPath():\n    \"\"\"\n    Return the path of the manage.py file\n    \"\"\"\n\n    return os.path.join(managePyDir(), 'manage.py')\n\n\ndef manage(c, cmd, pty=False):\n    \"\"\"\n    Runs a given command against django's \"manage.py\" script.\n\n    Args:\n        c - Command line context\n        cmd - django command to run\n    \"\"\"\n\n    c.run('cd \"{path}\" && python3 manage.py {cmd}'.format(\n        path=managePyDir(),\n        cmd=cmd\n    ), pty=pty)\n\n\n@task\ndef install(c):\n    \"\"\"\n    Installs required python packages\n    \"\"\"\n\n    # Install required Python packages with PIP\n    c.run('pip3 install -U -r requirements.txt')\n\n    # If a config.yaml file does not exist, copy from the template!\n    CONFIG_FILE = os.path.join(localDir(), 'InvenTree', 'config.yaml')\n    CONFIG_TEMPLATE_FILE = os.path.join(localDir(), 'InvenTree', 'config_template.yaml')\n\n    if not os.path.exists(CONFIG_FILE):\n        print(\"Config file 'config.yaml' does not exist - copying from template.\")\n        copyfile(CONFIG_TEMPLATE_FILE, CONFIG_FILE)\n\n\n@task\ndef shell(c):\n    \"\"\"\n    Open a python shell with access to the InvenTree database models.\n    \"\"\"\n\n    manage(c, 'shell', pty=True)\n\n@task\ndef worker(c):\n    \"\"\"\n    Run the InvenTree background worker process\n    \"\"\"\n\n    manage(c, 'qcluster', pty=True)\n\n@task\ndef superuser(c):\n    \"\"\"\n    Create a superuser (admin) account for the database.\n    \"\"\"\n\n    manage(c, 'createsuperuser', pty=True)\n\n@task\ndef check(c):\n    \"\"\"\n    Check validity of django codebase\n    \"\"\"\n\n    manage(c, \"check\")\n\n@task\ndef wait(c):\n    \"\"\"\n    Wait until the database connection is ready\n    \"\"\"\n\n    manage(c, \"wait_for_db\")\n\n@task\ndef migrate(c):\n    \"\"\"\n    Performs database migrations.\n    This is a critical step if the database schema have been altered!\n    \"\"\"\n\n    print(\"Running InvenTree database migrations...\")\n    print(\"========================================\")\n\n    manage(c, \"makemigrations\")\n    manage(c, \"migrate\")\n    manage(c, \"migrate --run-syncdb\")\n    manage(c, \"check\")\n\n    print(\"========================================\")\n    print(\"InvenTree database migrations completed!\")\n\n\n@task\ndef static(c):\n    \"\"\"\n    Copies required static files to the STATIC_ROOT directory,\n    as per Django requirements.\n    \"\"\"\n\n    manage(c, \"prerender\")\n    manage(c, \"collectstatic --no-input\")\n\n\n@task(pre=[install, migrate, static])\ndef update(c):\n    \"\"\"\n    Update InvenTree installation.\n\n    This command should be invoked after source code has been updated,\n    e.g. downloading new code from GitHub.\n\n    The following tasks are performed, in order:\n\n    - install\n    - migrate\n    - static\n    \"\"\"\n    pass\n\n@task(post=[static])\ndef translate(c):\n    \"\"\"\n    Regenerate translation files.\n\n    Run this command after added new translatable strings,\n    or after adding translations for existing strings.\n    \"\"\"\n\n    # Translate applicable .py / .html / .js files\n    manage(c, \"makemessages --all -e py,html,js\")\n    manage(c, \"compilemessages\")\n\n    path = os.path.join('InvenTree', 'script', 'translation_stats.py')\n\n    c.run(f'python {path}')\n\n@task\ndef style(c):\n    \"\"\"\n    Run PEP style checks against InvenTree sourcecode\n    \"\"\"\n\n    print(\"Running PEP style checks...\")\n    c.run('flake8 InvenTree')\n\n@task\ndef test(c, database=None):\n    \"\"\"\n    Run unit-tests for InvenTree codebase.\n    \"\"\"\n    # Run sanity check on the django install\n    manage(c, 'check')\n\n    # Run coverage tests\n    manage(c, 'test', pty=True)\n\n@task\ndef coverage(c):\n    \"\"\"\n    Run code-coverage of the InvenTree codebase,\n    using the 'coverage' code-analysis tools.\n\n    Generates a code coverage report (available in the htmlcov directory)\n    \"\"\"\n\n    # Run sanity check on the django install\n    manage(c, 'check')\n\n    # Run coverage tests\n    c.run('coverage run {manage} test {apps}'.format(\n        manage=managePyPath(),\n        apps=' '.join(apps())\n    ))\n\n    # Generate coverage report\n    c.run('coverage html')\n\n\ndef content_excludes():\n    \"\"\"\n    Returns a list of content types to exclude from import/export\n    \"\"\"\n\n    excludes = [\n        \"contenttypes\",\n        \"sessions.session\",\n        \"auth.permission\",\n        \"error_report.error\",\n        \"admin.logentry\",\n        \"django_q.schedule\",\n        \"django_q.task\",\n        \"django_q.ormq\",\n        \"users.owner\",\n    ]\n\n    output = \"\"\n\n    for e in excludes:\n        output += f\"--exclude {e} \"\n\n    return output\n\n\n@task(help={'filename': \"Output filename (default = 'data.json')\"})\ndef export_records(c, filename='data.json'):\n    \"\"\"\n    Export all database records to a file\n    \"\"\"\n\n    # Get an absolute path to the file\n    if not os.path.isabs(filename):\n        filename = os.path.join(localDir(), filename)\n        filename = os.path.abspath(filename) \n\n    print(f\"Exporting database records to file '{filename}'\")\n\n    if os.path.exists(filename):\n        response = input(\"Warning: file already exists. Do you want to overwrite? [y/N]: \")\n        response = str(response).strip().lower()\n\n        if response not in ['y', 'yes']:\n            print(\"Cancelled export operation\")\n            sys.exit(1)\n\n    tmpfile = f\"{filename}.tmp\"\n\n    cmd = f\"dumpdata --indent 2 --output {tmpfile} {content_excludes()}\"\n\n    # Dump data to temporary file\n    manage(c, cmd, pty=True)\n\n    print(\"Running data post-processing step...\")\n\n    # Post-process the file, to remove any \"permissions\" specified for a user or group\n    with open(tmpfile, \"r\") as f_in:\n        data = json.loads(f_in.read())\n\n    for entry in data:\n        if \"model\" in entry:\n            \n            # Clear out any permissions specified for a group\n            if entry[\"model\"] == \"auth.group\":\n                entry[\"fields\"][\"permissions\"] = []\n\n            # Clear out any permissions specified for a user\n            if entry[\"model\"] == \"auth.user\":\n                entry[\"fields\"][\"user_permissions\"] = []\n\n    # Write the processed data to file\n    with open(filename, \"w\") as f_out:\n        f_out.write(json.dumps(data, indent=2))\n\n    print(\"Data export completed\")\n\n\n@task(help={'filename': 'Input filename'})\ndef import_records(c, filename='data.json'):\n    \"\"\"\n    Import database records from a file\n    \"\"\"\n\n    # Get an absolute path to the supplied filename\n    if not os.path.isabs(filename):\n        filename = os.path.join(localDir(), filename)\n\n    if not os.path.exists(filename):\n        print(f\"Error: File '{filename}' does not exist\")\n        sys.exit(1)\n\n    print(f\"Importing database records from '{filename}'\")\n\n    # Pre-process the data, to remove any \"permissions\" specified for a user or group\n    tmpfile = f\"{filename}.tmp.json\"\n\n    with open(filename, \"r\") as f_in:\n        data = json.loads(f_in.read())\n\n    for entry in data:\n        if \"model\" in entry:\n            \n            # Clear out any permissions specified for a group\n            if entry[\"model\"] == \"auth.group\":\n                entry[\"fields\"][\"permissions\"] = []\n\n            # Clear out any permissions specified for a user\n            if entry[\"model\"] == \"auth.user\":\n                entry[\"fields\"][\"user_permissions\"] = []\n\n    # Write the processed data to the tmp file\n    with open(tmpfile, \"w\") as f_out:\n        f_out.write(json.dumps(data, indent=2))\n\n    cmd = f\"loaddata {tmpfile} -i {content_excludes()}\"\n\n    manage(c, cmd, pty=True)\n\n    print(\"Data import completed\")\n\n@task\ndef import_fixtures(c):\n    \"\"\"\n    Import fixture data into the database.\n\n    This command imports all existing test fixture data into the database.\n\n    Warning:\n        - Intended for testing / development only!\n        - Running this command may overwrite existing database data!!\n        - Don't say you were not warned...\n    \"\"\"\n\n    fixtures = [\n        # Build model\n        'build',\n        \n        # Common models\n        'settings',\n\n        # Company model\n        'company',\n        'price_breaks',\n        'supplier_part',\n\n        # Order model\n        'order',\n\n        # Part model\n        'bom',\n        'category',\n        'params',\n        'part',\n        'test_templates',\n\n        # Stock model\n        'location',\n        'stock_tests',\n        'stock',\n\n        # Users\n        'users'\n    ]\n\n    command = 'loaddata ' + ' '.join(fixtures)\n\n    manage(c, command, pty=True)\n\n\n@task(help={'address': 'Server address:port (default=127.0.0.1:8000)'})\ndef server(c, address=\"127.0.0.1:8000\"):\n    \"\"\"\n    Launch a (deveopment) server using Django's in-built webserver.\n\n    Note: This is *not* sufficient for a production installation.\n    \"\"\"\n\n    manage(c, \"runserver {address}\".format(address=address), pty=True)\n", "path": "tasks.py"}]}