Revision 795e2ab33b1c27d8ad63ff5aac797389e696d655 authored by Antoine R. Dumont (@ardumont) on 04 December 2017, 17:59:50 UTC, committed by Antoine R. Dumont (@ardumont) on 04 December 2017, 17:59:50 UTC
2 parent s 85257e6 + ef1d0ba
Raw File
manage.py
#!/usr/bin/env python3

# Copyright (C) 2017  The Software Heritage developers
# See the AUTHORS file at the top-level directory of this distribution
# License: GNU General Public License version 3, or any later version
# See top-level LICENSE file for more information

import os
import sys

from swh.core import config


DEFAULT_CONFIG = {
    'port': ('int', 5006),
    'host': ('str', '127.0.0.1'),
}


if __name__ == "__main__":
    settings_file = 'development'
    if sys.argv[1] == 'runserver':  # override the default host:port
                                    # for the 'runserver' task

        conf = config.load_named_config('deposit/server',
                                        default_conf=DEFAULT_CONFIG)
        extra_cmd = ['%s:%s' % (conf['host'], conf['port'])]
        cmd = sys.argv + extra_cmd
    elif sys.argv[1] == 'test':     # override the default settings file
                                    # to read in testing mode
        settings_file = 'testing'
        cmd = sys.argv
    else:  # otherwise, do nothing
        cmd = sys.argv

    os.environ.setdefault('DJANGO_SETTINGS_MODULE',
                          'swh.deposit.settings.%s' % settings_file)

    try:
        from django.core.management import execute_from_command_line
    except ImportError:
        # The above import may fail for some other reason. Ensure that the
        # issue is really that Django is missing to avoid masking other
        # exceptions on Python 2.
        try:
            import django  # noqa
        except ImportError:
            raise ImportError(
                "Couldn't import Django. Are you sure it's installed and "
                "available on your PYTHONPATH environment variable? Did you "
                "forget to activate a virtual environment?"
            )
        raise
    execute_from_command_line(cmd)
back to top