dump_course_ids.py 1000 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
# pylint: disable=missing-docstring

from optparse import make_option
from textwrap import dedent

from django.core.management.base import BaseCommand, CommandError

from xmodule.modulestore.django import modulestore


class Command(BaseCommand):
    """
    Simple command to dump the course_ids available to the lms.
14 15 16

    Output is UTF-8 encoded by default.

17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
    """
    help = dedent(__doc__).strip()
    option_list = BaseCommand.option_list + (
        make_option('--modulestore',
                    action='store',
                    default='default',
                    help='Name of the modulestore to use'),
    )

    def handle(self, *args, **options):
        try:
            name = options['modulestore']
            store = modulestore(name)
        except KeyError:
            raise CommandError("Unknown modulestore {}".format(name))

33
        output = u'\n'.join(course.id.to_deprecated_string() for course in store.get_courses()) + '\n'
34

35
        return output.encode('utf-8')