Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove is_installed, replace with explicit check for database file #4886

Merged
merged 1 commit into from
Feb 23, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 0 additions & 20 deletions kalite/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,3 @@

# ROOT_DATA_PATH is *not* where the source files live. It's a place where non-user-writable data files may be written.
ROOT_DATA_PATH = os.path.join(sys.prefix, 'share', 'kalite')


# TODO: Burn down this function, the name is weird, it just checks if a
# database exists... not really significant enough to put it in kalite.__init__
def is_installed():
"""Returns True if KA Lite is installed."""

from django.conf import settings

if "sqlite" in settings.DATABASES["default"]["ENGINE"]:
return os.path.exists(settings.DATABASES["default"]["NAME"]) # this is the db filepath for SQLite
else:
# TODO(bcipolli): use django raw connection to test; something like:
# from django.db import connection
# try:
# connection.introspection.table_names()
# return True
# except:
# return False
return True
9 changes: 3 additions & 6 deletions kalite/distributed/management/commands/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,11 +274,6 @@ def handle(self, *args, **options):
if git_migrate_path:
call_command("gitmigrate", path=git_migrate_path, interactive=options["interactive"])

# TODO(benjaoming): This is used very loosely, what does it mean?
# Does it mean that the installation path is clean or does it mean
# that we should remove (clean) items from a previous installation?
install_clean = not kalite.is_installed()

database_kind = settings.DATABASES["default"]["ENGINE"]
if "sqlite" in database_kind:
database_file = settings.DATABASES["default"]["NAME"]
Expand All @@ -291,6 +286,8 @@ def handle(self, *args, **options):
# exist. But if it's empty, it's safe to overwrite.
database_exists = database_exists and os.path.getsize(database_file) > 0

install_clean = not database_exists

if database_file:
if not database_exists:
install_clean = True
Expand All @@ -316,7 +313,7 @@ def handle(self, *args, **options):
print(
"the database file will be moved to a deletable location.")

if not install_clean and not database_file and not kalite.is_installed():
if not install_clean and not database_file:
# Make sure that, for non-sqlite installs, the database exists.
raise Exception(
"For databases not using SQLite, you must set up your database before running setup.")
Expand Down