Skip to content

Commit

Permalink
Merge pull request #5343 from benjaoming/clearuserdata
Browse files Browse the repository at this point in the history
Prepare a device for cloning: Management command for clearing user data
  • Loading branch information
benjaoming committed Nov 25, 2016
2 parents 5d5928f + 6ee758c commit aa6181b
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
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."

0 comments on commit aa6181b

Please sign in to comment.