We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
updated default kinto config breaks docker (kinto server not reacheable from host)
In e4e70fb, the default listen ip has been changed to 127.0.0.1.
I couldn't manage to export the port using docker, using this command from the [install documentation](http://kinto.readthedocs.io/en/latest/tutorials/install.html#environment-variables):
```
docker run --env-file kinto.env --link kinto_db:db -p 127.0.0.1:8888:8888 --name kinto_web croco/kinto:latest
```
For instance, when I do `curl http://127.0.0.1:8888` from the host I get `Recv failure: Connection reset by peer`.

When I reverted kinto.ini to listen on 0.0.0.0, curl from the host succeeds.

Maybe there is an environment variable to override the `host` entry in the `server:main` section? Then it would be fine, provided an updated documentation...

This is not visible with the published kinto/kinto-server image, since it's still 5.1. I built my own from master because I needed an armhf image.

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `kinto/config/__init__.py`
Content:
```
1 import os
2 import codecs
3 from time import strftime
4 
5 from kinto.core import utils as core_utils
6 
7 from kinto import logger
8 from kinto import __version__
9 
10 HERE = os.path.abspath(os.path.dirname(__file__))
11 
12 
13 def render_template(template, destination, **kwargs):
14     template = os.path.join(HERE, template)
15     folder = os.path.dirname(destination)
16 
17     if folder and not os.path.exists(folder):
18         os.makedirs(folder)
19 
20     logger.info("Created config {}".format(os.path.abspath(destination)))
21 
22     with codecs.open(template, 'r', encoding='utf-8') as f:
23         raw_template = f.read()
24         rendered = raw_template.format(**kwargs)
25         with codecs.open(destination, 'w+', encoding='utf-8') as output:
26             output.write(rendered)
27 
28 
29 def init(config_file, backend):
30     values = {}
31 
32     values['secret'] = core_utils.random_bytes_hex(32)
33 
34     values['kinto_version'] = __version__
35     values['config_file_timestamp'] = core_utils._encoded(
36         strftime('%a, %d %b %Y %H:%M:%S %z'))
37 
38     values['storage_backend'] = "kinto.core.storage.%s" % backend
39     values['cache_backend'] = "kinto.core.cache.%s" % backend
40     values['permission_backend'] = "kinto.core.permission.%s" % backend
41 
42     if backend == 'postgresql':
43         postgresql_url = "postgres://postgres:postgres@localhost/postgres"
44         values['storage_url'] = postgresql_url
45         values['cache_url'] = postgresql_url
46         values['permission_url'] = postgresql_url
47 
48     elif backend == 'redis':
49         redis_url = "redis://localhost:6379"
50         values['storage_backend'] = "kinto_redis.storage"
51         values['cache_backend'] = "kinto_redis.cache"
52         values['permission_backend'] = "kinto_redis.permission"
53 
54         values['storage_url'] = redis_url + "/1"
55         values['cache_url'] = redis_url + "/2"
56         values['permission_url'] = redis_url + "/3"
57 
58     else:
59         values['storage_url'] = ''
60         values['cache_url'] = ''
61         values['permission_url'] = ''
62 
63     render_template("kinto.tpl", config_file, **values)
64
```

Path: `kinto/__main__.py`
Content:
```
1 from __future__ import print_function
2 import argparse
3 import os
4 import sys
5 import logging
6 import logging.config
7 from six.moves import input
8 
9 from kinto.core import scripts
10 from pyramid.scripts import pserve
11 from pyramid.paster import bootstrap
12 from kinto import __version__
13 from kinto.config import init
14 
15 DEFAULT_CONFIG_FILE = 'config/kinto.ini'
16 DEFAULT_PORT = 8888
17 DEFAULT_LOG_LEVEL = logging.INFO
18 DEFAULT_LOG_FORMAT = "%(levelname)-5.5s  %(message)s"
19 
20 
21 def main(args=None):
22     """The main routine."""
23     if args is None:
24         args = sys.argv[1:]
25 
26     parser = argparse.ArgumentParser(description="Kinto Command-Line "
27                                                  "Interface")
28     # XXX: deprecate this option, unnatural as first argument.
29     parser.add_argument('--ini',
30                         help='Application configuration file',
31                         dest='ini_file',
32                         required=False,
33                         default=DEFAULT_CONFIG_FILE)
34 
35     parser.add_argument('-q', '--quiet', action='store_const',
36                         const=logging.CRITICAL, dest='verbosity',
37                         help='Show only critical errors.')
38 
39     parser.add_argument('--debug', action='store_const',
40                         const=logging.DEBUG, dest='verbosity',
41                         help='Show all messages, including debug messages.')
42 
43     commands = ('init', 'start', 'migrate', 'delete-collection', 'version')
44     subparsers = parser.add_subparsers(title='subcommands',
45                                        description='Main Kinto CLI commands',
46                                        dest='subcommand',
47                                        help="Choose and run with --help")
48     subparsers.required = True
49 
50     for command in commands:
51         subparser = subparsers.add_parser(command)
52         subparser.set_defaults(which=command)
53 
54         if command == 'init':
55             subparser.add_argument('--backend',
56                                    help='{memory,redis,postgresql}',
57                                    dest='backend',
58                                    required=False,
59                                    default=None)
60         elif command == 'migrate':
61             subparser.add_argument('--dry-run',
62                                    action='store_true',
63                                    help='Simulate the migration operations '
64                                         'and show information',
65                                    dest='dry_run',
66                                    required=False,
67                                    default=False)
68         elif command == 'delete-collection':
69             subparser.add_argument('--bucket',
70                                    help='The bucket where the collection '
71                                         'belongs to.',
72                                    required=True)
73             subparser.add_argument('--collection',
74                                    help='The collection to remove.',
75                                    required=True)
76 
77         elif command == 'start':
78             subparser.add_argument('--reload',
79                                    action='store_true',
80                                    help='Restart when code or config changes',
81                                    required=False,
82                                    default=False)
83             subparser.add_argument('--port',
84                                    type=int,
85                                    help='Listening port number',
86                                    required=False,
87                                    default=DEFAULT_PORT)
88 
89     # Parse command-line arguments
90     parsed_args = vars(parser.parse_args(args))
91 
92     config_file = parsed_args['ini_file']
93     which_command = parsed_args['which']
94 
95     # Initialize logging from
96     level = parsed_args.get('verbosity') or DEFAULT_LOG_LEVEL
97     logging.basicConfig(level=level, format=DEFAULT_LOG_FORMAT)
98 
99     if which_command == 'init':
100         if os.path.exists(config_file):
101             print("%s already exists." % config_file, file=sys.stderr)
102             return 1
103 
104         backend = parsed_args['backend']
105         if not backend:
106             while True:
107                 prompt = ("Select the backend you would like to use: "
108                           "(1 - postgresql, 2 - redis, default - memory) ")
109                 answer = input(prompt).strip()
110                 try:
111                     backends = {"1": "postgresql", "2": "redis", "": "memory"}
112                     backend = backends[answer]
113                     break
114                 except KeyError:
115                     pass
116 
117         init(config_file, backend)
118 
119         # Install postgresql libraries if necessary
120         if backend == "postgresql":
121             try:
122                 import psycopg2  # NOQA
123             except ImportError:
124                 import pip
125                 pip.main(['install', "kinto[postgresql]"])
126         elif backend == "redis":
127             try:
128                 import kinto_redis  # NOQA
129             except ImportError:
130                 import pip
131                 pip.main(['install', "kinto[redis]"])
132 
133     elif which_command == 'migrate':
134         dry_run = parsed_args['dry_run']
135         env = bootstrap(config_file)
136         scripts.migrate(env, dry_run=dry_run)
137 
138     elif which_command == 'delete-collection':
139         env = bootstrap(config_file)
140         return scripts.delete_collection(env,
141                                          parsed_args['bucket'],
142                                          parsed_args['collection'])
143 
144     elif which_command == 'start':
145         pserve_argv = ['pserve', config_file]
146         if parsed_args['reload']:
147             pserve_argv.append('--reload')
148         pserve_argv.append('http_port=%s' % parsed_args['port'])
149         pserve.main(pserve_argv)
150 
151     elif which_command == 'version':
152         print(__version__)
153 
154     return 0
155
```
--- 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/kinto/__main__.py b/kinto/__main__.py
--- a/kinto/__main__.py
+++ b/kinto/__main__.py
@@ -57,6 +57,11 @@
                                    dest='backend',
                                    required=False,
                                    default=None)
+            subparser.add_argument('--host',
+                                   help='Host to listen() on.',
+                                   dest='host',
+                                   required=False,
+                                   default='127.0.0.1')
         elif command == 'migrate':
             subparser.add_argument('--dry-run',
                                    action='store_true',
@@ -114,7 +119,7 @@
                 except KeyError:
                     pass
 
-        init(config_file, backend)
+        init(config_file, backend, parsed_args['host'])
 
         # Install postgresql libraries if necessary
         if backend == "postgresql":
diff --git a/kinto/config/__init__.py b/kinto/config/__init__.py
--- a/kinto/config/__init__.py
+++ b/kinto/config/__init__.py
@@ -26,9 +26,10 @@
             output.write(rendered)
 
 
-def init(config_file, backend):
+def init(config_file, backend, host='127.0.0.1'):
     values = {}
 
+    values['host'] = host
     values['secret'] = core_utils.random_bytes_hex(32)
 
     values['kinto_version'] = __version__

{"golden_diff": "diff --git a/kinto/__main__.py b/kinto/__main__.py\n--- a/kinto/__main__.py\n+++ b/kinto/__main__.py\n@@ -57,6 +57,11 @@\n                                    dest='backend',\n                                    required=False,\n                                    default=None)\n+            subparser.add_argument('--host',\n+                                   help='Host to listen() on.',\n+                                   dest='host',\n+                                   required=False,\n+                                   default='127.0.0.1')\n         elif command == 'migrate':\n             subparser.add_argument('--dry-run',\n                                    action='store_true',\n@@ -114,7 +119,7 @@\n                 except KeyError:\n                     pass\n \n-        init(config_file, backend)\n+        init(config_file, backend, parsed_args['host'])\n \n         # Install postgresql libraries if necessary\n         if backend == \"postgresql\":\ndiff --git a/kinto/config/__init__.py b/kinto/config/__init__.py\n--- a/kinto/config/__init__.py\n+++ b/kinto/config/__init__.py\n@@ -26,9 +26,10 @@\n             output.write(rendered)\n \n \n-def init(config_file, backend):\n+def init(config_file, backend, host='127.0.0.1'):\n     values = {}\n \n+    values['host'] = host\n     values['secret'] = core_utils.random_bytes_hex(32)\n \n     values['kinto_version'] = __version__\n", "issue": "updated default kinto config breaks docker (kinto server not reacheable from host)\nIn e4e70fb, the default listen ip has been changed to 127.0.0.1.\r\nI couldn't manage to export the port using docker, using this command from the [install documentation](http://kinto.readthedocs.io/en/latest/tutorials/install.html#environment-variables):\r\n```\r\ndocker run --env-file kinto.env --link kinto_db:db -p 127.0.0.1:8888:8888 --name kinto_web croco/kinto:latest\r\n```\r\nFor instance, when I do `curl http://127.0.0.1:8888` from the host I get `Recv failure: Connection reset by peer`.\r\n\r\nWhen I reverted kinto.ini to listen on 0.0.0.0, curl from the host succeeds.\r\n\r\nMaybe there is an environment variable to override the `host` entry in the `server:main` section? Then it would be fine, provided an updated documentation...\r\n\r\nThis is not visible with the published kinto/kinto-server image, since it's still 5.1. I built my own from master because I needed an armhf image.\n", "before_files": [{"content": "import os\nimport codecs\nfrom time import strftime\n\nfrom kinto.core import utils as core_utils\n\nfrom kinto import logger\nfrom kinto import __version__\n\nHERE = os.path.abspath(os.path.dirname(__file__))\n\n\ndef render_template(template, destination, **kwargs):\n    template = os.path.join(HERE, template)\n    folder = os.path.dirname(destination)\n\n    if folder and not os.path.exists(folder):\n        os.makedirs(folder)\n\n    logger.info(\"Created config {}\".format(os.path.abspath(destination)))\n\n    with codecs.open(template, 'r', encoding='utf-8') as f:\n        raw_template = f.read()\n        rendered = raw_template.format(**kwargs)\n        with codecs.open(destination, 'w+', encoding='utf-8') as output:\n            output.write(rendered)\n\n\ndef init(config_file, backend):\n    values = {}\n\n    values['secret'] = core_utils.random_bytes_hex(32)\n\n    values['kinto_version'] = __version__\n    values['config_file_timestamp'] = core_utils._encoded(\n        strftime('%a, %d %b %Y %H:%M:%S %z'))\n\n    values['storage_backend'] = \"kinto.core.storage.%s\" % backend\n    values['cache_backend'] = \"kinto.core.cache.%s\" % backend\n    values['permission_backend'] = \"kinto.core.permission.%s\" % backend\n\n    if backend == 'postgresql':\n        postgresql_url = \"postgres://postgres:postgres@localhost/postgres\"\n        values['storage_url'] = postgresql_url\n        values['cache_url'] = postgresql_url\n        values['permission_url'] = postgresql_url\n\n    elif backend == 'redis':\n        redis_url = \"redis://localhost:6379\"\n        values['storage_backend'] = \"kinto_redis.storage\"\n        values['cache_backend'] = \"kinto_redis.cache\"\n        values['permission_backend'] = \"kinto_redis.permission\"\n\n        values['storage_url'] = redis_url + \"/1\"\n        values['cache_url'] = redis_url + \"/2\"\n        values['permission_url'] = redis_url + \"/3\"\n\n    else:\n        values['storage_url'] = ''\n        values['cache_url'] = ''\n        values['permission_url'] = ''\n\n    render_template(\"kinto.tpl\", config_file, **values)\n", "path": "kinto/config/__init__.py"}, {"content": "from __future__ import print_function\nimport argparse\nimport os\nimport sys\nimport logging\nimport logging.config\nfrom six.moves import input\n\nfrom kinto.core import scripts\nfrom pyramid.scripts import pserve\nfrom pyramid.paster import bootstrap\nfrom kinto import __version__\nfrom kinto.config import init\n\nDEFAULT_CONFIG_FILE = 'config/kinto.ini'\nDEFAULT_PORT = 8888\nDEFAULT_LOG_LEVEL = logging.INFO\nDEFAULT_LOG_FORMAT = \"%(levelname)-5.5s  %(message)s\"\n\n\ndef main(args=None):\n    \"\"\"The main routine.\"\"\"\n    if args is None:\n        args = sys.argv[1:]\n\n    parser = argparse.ArgumentParser(description=\"Kinto Command-Line \"\n                                                 \"Interface\")\n    # XXX: deprecate this option, unnatural as first argument.\n    parser.add_argument('--ini',\n                        help='Application configuration file',\n                        dest='ini_file',\n                        required=False,\n                        default=DEFAULT_CONFIG_FILE)\n\n    parser.add_argument('-q', '--quiet', action='store_const',\n                        const=logging.CRITICAL, dest='verbosity',\n                        help='Show only critical errors.')\n\n    parser.add_argument('--debug', action='store_const',\n                        const=logging.DEBUG, dest='verbosity',\n                        help='Show all messages, including debug messages.')\n\n    commands = ('init', 'start', 'migrate', 'delete-collection', 'version')\n    subparsers = parser.add_subparsers(title='subcommands',\n                                       description='Main Kinto CLI commands',\n                                       dest='subcommand',\n                                       help=\"Choose and run with --help\")\n    subparsers.required = True\n\n    for command in commands:\n        subparser = subparsers.add_parser(command)\n        subparser.set_defaults(which=command)\n\n        if command == 'init':\n            subparser.add_argument('--backend',\n                                   help='{memory,redis,postgresql}',\n                                   dest='backend',\n                                   required=False,\n                                   default=None)\n        elif command == 'migrate':\n            subparser.add_argument('--dry-run',\n                                   action='store_true',\n                                   help='Simulate the migration operations '\n                                        'and show information',\n                                   dest='dry_run',\n                                   required=False,\n                                   default=False)\n        elif command == 'delete-collection':\n            subparser.add_argument('--bucket',\n                                   help='The bucket where the collection '\n                                        'belongs to.',\n                                   required=True)\n            subparser.add_argument('--collection',\n                                   help='The collection to remove.',\n                                   required=True)\n\n        elif command == 'start':\n            subparser.add_argument('--reload',\n                                   action='store_true',\n                                   help='Restart when code or config changes',\n                                   required=False,\n                                   default=False)\n            subparser.add_argument('--port',\n                                   type=int,\n                                   help='Listening port number',\n                                   required=False,\n                                   default=DEFAULT_PORT)\n\n    # Parse command-line arguments\n    parsed_args = vars(parser.parse_args(args))\n\n    config_file = parsed_args['ini_file']\n    which_command = parsed_args['which']\n\n    # Initialize logging from\n    level = parsed_args.get('verbosity') or DEFAULT_LOG_LEVEL\n    logging.basicConfig(level=level, format=DEFAULT_LOG_FORMAT)\n\n    if which_command == 'init':\n        if os.path.exists(config_file):\n            print(\"%s already exists.\" % config_file, file=sys.stderr)\n            return 1\n\n        backend = parsed_args['backend']\n        if not backend:\n            while True:\n                prompt = (\"Select the backend you would like to use: \"\n                          \"(1 - postgresql, 2 - redis, default - memory) \")\n                answer = input(prompt).strip()\n                try:\n                    backends = {\"1\": \"postgresql\", \"2\": \"redis\", \"\": \"memory\"}\n                    backend = backends[answer]\n                    break\n                except KeyError:\n                    pass\n\n        init(config_file, backend)\n\n        # Install postgresql libraries if necessary\n        if backend == \"postgresql\":\n            try:\n                import psycopg2  # NOQA\n            except ImportError:\n                import pip\n                pip.main(['install', \"kinto[postgresql]\"])\n        elif backend == \"redis\":\n            try:\n                import kinto_redis  # NOQA\n            except ImportError:\n                import pip\n                pip.main(['install', \"kinto[redis]\"])\n\n    elif which_command == 'migrate':\n        dry_run = parsed_args['dry_run']\n        env = bootstrap(config_file)\n        scripts.migrate(env, dry_run=dry_run)\n\n    elif which_command == 'delete-collection':\n        env = bootstrap(config_file)\n        return scripts.delete_collection(env,\n                                         parsed_args['bucket'],\n                                         parsed_args['collection'])\n\n    elif which_command == 'start':\n        pserve_argv = ['pserve', config_file]\n        if parsed_args['reload']:\n            pserve_argv.append('--reload')\n        pserve_argv.append('http_port=%s' % parsed_args['port'])\n        pserve.main(pserve_argv)\n\n    elif which_command == 'version':\n        print(__version__)\n\n    return 0\n", "path": "kinto/__main__.py"}], "after_files": [{"content": "import os\nimport codecs\nfrom time import strftime\n\nfrom kinto.core import utils as core_utils\n\nfrom kinto import logger\nfrom kinto import __version__\n\nHERE = os.path.abspath(os.path.dirname(__file__))\n\n\ndef render_template(template, destination, **kwargs):\n    template = os.path.join(HERE, template)\n    folder = os.path.dirname(destination)\n\n    if folder and not os.path.exists(folder):\n        os.makedirs(folder)\n\n    logger.info(\"Created config {}\".format(os.path.abspath(destination)))\n\n    with codecs.open(template, 'r', encoding='utf-8') as f:\n        raw_template = f.read()\n        rendered = raw_template.format(**kwargs)\n        with codecs.open(destination, 'w+', encoding='utf-8') as output:\n            output.write(rendered)\n\n\ndef init(config_file, backend, host='127.0.0.1'):\n    values = {}\n\n    values['host'] = host\n    values['secret'] = core_utils.random_bytes_hex(32)\n\n    values['kinto_version'] = __version__\n    values['config_file_timestamp'] = core_utils._encoded(\n        strftime('%a, %d %b %Y %H:%M:%S %z'))\n\n    values['storage_backend'] = \"kinto.core.storage.%s\" % backend\n    values['cache_backend'] = \"kinto.core.cache.%s\" % backend\n    values['permission_backend'] = \"kinto.core.permission.%s\" % backend\n\n    if backend == 'postgresql':\n        postgresql_url = \"postgres://postgres:postgres@localhost/postgres\"\n        values['storage_url'] = postgresql_url\n        values['cache_url'] = postgresql_url\n        values['permission_url'] = postgresql_url\n\n    elif backend == 'redis':\n        redis_url = \"redis://localhost:6379\"\n        values['storage_backend'] = \"kinto_redis.storage\"\n        values['cache_backend'] = \"kinto_redis.cache\"\n        values['permission_backend'] = \"kinto_redis.permission\"\n\n        values['storage_url'] = redis_url + \"/1\"\n        values['cache_url'] = redis_url + \"/2\"\n        values['permission_url'] = redis_url + \"/3\"\n\n    else:\n        values['storage_url'] = ''\n        values['cache_url'] = ''\n        values['permission_url'] = ''\n\n    render_template(\"kinto.tpl\", config_file, **values)\n", "path": "kinto/config/__init__.py"}, {"content": "from __future__ import print_function\nimport argparse\nimport os\nimport sys\nimport logging\nimport logging.config\nfrom six.moves import input\n\nfrom kinto.core import scripts\nfrom pyramid.scripts import pserve\nfrom pyramid.paster import bootstrap\nfrom kinto import __version__\nfrom kinto.config import init\n\nDEFAULT_CONFIG_FILE = 'config/kinto.ini'\nDEFAULT_PORT = 8888\nDEFAULT_LOG_LEVEL = logging.INFO\nDEFAULT_LOG_FORMAT = \"%(levelname)-5.5s  %(message)s\"\n\n\ndef main(args=None):\n    \"\"\"The main routine.\"\"\"\n    if args is None:\n        args = sys.argv[1:]\n\n    parser = argparse.ArgumentParser(description=\"Kinto Command-Line \"\n                                                 \"Interface\")\n    # XXX: deprecate this option, unnatural as first argument.\n    parser.add_argument('--ini',\n                        help='Application configuration file',\n                        dest='ini_file',\n                        required=False,\n                        default=DEFAULT_CONFIG_FILE)\n\n    parser.add_argument('-q', '--quiet', action='store_const',\n                        const=logging.CRITICAL, dest='verbosity',\n                        help='Show only critical errors.')\n\n    parser.add_argument('--debug', action='store_const',\n                        const=logging.DEBUG, dest='verbosity',\n                        help='Show all messages, including debug messages.')\n\n    commands = ('init', 'start', 'migrate', 'delete-collection', 'version')\n    subparsers = parser.add_subparsers(title='subcommands',\n                                       description='Main Kinto CLI commands',\n                                       dest='subcommand',\n                                       help=\"Choose and run with --help\")\n    subparsers.required = True\n\n    for command in commands:\n        subparser = subparsers.add_parser(command)\n        subparser.set_defaults(which=command)\n\n        if command == 'init':\n            subparser.add_argument('--backend',\n                                   help='{memory,redis,postgresql}',\n                                   dest='backend',\n                                   required=False,\n                                   default=None)\n            subparser.add_argument('--host',\n                                   help='Host to listen() on.',\n                                   dest='host',\n                                   required=False,\n                                   default='127.0.0.1')\n        elif command == 'migrate':\n            subparser.add_argument('--dry-run',\n                                   action='store_true',\n                                   help='Simulate the migration operations '\n                                        'and show information',\n                                   dest='dry_run',\n                                   required=False,\n                                   default=False)\n        elif command == 'delete-collection':\n            subparser.add_argument('--bucket',\n                                   help='The bucket where the collection '\n                                        'belongs to.',\n                                   required=True)\n            subparser.add_argument('--collection',\n                                   help='The collection to remove.',\n                                   required=True)\n\n        elif command == 'start':\n            subparser.add_argument('--reload',\n                                   action='store_true',\n                                   help='Restart when code or config changes',\n                                   required=False,\n                                   default=False)\n            subparser.add_argument('--port',\n                                   type=int,\n                                   help='Listening port number',\n                                   required=False,\n                                   default=DEFAULT_PORT)\n\n    # Parse command-line arguments\n    parsed_args = vars(parser.parse_args(args))\n\n    config_file = parsed_args['ini_file']\n    which_command = parsed_args['which']\n\n    # Initialize logging from\n    level = parsed_args.get('verbosity') or DEFAULT_LOG_LEVEL\n    logging.basicConfig(level=level, format=DEFAULT_LOG_FORMAT)\n\n    if which_command == 'init':\n        if os.path.exists(config_file):\n            print(\"%s already exists.\" % config_file, file=sys.stderr)\n            return 1\n\n        backend = parsed_args['backend']\n        if not backend:\n            while True:\n                prompt = (\"Select the backend you would like to use: \"\n                          \"(1 - postgresql, 2 - redis, default - memory) \")\n                answer = input(prompt).strip()\n                try:\n                    backends = {\"1\": \"postgresql\", \"2\": \"redis\", \"\": \"memory\"}\n                    backend = backends[answer]\n                    break\n                except KeyError:\n                    pass\n\n        init(config_file, backend, parsed_args['host'])\n\n        # Install postgresql libraries if necessary\n        if backend == \"postgresql\":\n            try:\n                import psycopg2  # NOQA\n            except ImportError:\n                import pip\n                pip.main(['install', \"kinto[postgresql]\"])\n        elif backend == \"redis\":\n            try:\n                import kinto_redis  # NOQA\n            except ImportError:\n                import pip\n                pip.main(['install', \"kinto[redis]\"])\n\n    elif which_command == 'migrate':\n        dry_run = parsed_args['dry_run']\n        env = bootstrap(config_file)\n        scripts.migrate(env, dry_run=dry_run)\n\n    elif which_command == 'delete-collection':\n        env = bootstrap(config_file)\n        return scripts.delete_collection(env,\n                                         parsed_args['bucket'],\n                                         parsed_args['collection'])\n\n    elif which_command == 'start':\n        pserve_argv = ['pserve', config_file]\n        if parsed_args['reload']:\n            pserve_argv.append('--reload')\n        pserve_argv.append('http_port=%s' % parsed_args['port'])\n        pserve.main(pserve_argv)\n\n    elif which_command == 'version':\n        print(__version__)\n\n    return 0\n", "path": "kinto/__main__.py"}]}