def run(self, open_browser=False, open_data_dir=False):
        self.migrate()
        if self.to_migrate:
            self.migrate()
        if open_browser:

            def check_thread():
                import urllib.request

                while (not urllib.request.urlopen("http://localhost:{}".format(
                        plug_in_django_manage.CONFIG.get(
                            "django_settings", "port",
                            default=8000))).getcode() == 200):
                    time.sleep(200)
                import webbrowser

                webbrowser.open(
                    "http://localhost:{}".format(
                        plug_in_django_manage.CONFIG.get("django_settings",
                                                         "port",
                                                         default=8000)),
                    new=2,
                )

            import threading

            threading.Thread(target=check_thread).start()
        if open_data_dir:
            import webbrowser

            if sys.platform == "darwin":
                webbrowser.open(self.BASE_DIR)
            elif sys.platform == "linux2":
                webbrowser.open(self.BASE_DIR)
            elif sys.platform == "win32":
                webbrowser.open(self.BASE_DIR)
            else:
                webbrowser.open(self.BASE_DIR)
        plug_in_django_manage.run(
            sys.argv[0],
            "runserver",
            "--noreload",
            "0.0.0.0:" + str(
                plug_in_django_manage.CONFIG.get(
                    "django_settings", "port", default=8000)),
        )
def main():
    os.makedirs(BASE_DIR, exist_ok=True)
    config = JsonDict(os.path.join(BASE_DIR, SNAKE_NAME + "_config.json"))

    logging_fmt = (
        "%(asctime)s %(filename)s %(lineno)d %(name)s %(levelname)-8s  %(message)s"
    )
    logging.basicConfig(
        level=config.get(
            "basic",
            "logging",
            "level",
            default=logging.DEBUG if DEBUGGING else logging.INFO,
        ),
        format=logging_fmt,
        datefmt="(%H:%M:%S)",
    )

    rotating_handler = RotatingFileHandler(
        os.path.join(BASE_DIR, "log.log"),
        maxBytes=config.get("basic", "logging", "max_bytes", default=2 ** 19),
        backupCount=config.get("basic", "logging", "backup_count", default=10),
    )
    rotating_handler.setFormatter(logging.Formatter(logging_fmt))
    logging.getLogger("").addHandler(rotating_handler)

    logger = logging.getLogger(BASENAME)

    coloredlogs.install(level="DEBUG", fmt=logging_fmt)

    logger.info("Use basedir: " + os.path.abspath(BASE_DIR))

    #    board_collection.

    # plugin to django
    plug_in_django_manage.plug_in(DjangoArduinoControllerConfig, config)

    plug_in_django_manage.CONFIG.put("django_settings", "apps", "channels", value=True)

    # set site parameters
    plug_in_django_manage.CONFIG.put("public", "site", "title", value=BASENAME)
    plug_in_django_manage.CONFIG.put("django_settings", "DEBUG", value=DEBUGGING)
    plug_in_django_manage.CONFIG.put("django_settings", "BASE_DIR", value=BASE_DIR)

    # login required
    plug_in_django_manage.CONFIG.put(
        "django_settings",
        "manual",
        "add_to_list",
        "MIDDLEWARE",
        value=[
            #     "global_login_required.GlobalLoginRequiredMiddleware"
        ],
    )
    # if login is required accounds neet to be public
    plug_in_django_manage.CONFIG.put(
        "django_settings",
        "manual",
        "add_to_list",
        "PUBLIC_PATHS",
        value=[r"^/accounts/.*"],
    )

    plug_in_django_manage.run(
        sys.argv[0],
        "runserver",
        "--noreload",
        "0.0.0.0:"
        + str(
            plug_in_django_manage.CONFIG.get("django_settings", "port", default=8000)
        ),
    )
 def migrate(self):
     plug_in_django_manage.run(sys.argv[0], "makemigrations")
     plug_in_django_manage.run(sys.argv[0], "migrate")