Skip to content

Commit

Permalink
Add "--no-assessment-items" option to setup command, for central server
Browse files Browse the repository at this point in the history
  • Loading branch information
jamalex committed Jul 11, 2015
1 parent 47c8490 commit b0e5c0a
Showing 1 changed file with 72 additions and 61 deletions.
133 changes: 72 additions & 61 deletions kalite/distributed/management/commands/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,11 @@ class Command(BaseCommand):
dest='force-assessment-item-dl',
default=False,
help='Downloads assessment items from the url specified by settings.ASSESSMENT_ITEMS_ZIP_URL, without interaction'),
make_option('-i', '--no-assessment-items',
action='store_true',
dest='no-assessment-items',
default=False,
help='Skip all steps associating with assessment item downloading or the assessment item database'),
make_option('-g', '--git-migrate',
action='store',
dest='git_migrate_path',
Expand Down Expand Up @@ -360,73 +365,79 @@ def handle(self, *args, **options):
call_command(
"syncdb", interactive=False, verbosity=options.get("verbosity"))
call_command("migrate", merge=True, verbosity=options.get("verbosity"))
# Create *.json and friends database
call_command("syncdb", interactive=False, verbosity=options.get(
"verbosity"), database="assessment_items")

# download assessment items
# This can take a long time and lead to Travis stalling. None of this
# is required for tests.

# Outdated location of assessment items
# TODO(benjaoming) for 0.15, remove this
writable_assessment_items = os.access(
settings.KHAN_ASSESSMENT_ITEM_ROOT, os.W_OK)

def _move_to_new_location(old, new):
if not writable_assessment_items:
return
if os.path.exists(old):
if os.access(settings.KHAN_CONTENT_PATH, os.W_OK):
os.rename(old, new)
_move_to_new_location(
os.path.join(settings.KHAN_CONTENT_PATH, 'assessmentitems.sqlite'),
settings.KHAN_ASSESSMENT_ITEM_DATABASE_PATH
)
_move_to_new_location(
os.path.join(
settings.KHAN_CONTENT_PATH, 'assessmentitems.version'),
settings.KHAN_ASSESSMENT_ITEM_VERSION_PATH
)
_move_to_new_location(
os.path.join(
settings.USER_DATA_ROOT, "data", "khan", "assessmentitems.json"),
settings.KHAN_ASSESSMENT_ITEM_JSON_PATH
)
if writable_assessment_items and options['force-assessment-item-dl']:
call_command(
"unpack_assessment_zip", settings.ASSESSMENT_ITEMS_ZIP_URL)
elif options['force-assessment-item-dl']:
raise RuntimeError(
"Got force-assessment-item-dl but directory not writable")
elif writable_assessment_items and not settings.RUNNING_IN_TRAVIS and options['interactive']:
print(
"\nStarting in version 0.13, you will need an assessment items package in order to access many of the available exercises.")
print(
"If you have an internet connection, you can download the needed package. Warning: this may take a long time!")
print(
"If you have already downloaded the assessment items package, you can specify the file in the next step.")
print("Otherwise, we will download it from {url}.".format(
url=settings.ASSESSMENT_ITEMS_ZIP_URL))

if raw_input_yn("Do you wish to download the assessment items package now?"):
ass_item_filename = settings.ASSESSMENT_ITEMS_ZIP_URL
elif raw_input_yn("Have you already downloaded the assessment items package?"):
ass_item_filename = get_assessment_items_filename()
else:
ass_item_filename = None
# is required for tests, and does not apply to the central server.
if options.get("no-assessment-items", False):

logging.warning("Skipping assessment item downloading and configuration.")

else:

# Create *.json and friends database
call_command("syncdb", interactive=False, verbosity=options.get(
"verbosity"), database="assessment_items")

# Outdated location of assessment items
# TODO(benjaoming) for 0.15, remove this
writable_assessment_items = os.access(
settings.KHAN_ASSESSMENT_ITEM_ROOT, os.W_OK)

def _move_to_new_location(old, new):
if not writable_assessment_items:
return
if os.path.exists(old):
if os.access(settings.KHAN_CONTENT_PATH, os.W_OK):
os.rename(old, new)
_move_to_new_location(
os.path.join(settings.KHAN_CONTENT_PATH, 'assessmentitems.sqlite'),
settings.KHAN_ASSESSMENT_ITEM_DATABASE_PATH
)
_move_to_new_location(
os.path.join(
settings.KHAN_CONTENT_PATH, 'assessmentitems.version'),
settings.KHAN_ASSESSMENT_ITEM_VERSION_PATH
)
_move_to_new_location(
os.path.join(
settings.USER_DATA_ROOT, "data", "khan", "assessmentitems.json"),
settings.KHAN_ASSESSMENT_ITEM_JSON_PATH
)
if writable_assessment_items and options['force-assessment-item-dl']:
call_command(
"unpack_assessment_zip", settings.ASSESSMENT_ITEMS_ZIP_URL)
elif options['force-assessment-item-dl']:
raise RuntimeError(
"Got force-assessment-item-dl but directory not writable")
elif writable_assessment_items and not settings.RUNNING_IN_TRAVIS and options['interactive']:
print(
"\nStarting in version 0.13, you need an assessment items package in order to access many of the available exercises.")
print(
"If you have an internet connection, you can download the needed package. Warning: this may take a long time!")
print(
"If you have already downloaded the assessment items package, you can specify the file in the next step.")
print("Otherwise, we will download it from {url}.".format(
url=settings.ASSESSMENT_ITEMS_ZIP_URL))

if raw_input_yn("Do you wish to download the assessment items package now?"):
ass_item_filename = settings.ASSESSMENT_ITEMS_ZIP_URL
elif raw_input_yn("Have you already downloaded the assessment items package?"):
ass_item_filename = get_assessment_items_filename()
else:
ass_item_filename = None

if not ass_item_filename:
if not ass_item_filename:
logging.warning(
"No assessment items package file given. You will need to download and unpack it later.")
else:
call_command("unpack_assessment_zip", ass_item_filename)
elif options['interactive']:
logging.warning(
"No assessment items package file given. You will need to download and unpack it later.")
"Assessment item directory not writable, skipping download.")
else:
call_command("unpack_assessment_zip", ass_item_filename)
elif options['interactive']:
logging.warning(
"Assessment item directory not writable, skipping download.")
else:
logging.warning(
"No assessment items package file given. You will need to download and unpack it later.")
logging.warning(
"No assessment items package file given. You will need to download and unpack it later.")

# Individually generate any prerequisite models/state that is missing
if not Settings.get("private_key"):
Expand Down

0 comments on commit b0e5c0a

Please sign in to comment.