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

Prepare a device for cloning: Management command for clearing user data #5343

Merged
merged 3 commits into from
Nov 25, 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
6 changes: 6 additions & 0 deletions docs/installguide/release_notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ Release Notes

This is a draft of what will be released. Notes are not fully accurate or final.

New features
^^^^^^^^^^^^

* New management command ``clearuserdata``, makes it easy to prepare a
prototype device for subsequent cloning. :url-issue:`5341`

Bug fixes
^^^^^^^^^

Expand Down
52 changes: 52 additions & 0 deletions kalite/distributed/management/commands/clearuserdata.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import os
import shutil
import sys

from optparse import make_option

from django.conf import settings
from django.core.management.base import BaseCommand


class Command(BaseCommand):
help = "Clear out all usage data (NOT including videos and content packs)"

option_list = BaseCommand.option_list + (
make_option('--noinput',
action='store_true',
dest='noinput',
default=False,
help='Do not warn, just clear out user data',
),
)

def handle(self, *args, **options):

if not options['noinput']:

print (
"This will remove all usage data and device registration "
"permanently."
)
yn = raw_input("Are you sure? [y/n] ")
if yn.lower().strip() != "y":
print "No problem, have a nice day!"
sys.exit(0)

shutil.copy(
settings.DB_TEMPLATE_DEFAULT,
settings.DEFAULT_DATABASE_PATH
)

if os.path.exists(settings.SECRET_KEY_FILE):
os.unlink(settings.SECRET_KEY_FILE)

print ""
print "Successfully cleared out database and secret device key."
print ""
print (
"This device will automatically be re-initialized upon next "
"kalite start-up."
)
print ""
print "KA Lite installation is ready to be cloned to other devices."