2015-06-16 10:37:23 +02:00
|
|
|
import argparse
|
2013-10-13 17:17:56 +02:00
|
|
|
import ctypes
|
2013-09-08 14:30:26 +02:00
|
|
|
import os
|
|
|
|
import sys
|
2013-10-12 21:30:34 +02:00
|
|
|
import tempfile
|
2013-10-28 16:34:53 +01:00
|
|
|
import threading
|
|
|
|
import time
|
|
|
|
import webbrowser
|
2017-08-24 12:26:55 +02:00
|
|
|
from typing import Dict, Optional
|
2013-10-28 16:34:53 +01:00
|
|
|
|
|
|
|
from django.conf import ENVIRONMENT_VARIABLE
|
2015-06-16 10:37:23 +02:00
|
|
|
from django.core.exceptions import ImproperlyConfigured
|
2014-08-16 09:25:18 +02:00
|
|
|
from django.utils.crypto import get_random_string
|
2017-08-24 12:26:55 +02:00
|
|
|
from mypy_extensions import NoReturn
|
2013-09-08 14:30:26 +02:00
|
|
|
|
2018-07-09 23:22:26 +02:00
|
|
|
|
2019-01-06 16:22:33 +01:00
|
|
|
DEVELOPMENT_VERSION = "Development Version"
|
|
|
|
UNIX_VERSION = "Unix Version"
|
|
|
|
WINDOWS_VERSION = "Windows Version"
|
|
|
|
WINDOWS_PORTABLE_VERSION = "Windows Portable Version"
|
2013-09-08 14:30:26 +02:00
|
|
|
|
2013-10-13 17:17:56 +02:00
|
|
|
|
2013-10-12 21:30:34 +02:00
|
|
|
class PortableDirNotWritable(Exception):
|
|
|
|
pass
|
2013-09-08 14:30:26 +02:00
|
|
|
|
2013-10-13 17:17:56 +02:00
|
|
|
|
2013-11-06 17:49:41 +01:00
|
|
|
class PortIsBlockedError(Exception):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
2013-10-28 16:34:53 +01:00
|
|
|
class DatabaseInSettingsError(Exception):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
2015-01-16 14:18:34 +01:00
|
|
|
class UnknownCommand(Exception):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
class ExceptionArgumentParser(argparse.ArgumentParser):
|
2017-08-24 12:26:55 +02:00
|
|
|
def error(self, message: str) -> NoReturn:
|
2015-01-16 14:18:34 +01:00
|
|
|
raise UnknownCommand(message)
|
|
|
|
|
|
|
|
|
2017-08-24 12:26:55 +02:00
|
|
|
def detect_openslides_type() -> str:
|
2013-09-08 14:30:26 +02:00
|
|
|
"""
|
2013-10-13 17:17:56 +02:00
|
|
|
Returns the type of this OpenSlides version.
|
2013-09-08 14:30:26 +02:00
|
|
|
"""
|
2019-01-06 16:22:33 +01:00
|
|
|
if sys.platform == "win32":
|
|
|
|
if os.path.basename(sys.executable).lower() == "openslides.exe":
|
2013-09-08 14:30:26 +02:00
|
|
|
# Note: sys.executable is the path of the *interpreter*
|
|
|
|
# the portable version embeds python so it *is* the interpreter.
|
|
|
|
# The wrappers generated by pip and co. will spawn the usual
|
|
|
|
# python(w).exe, so there is no danger of mistaking them
|
|
|
|
# for the portable even though they may also be called
|
|
|
|
# openslides.exe
|
|
|
|
openslides_type = WINDOWS_PORTABLE_VERSION
|
|
|
|
else:
|
|
|
|
openslides_type = WINDOWS_VERSION
|
|
|
|
else:
|
|
|
|
openslides_type = UNIX_VERSION
|
|
|
|
return openslides_type
|
|
|
|
|
|
|
|
|
2018-08-08 21:09:22 +02:00
|
|
|
def get_default_settings_dir(openslides_type: str = None) -> str:
|
2013-10-28 16:34:53 +01:00
|
|
|
"""
|
|
|
|
Returns the default settings path according to the OpenSlides type.
|
|
|
|
|
|
|
|
The argument 'openslides_type' has to be one of the three types mentioned in
|
|
|
|
openslides.utils.main.
|
|
|
|
"""
|
2015-01-16 14:18:34 +01:00
|
|
|
if openslides_type is None:
|
|
|
|
openslides_type = detect_openslides_type()
|
|
|
|
|
2013-10-28 16:34:53 +01:00
|
|
|
if openslides_type == UNIX_VERSION:
|
2014-08-16 09:25:18 +02:00
|
|
|
parent_directory = os.environ.get(
|
2019-01-06 16:22:33 +01:00
|
|
|
"XDG_CONFIG_HOME", os.path.expanduser("~/.config")
|
|
|
|
)
|
2013-10-28 16:34:53 +01:00
|
|
|
elif openslides_type == WINDOWS_VERSION:
|
2018-01-16 16:02:23 +01:00
|
|
|
parent_directory = get_win32_app_data_dir()
|
2013-10-28 16:34:53 +01:00
|
|
|
elif openslides_type == WINDOWS_PORTABLE_VERSION:
|
2018-01-16 16:02:23 +01:00
|
|
|
parent_directory = get_win32_portable_dir()
|
2013-10-28 16:34:53 +01:00
|
|
|
else:
|
2019-01-12 23:01:42 +01:00
|
|
|
raise TypeError(f"{openslides_type} is not a valid OpenSlides type.")
|
2019-01-06 16:22:33 +01:00
|
|
|
return os.path.join(parent_directory, "openslides")
|
2013-10-28 16:34:53 +01:00
|
|
|
|
|
|
|
|
2018-01-16 16:02:23 +01:00
|
|
|
def get_local_settings_dir() -> str:
|
2015-01-16 14:18:34 +01:00
|
|
|
"""
|
2016-02-27 18:27:03 +01:00
|
|
|
Returns the path to a local settings.
|
2015-01-16 14:18:34 +01:00
|
|
|
|
2018-01-16 16:02:23 +01:00
|
|
|
On Unix systems: 'personal_data/var/'
|
2015-01-16 14:18:34 +01:00
|
|
|
"""
|
2019-01-06 16:22:33 +01:00
|
|
|
return os.path.join("personal_data", "var")
|
2015-01-16 14:18:34 +01:00
|
|
|
|
|
|
|
|
2019-01-06 16:22:33 +01:00
|
|
|
def setup_django_settings_module(
|
|
|
|
settings_path: str = None, local_installation: bool = False
|
|
|
|
) -> None:
|
2013-10-28 16:34:53 +01:00
|
|
|
"""
|
|
|
|
Sets the environment variable ENVIRONMENT_VARIABLE, that means
|
|
|
|
'DJANGO_SETTINGS_MODULE', to the given settings.
|
2015-01-16 14:18:34 +01:00
|
|
|
|
|
|
|
If no settings_path is given and the environment variable is already set,
|
|
|
|
then this function does nothing.
|
|
|
|
|
|
|
|
If the argument settings_path is set, then the environment variable is
|
|
|
|
always overwritten.
|
2013-10-28 16:34:53 +01:00
|
|
|
"""
|
2017-08-24 12:26:55 +02:00
|
|
|
if settings_path is None and os.environ.get(ENVIRONMENT_VARIABLE, ""):
|
2015-01-16 14:18:34 +01:00
|
|
|
return
|
|
|
|
|
|
|
|
if settings_path is None:
|
2016-02-27 18:27:03 +01:00
|
|
|
if local_installation:
|
2018-01-16 16:02:23 +01:00
|
|
|
settings_dir = get_local_settings_dir()
|
2015-01-16 14:18:34 +01:00
|
|
|
else:
|
2018-01-16 16:02:23 +01:00
|
|
|
settings_dir = get_default_settings_dir()
|
2019-01-06 16:22:33 +01:00
|
|
|
settings_path = os.path.join(settings_dir, "settings.py")
|
2015-01-16 14:18:34 +01:00
|
|
|
|
2013-10-28 16:34:53 +01:00
|
|
|
settings_file = os.path.basename(settings_path)
|
2019-01-06 16:22:33 +01:00
|
|
|
settings_module_name = ".".join(settings_file.split(".")[:-1])
|
|
|
|
if "." in settings_module_name:
|
|
|
|
raise ImproperlyConfigured(
|
|
|
|
"'.' is not an allowed character in the settings-file"
|
|
|
|
)
|
2013-10-28 16:34:53 +01:00
|
|
|
|
2015-01-16 14:18:34 +01:00
|
|
|
# Change the python path. Also set the environment variable python path, so
|
|
|
|
# change of the python path also works after a reload
|
|
|
|
settings_module_dir = os.path.abspath(os.path.dirname(settings_path))
|
|
|
|
sys.path.insert(0, settings_module_dir)
|
|
|
|
try:
|
2019-01-06 16:22:33 +01:00
|
|
|
os.environ["PYTHONPATH"] = os.pathsep.join(
|
|
|
|
(settings_module_dir, os.environ["PYTHONPATH"])
|
|
|
|
)
|
2015-01-16 14:18:34 +01:00
|
|
|
except KeyError:
|
|
|
|
# The environment variable is empty
|
2019-01-06 16:22:33 +01:00
|
|
|
os.environ["PYTHONPATH"] = settings_module_dir
|
2013-10-28 16:34:53 +01:00
|
|
|
|
2015-01-16 14:18:34 +01:00
|
|
|
# Set the environment variable to the settings module
|
|
|
|
os.environ[ENVIRONMENT_VARIABLE] = settings_module_name
|
2013-10-28 16:34:53 +01:00
|
|
|
|
|
|
|
|
2018-08-08 21:09:22 +02:00
|
|
|
def get_default_settings_context(user_data_dir: str = None) -> Dict[str, str]:
|
2013-10-28 16:34:53 +01:00
|
|
|
"""
|
2014-01-11 15:47:15 +01:00
|
|
|
Returns the default context values for the settings template:
|
|
|
|
'openslides_user_data_path', 'import_function' and 'debug'.
|
2013-10-28 16:34:53 +01:00
|
|
|
|
|
|
|
The argument 'user_data_path' is a given path for user specific data or None.
|
|
|
|
"""
|
2017-01-20 11:35:29 +01:00
|
|
|
# Setup path for user specific data (SQLite3 database, media, ...):
|
2013-10-28 16:34:53 +01:00
|
|
|
# Take it either from command line or get default path
|
2014-01-11 15:47:15 +01:00
|
|
|
default_context = {}
|
2018-01-16 16:02:23 +01:00
|
|
|
if user_data_dir:
|
2019-01-06 16:22:33 +01:00
|
|
|
default_context["openslides_user_data_dir"] = repr(user_data_dir)
|
|
|
|
default_context["import_function"] = ""
|
2013-10-28 16:34:53 +01:00
|
|
|
else:
|
|
|
|
openslides_type = detect_openslides_type()
|
2014-01-11 15:47:15 +01:00
|
|
|
if openslides_type == WINDOWS_PORTABLE_VERSION:
|
2019-01-06 16:22:33 +01:00
|
|
|
default_context[
|
|
|
|
"openslides_user_data_dir"
|
|
|
|
] = "get_win32_portable_user_data_dir()"
|
|
|
|
default_context[
|
|
|
|
"import_function"
|
|
|
|
] = "from openslides.utils.main import get_win32_portable_user_data_dir"
|
2014-01-11 15:47:15 +01:00
|
|
|
else:
|
2018-01-16 16:02:23 +01:00
|
|
|
data_dir = get_default_user_data_dir(openslides_type)
|
2019-01-06 16:22:33 +01:00
|
|
|
default_context["openslides_user_data_dir"] = repr(
|
|
|
|
os.path.join(data_dir, "openslides")
|
|
|
|
)
|
|
|
|
default_context["import_function"] = ""
|
|
|
|
default_context["debug"] = "False"
|
2013-10-28 16:34:53 +01:00
|
|
|
return default_context
|
|
|
|
|
|
|
|
|
2018-01-16 16:02:23 +01:00
|
|
|
def get_default_user_data_dir(openslides_type: str) -> str:
|
2013-09-08 14:30:26 +02:00
|
|
|
"""
|
2018-01-16 16:02:23 +01:00
|
|
|
Returns the default directory for user specific data according to the OpenSlides
|
2013-10-13 17:17:56 +02:00
|
|
|
type.
|
|
|
|
|
|
|
|
The argument 'openslides_type' has to be one of the three types mentioned
|
|
|
|
in openslides.utils.main.
|
2013-09-08 14:30:26 +02:00
|
|
|
"""
|
2013-10-13 17:17:56 +02:00
|
|
|
if openslides_type == UNIX_VERSION:
|
2018-01-16 16:02:23 +01:00
|
|
|
default_user_data_dir = os.environ.get(
|
2019-01-06 16:22:33 +01:00
|
|
|
"XDG_DATA_HOME", os.path.expanduser("~/.local/share")
|
|
|
|
)
|
2013-10-13 17:17:56 +02:00
|
|
|
elif openslides_type == WINDOWS_VERSION:
|
2018-01-16 16:02:23 +01:00
|
|
|
default_user_data_dir = get_win32_app_data_dir()
|
2013-10-13 17:17:56 +02:00
|
|
|
elif openslides_type == WINDOWS_PORTABLE_VERSION:
|
2018-01-16 16:02:23 +01:00
|
|
|
default_user_data_dir = get_win32_portable_dir()
|
2013-10-13 17:17:56 +02:00
|
|
|
else:
|
2019-01-12 23:01:42 +01:00
|
|
|
raise TypeError(f"{openslides_type} is not a valid OpenSlides type.")
|
2018-01-16 16:02:23 +01:00
|
|
|
return default_user_data_dir
|
2013-09-08 14:30:26 +02:00
|
|
|
|
|
|
|
|
2018-01-16 16:02:23 +01:00
|
|
|
def get_win32_app_data_dir() -> str:
|
2013-09-08 14:30:26 +02:00
|
|
|
"""
|
2018-01-16 16:02:23 +01:00
|
|
|
Returns the directory of Windows' AppData directory.
|
2013-09-08 14:30:26 +02:00
|
|
|
"""
|
2019-01-06 16:22:33 +01:00
|
|
|
shell32 = ctypes.WinDLL("shell32.dll") # type: ignore
|
2013-09-08 14:30:26 +02:00
|
|
|
SHGetFolderPath = shell32.SHGetFolderPathW
|
|
|
|
SHGetFolderPath.argtypes = (
|
2019-01-06 16:22:33 +01:00
|
|
|
ctypes.c_void_p,
|
|
|
|
ctypes.c_int,
|
|
|
|
ctypes.c_void_p,
|
|
|
|
ctypes.c_uint32,
|
|
|
|
ctypes.c_wchar_p,
|
|
|
|
)
|
2013-09-08 14:30:26 +02:00
|
|
|
SHGetFolderPath.restype = ctypes.c_uint32
|
|
|
|
|
2019-01-06 16:22:33 +01:00
|
|
|
CSIDL_LOCAL_APPDATA = 0x001C
|
2013-09-08 14:30:26 +02:00
|
|
|
MAX_PATH = 260
|
|
|
|
|
|
|
|
buf = ctypes.create_unicode_buffer(MAX_PATH)
|
|
|
|
res = SHGetFolderPath(0, CSIDL_LOCAL_APPDATA, 0, 0, buf)
|
|
|
|
if res != 0:
|
2014-08-16 09:25:18 +02:00
|
|
|
# TODO: Write other exception
|
2013-10-13 17:17:56 +02:00
|
|
|
raise Exception("Could not determine Windows' APPDATA path")
|
2013-09-08 14:30:26 +02:00
|
|
|
|
2018-08-20 21:01:30 +02:00
|
|
|
return buf.value # type: ignore
|
2013-09-08 14:30:26 +02:00
|
|
|
|
|
|
|
|
2018-01-16 16:02:23 +01:00
|
|
|
def get_win32_portable_dir() -> str:
|
2013-09-08 14:30:26 +02:00
|
|
|
"""
|
2018-01-16 16:02:23 +01:00
|
|
|
Returns the directory of the Windows portable version.
|
2013-09-08 14:30:26 +02:00
|
|
|
"""
|
|
|
|
# NOTE: sys.executable will be the path to openslides.exe
|
|
|
|
# since it is essentially a small wrapper that embeds the
|
|
|
|
# python interpreter
|
2018-01-16 16:02:23 +01:00
|
|
|
portable_dir = os.path.dirname(os.path.abspath(sys.executable))
|
2013-09-08 14:30:26 +02:00
|
|
|
try:
|
2018-01-16 16:02:23 +01:00
|
|
|
fd, test_file = tempfile.mkstemp(dir=portable_dir)
|
2013-09-08 14:30:26 +02:00
|
|
|
except OSError:
|
2013-10-12 21:30:34 +02:00
|
|
|
raise PortableDirNotWritable(
|
2019-01-06 16:22:33 +01:00
|
|
|
"Portable directory is not writeable. "
|
|
|
|
"Please choose another directory for settings and data files."
|
|
|
|
)
|
2013-10-12 21:30:34 +02:00
|
|
|
else:
|
2013-09-08 14:30:26 +02:00
|
|
|
os.close(fd)
|
|
|
|
os.unlink(test_file)
|
2018-01-16 16:02:23 +01:00
|
|
|
return portable_dir
|
2013-09-08 14:30:26 +02:00
|
|
|
|
|
|
|
|
2018-01-16 16:02:23 +01:00
|
|
|
def get_win32_portable_user_data_dir() -> str:
|
2014-05-03 13:39:47 +02:00
|
|
|
"""
|
2018-01-16 16:02:23 +01:00
|
|
|
Returns the user data directory to the Windows portable version.
|
2014-05-03 13:39:47 +02:00
|
|
|
"""
|
2019-01-06 16:22:33 +01:00
|
|
|
return os.path.join(get_win32_portable_dir(), "openslides")
|
2014-05-03 13:39:47 +02:00
|
|
|
|
|
|
|
|
2019-01-06 16:22:33 +01:00
|
|
|
def write_settings(
|
|
|
|
settings_dir: str = None,
|
|
|
|
settings_filename: str = "settings.py",
|
|
|
|
template: str = None,
|
|
|
|
**context: str,
|
|
|
|
) -> str:
|
2013-10-28 16:34:53 +01:00
|
|
|
"""
|
2018-01-16 16:02:23 +01:00
|
|
|
Creates the settings file at the given dir using the given values for the
|
2013-10-28 16:34:53 +01:00
|
|
|
file template.
|
2015-01-16 14:18:34 +01:00
|
|
|
|
|
|
|
Retuns the path to the created settings.
|
2013-10-28 16:34:53 +01:00
|
|
|
"""
|
2018-01-16 16:02:23 +01:00
|
|
|
if settings_dir is None:
|
|
|
|
settings_dir = get_default_settings_dir()
|
|
|
|
settings_path = os.path.join(settings_dir, settings_filename)
|
2015-01-16 14:18:34 +01:00
|
|
|
|
2013-10-28 16:34:53 +01:00
|
|
|
if template is None:
|
2019-01-06 16:22:33 +01:00
|
|
|
with open(
|
|
|
|
os.path.join(os.path.dirname(__file__), "settings.py.tpl")
|
|
|
|
) as template_file:
|
2013-10-28 16:34:53 +01:00
|
|
|
template = template_file.read()
|
2014-08-16 09:25:18 +02:00
|
|
|
|
|
|
|
# Create a random SECRET_KEY to put it in the settings.
|
|
|
|
# from django.core.management.commands.startproject
|
2019-01-06 16:22:33 +01:00
|
|
|
chars = "abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)"
|
|
|
|
context.setdefault("secret_key", get_random_string(50, chars))
|
2015-01-16 14:18:34 +01:00
|
|
|
for key, value in get_default_settings_context().items():
|
|
|
|
context.setdefault(key, value)
|
|
|
|
|
2013-10-28 16:34:53 +01:00
|
|
|
content = template % context
|
2018-01-16 16:02:23 +01:00
|
|
|
settings_module = os.path.realpath(settings_dir)
|
2013-10-28 16:34:53 +01:00
|
|
|
if not os.path.exists(settings_module):
|
|
|
|
os.makedirs(settings_module)
|
2019-01-06 16:22:33 +01:00
|
|
|
with open(settings_path, "w") as settings_file:
|
2013-10-28 16:34:53 +01:00
|
|
|
settings_file.write(content)
|
2018-01-16 16:02:23 +01:00
|
|
|
|
2019-01-06 16:22:33 +01:00
|
|
|
if context["openslides_user_data_dir"] == "get_win32_portable_user_data_dir()":
|
2018-01-16 16:02:23 +01:00
|
|
|
openslides_user_data_dir = get_win32_portable_user_data_dir()
|
2017-02-15 17:07:59 +01:00
|
|
|
else:
|
2019-01-06 16:22:33 +01:00
|
|
|
openslides_user_data_dir = context["openslides_user_data_dir"].strip("'")
|
|
|
|
os.makedirs(os.path.join(openslides_user_data_dir, "static"), exist_ok=True)
|
2015-01-16 14:18:34 +01:00
|
|
|
return os.path.realpath(settings_path)
|
2013-10-28 16:34:53 +01:00
|
|
|
|
|
|
|
|
2017-08-24 12:26:55 +02:00
|
|
|
def open_browser(host: str, port: int) -> None:
|
2017-02-15 13:22:08 +01:00
|
|
|
"""
|
|
|
|
Launches the default web browser at the given host and port and opens
|
|
|
|
the webinterface. Uses start_browser internally.
|
|
|
|
"""
|
2019-01-06 16:22:33 +01:00
|
|
|
if host == "0.0.0.0":
|
2017-02-15 13:22:08 +01:00
|
|
|
# Windows does not support 0.0.0.0, so use 'localhost' instead
|
2019-01-12 23:01:42 +01:00
|
|
|
start_browser(f"http://localhost:{port}")
|
2017-02-15 13:22:08 +01:00
|
|
|
else:
|
2019-01-12 23:01:42 +01:00
|
|
|
start_browser(f"http://{host}:{port}")
|
2017-02-15 13:22:08 +01:00
|
|
|
|
|
|
|
|
2017-08-24 12:26:55 +02:00
|
|
|
def start_browser(browser_url: str) -> None:
|
2013-10-28 16:34:53 +01:00
|
|
|
"""
|
|
|
|
Launches the default web browser at the given url and opens the
|
|
|
|
webinterface.
|
|
|
|
"""
|
2016-08-08 09:51:44 +02:00
|
|
|
try:
|
|
|
|
browser = webbrowser.get()
|
|
|
|
except webbrowser.Error:
|
2019-01-06 16:22:33 +01:00
|
|
|
print("Could not locate runnable browser: Skipping start")
|
2016-08-08 09:51:44 +02:00
|
|
|
else:
|
2013-10-28 16:34:53 +01:00
|
|
|
|
2017-08-24 12:26:55 +02:00
|
|
|
def function() -> None:
|
2019-01-20 10:05:50 +01:00
|
|
|
# TODO: Use a nonblocking sleep event here.
|
2016-08-08 09:51:44 +02:00
|
|
|
time.sleep(1)
|
|
|
|
browser.open(browser_url)
|
2013-10-28 16:34:53 +01:00
|
|
|
|
2016-08-08 09:51:44 +02:00
|
|
|
thread = threading.Thread(target=function)
|
|
|
|
thread.start()
|
2013-10-28 16:34:53 +01:00
|
|
|
|
|
|
|
|
2017-08-24 12:26:55 +02:00
|
|
|
def get_database_path_from_settings() -> Optional[str]:
|
2013-10-28 16:34:53 +01:00
|
|
|
"""
|
|
|
|
Retrieves the database path out of the settings file. Returns None,
|
|
|
|
if it is not a SQLite3 database.
|
2015-01-16 14:18:34 +01:00
|
|
|
|
|
|
|
Needed for the backupdb command.
|
2013-10-28 16:34:53 +01:00
|
|
|
"""
|
|
|
|
from django.conf import settings as django_settings
|
|
|
|
from django.db import DEFAULT_DB_ALIAS
|
|
|
|
|
|
|
|
db_settings = django_settings.DATABASES
|
|
|
|
default = db_settings.get(DEFAULT_DB_ALIAS)
|
|
|
|
if not default:
|
|
|
|
raise DatabaseInSettingsError("Default databases is not configured")
|
2019-01-06 16:22:33 +01:00
|
|
|
database_path = default.get("NAME")
|
2013-10-28 16:34:53 +01:00
|
|
|
if not database_path:
|
2019-01-06 16:22:33 +01:00
|
|
|
raise DatabaseInSettingsError("No path or name specified for default database.")
|
|
|
|
if default.get("ENGINE") != "django.db.backends.sqlite3":
|
2013-10-28 16:34:53 +01:00
|
|
|
database_path = None
|
|
|
|
return database_path
|
2014-01-31 01:54:41 +01:00
|
|
|
|
|
|
|
|
2017-08-24 12:26:55 +02:00
|
|
|
def is_local_installation() -> bool:
|
2015-01-16 14:18:34 +01:00
|
|
|
"""
|
2016-02-27 18:27:03 +01:00
|
|
|
Returns True if the command is called for a local installation
|
2015-01-16 14:18:34 +01:00
|
|
|
|
2016-02-27 18:27:03 +01:00
|
|
|
This is the case if manage.py is used, or when the --local-installation flag is set.
|
2015-01-16 14:18:34 +01:00
|
|
|
"""
|
2019-01-06 16:22:33 +01:00
|
|
|
return (
|
|
|
|
True
|
|
|
|
if "--local-installation" in sys.argv or "manage.py" in sys.argv[0]
|
|
|
|
else False
|
|
|
|
)
|
2017-02-12 12:42:20 +01:00
|
|
|
|
|
|
|
|
2017-08-24 12:26:55 +02:00
|
|
|
def is_windows() -> bool:
|
2017-02-12 12:42:20 +01:00
|
|
|
"""
|
2017-02-15 13:22:08 +01:00
|
|
|
Returns True if the current system is Windows. Returns False otherwise.
|
2017-02-12 12:42:20 +01:00
|
|
|
"""
|
2019-01-06 16:22:33 +01:00
|
|
|
return sys.platform == "win32"
|