From 88f426077776f0b8c43c477292d5aed5ca2096d9 Mon Sep 17 00:00:00 2001 From: Adam Jones Date: Wed, 17 Aug 2016 00:35:31 -0400 Subject: [PATCH] Change default location for db and logs to ~/.caravel Fix #915 (#947) --- caravel/config.py | 11 +++++------ docs/installation.rst | 6 +++--- tests/caravel_test_config.py | 3 +-- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/caravel/config.py b/caravel/config.py index 06fded5246..f4285ebddd 100644 --- a/caravel/config.py +++ b/caravel/config.py @@ -15,7 +15,9 @@ from dateutil import tz from flask_appbuilder.security.manager import AUTH_DB BASE_DIR = os.path.abspath(os.path.dirname(__file__)) - +DATA_DIR = os.path.join(os.path.expanduser('~'), '.caravel') +if not os.path.exists(DATA_DIR): + os.makedirs(DATA_DIR) # --------------------------------------------------------- # Caravel specific config @@ -34,10 +36,7 @@ CUSTOM_SECURITY_MANAGER = None SECRET_KEY = '\2\1thisismyscretkey\1\2\e\y\y\h' # noqa # The SQLAlchemy connection string. -SQLALCHEMY_DATABASE_URI = 'sqlite:////tmp/caravel.db' -# this is for platform specific: "nt" is for windows, "posix" is *nix (including Mac) -if os.name == "nt": - SQLALCHEMY_DATABASE_URI = 'sqlite:///c:\\tmp\\caravel.db' +SQLALCHEMY_DATABASE_URI = 'sqlite:///' + os.path.join(DATA_DIR, 'caravel.db') # SQLALCHEMY_DATABASE_URI = 'mysql://myapp@localhost/myapp' # SQLALCHEMY_DATABASE_URI = 'postgresql://root:password@localhost/myapp' @@ -172,7 +171,7 @@ LOG_LEVEL = 'DEBUG' ENABLE_TIME_ROTATE = False TIME_ROTATE_LOG_LEVEL = 'DEBUG' -FILENAME = '/tmp/caravel.log' +FILENAME = os.path.join(DATA_DIR, 'caravel.log') ROLLOVER = 'midnight' INTERVAL = 1 BACKUP_COUNT = 30 diff --git a/docs/installation.rst b/docs/installation.rst index ae57ffbdf2..4b050691df 100644 --- a/docs/installation.rst +++ b/docs/installation.rst @@ -136,7 +136,7 @@ of the parameters you can copy / paste in that configuration module: :: # caravel metadata (slices, connections, tables, dashboards, ...). # Note that the connection information to connect to the datasources # you want to explore are managed directly in the web UI - SQLALCHEMY_DATABASE_URI = 'sqlite:////tmp/caravel.db' + SQLALCHEMY_DATABASE_URI = 'sqlite:////path/to/caravel.db' # Flask-WTF flag for CSRF CSRF_ENABLED = True @@ -149,7 +149,7 @@ for more information on how to configure Caravel. Please make sure to change: -* *SQLALCHEMY_DATABASE_URI*, by default it is stored on */tmp* and so will be cleared after each boot +* *SQLALCHEMY_DATABASE_URI*, by default it is stored at *~/.caravel/caravel.db* * *SECRET_KEY*, to a long random string Database dependencies @@ -202,7 +202,7 @@ complies with the Flask-Cache specifications. Flask-Cache supports multiple caching backends (Redis, Memcached, SimpleCache (in-memory), or the local filesystem). If you are going to use Memcached please use the pylibmc client library as python-memcached does -not handle storing binary data correctly. If you use Redis, please install +not handle storing binary data correctly. If you use Redis, please install [python-redis](https://pypi.python.org/pypi/redis). For setting your timeouts, this is done in the Caravel metadata and goes diff --git a/tests/caravel_test_config.py b/tests/caravel_test_config.py index a7de456949..1720ec837b 100644 --- a/tests/caravel_test_config.py +++ b/tests/caravel_test_config.py @@ -1,7 +1,7 @@ from caravel.config import * AUTH_USER_REGISTRATION_ROLE = 'alpha' -SQLALCHEMY_DATABASE_URI = 'sqlite:////tmp/caravel_unittests.db' +SQLALCHEMY_DATABASE_URI = 'sqlite:///' + os.path.join(DATA_DIR, 'unittests.db') DEBUG = True CARAVEL_WEBSERVER_PORT = 8081 @@ -9,4 +9,3 @@ CARAVEL_WEBSERVER_PORT = 8081 # continuous integration if 'CARAVEL__SQLALCHEMY_DATABASE_URI' in os.environ: SQLALCHEMY_DATABASE_URI = os.environ.get('CARAVEL__SQLALCHEMY_DATABASE_URI') -