From 5613797aa80e285de1fd55b48fcb34b504ecf8d3 Mon Sep 17 00:00:00 2001 From: Ayub khan Date: Tue, 9 Jul 2019 15:01:12 +0500 Subject: [PATCH] INCR-336 python3 compatibility --- .../management/commands/cleanup_assets.py | 2 ++ .../contentstore/management/commands/delete_course.py | 8 ++++++-- .../contentstore/management/commands/export_olx.py | 2 ++ .../contentstore/management/commands/import.py | 5 ++++- .../management/commands/migrate_transcripts.py | 11 ++++++++--- .../contentstore/management/commands/prompt.py | 9 ++++++++- .../management/commands/reindex_course.py | 5 ++++- .../contentstore/management/commands/utils.py | 2 ++ .../management/commands/video_thumbnails.py | 6 ++++-- .../contentstore/management/commands/xlint.py | 3 ++- 10 files changed, 42 insertions(+), 11 deletions(-) diff --git a/cms/djangoapps/contentstore/management/commands/cleanup_assets.py b/cms/djangoapps/contentstore/management/commands/cleanup_assets.py index 0eff9ad035..f335b11c66 100644 --- a/cms/djangoapps/contentstore/management/commands/cleanup_assets.py +++ b/cms/djangoapps/contentstore/management/commands/cleanup_assets.py @@ -2,6 +2,8 @@ Script for removing all redundant Mac OS metadata files (with filename ".DS_Store" or with filename which starts with "._") for all courses """ +from __future__ import absolute_import + import logging from django.core.management.base import BaseCommand diff --git a/cms/djangoapps/contentstore/management/commands/delete_course.py b/cms/djangoapps/contentstore/management/commands/delete_course.py index 1f6c706f1e..f16ea35a68 100644 --- a/cms/djangoapps/contentstore/management/commands/delete_course.py +++ b/cms/djangoapps/contentstore/management/commands/delete_course.py @@ -1,14 +1,18 @@ -from __future__ import print_function -from six import text_type +""" +Management Command to delete course. +""" +from __future__ import absolute_import, print_function from django.core.management.base import BaseCommand, CommandError from opaque_keys import InvalidKeyError from opaque_keys.edx.keys import CourseKey +from six import text_type from contentstore.utils import delete_course from xmodule.contentstore.django import contentstore from xmodule.modulestore import ModuleStoreEnum from xmodule.modulestore.django import modulestore + from .prompt import query_yes_no diff --git a/cms/djangoapps/contentstore/management/commands/export_olx.py b/cms/djangoapps/contentstore/management/commands/export_olx.py index 4d02aeefd7..bb11b7ad7b 100644 --- a/cms/djangoapps/contentstore/management/commands/export_olx.py +++ b/cms/djangoapps/contentstore/management/commands/export_olx.py @@ -14,6 +14,8 @@ At present, it differs from Studio exports in several ways: * It only supports the export of courses. It does not export libraries. """ +from __future__ import absolute_import + import os import re import shutil diff --git a/cms/djangoapps/contentstore/management/commands/import.py b/cms/djangoapps/contentstore/management/commands/import.py index 7aed4105d1..c2e9d54df4 100644 --- a/cms/djangoapps/contentstore/management/commands/import.py +++ b/cms/djangoapps/contentstore/management/commands/import.py @@ -1,13 +1,16 @@ """ Script for importing courseware from XML format """ +from __future__ import absolute_import + from django.core.management.base import BaseCommand + from openedx.core.djangoapps.django_comment_common.utils import are_permissions_roles_seeded, seed_permissions_roles from xmodule.contentstore.django import contentstore from xmodule.modulestore import ModuleStoreEnum from xmodule.modulestore.django import modulestore -from xmodule.util.sandboxing import DEFAULT_PYTHON_LIB_FILENAME from xmodule.modulestore.xml_importer import import_course_from_xml +from xmodule.util.sandboxing import DEFAULT_PYTHON_LIB_FILENAME class Command(BaseCommand): diff --git a/cms/djangoapps/contentstore/management/commands/migrate_transcripts.py b/cms/djangoapps/contentstore/management/commands/migrate_transcripts.py index b869f76898..5c66732a64 100644 --- a/cms/djangoapps/contentstore/management/commands/migrate_transcripts.py +++ b/cms/djangoapps/contentstore/management/commands/migrate_transcripts.py @@ -2,19 +2,24 @@ Command to migrate transcripts to django storage. """ +from __future__ import absolute_import + import logging + from django.core.management import BaseCommand, CommandError from opaque_keys import InvalidKeyError from opaque_keys.edx.keys import CourseKey from opaque_keys.edx.locator import CourseLocator +from six.moves import map + from cms.djangoapps.contentstore.tasks import ( DEFAULT_ALL_COURSES, - DEFAULT_FORCE_UPDATE, DEFAULT_COMMIT, + DEFAULT_FORCE_UPDATE, enqueue_async_migrate_transcripts_tasks ) +from openedx.core.djangoapps.video_config.models import MigrationEnqueuedCourse, TranscriptMigrationSetting from openedx.core.lib.command_utils import get_mutually_exclusive_required_option, parse_course_keys -from openedx.core.djangoapps.video_config.models import TranscriptMigrationSetting, MigrationEnqueuedCourse from xmodule.modulestore.django import modulestore log = logging.getLogger(__name__) @@ -91,7 +96,7 @@ class Command(BaseCommand): if courses_mode == 'all_courses': course_keys = [course.id for course in modulestore().get_course_summaries()] elif courses_mode == 'course_ids': - course_keys = map(self._parse_course_key, options['course_ids']) + course_keys = list(map(self._parse_course_key, options['course_ids'])) else: migration_settings = self._latest_settings() if migration_settings.all_courses: diff --git a/cms/djangoapps/contentstore/management/commands/prompt.py b/cms/djangoapps/contentstore/management/commands/prompt.py index e658738128..927c5c916c 100644 --- a/cms/djangoapps/contentstore/management/commands/prompt.py +++ b/cms/djangoapps/contentstore/management/commands/prompt.py @@ -1,5 +1,12 @@ +""" +Takes user input. +""" +from __future__ import absolute_import + import sys +from six.moves import input + def query_yes_no(question, default="yes"): """Ask a yes/no question via raw_input() and return their answer. @@ -29,7 +36,7 @@ def query_yes_no(question, default="yes"): while True: sys.stdout.write(question + prompt) - choice = raw_input().lower() + choice = input().lower() if default is not None and choice == '': return valid[default] elif choice in valid: diff --git a/cms/djangoapps/contentstore/management/commands/reindex_course.py b/cms/djangoapps/contentstore/management/commands/reindex_course.py index 0171c80dde..0055dbd31f 100644 --- a/cms/djangoapps/contentstore/management/commands/reindex_course.py +++ b/cms/djangoapps/contentstore/management/commands/reindex_course.py @@ -1,4 +1,6 @@ """ Management command to update courses' search index """ +from __future__ import absolute_import + import logging from textwrap import dedent @@ -8,6 +10,7 @@ from opaque_keys import InvalidKeyError from opaque_keys.edx.keys import CourseKey from opaque_keys.edx.locator import CourseLocator from search.search_engine_base import SearchEngine +from six.moves import map from contentstore.courseware_index import CoursewareSearchIndexer from xmodule.modulestore.django import modulestore @@ -101,7 +104,7 @@ class Command(BaseCommand): return else: # in case course keys are provided as arguments - course_keys = map(self._parse_course_key, course_ids) + course_keys = list(map(self._parse_course_key, course_ids)) for course_key in course_keys: CoursewareSearchIndexer.do_course_reindex(store, course_key) diff --git a/cms/djangoapps/contentstore/management/commands/utils.py b/cms/djangoapps/contentstore/management/commands/utils.py index 0b248ca526..99de627194 100644 --- a/cms/djangoapps/contentstore/management/commands/utils.py +++ b/cms/djangoapps/contentstore/management/commands/utils.py @@ -1,6 +1,8 @@ """ Common methods for cms commands to use """ +from __future__ import absolute_import + from django.contrib.auth.models import User from opaque_keys.edx.keys import CourseKey diff --git a/cms/djangoapps/contentstore/management/commands/video_thumbnails.py b/cms/djangoapps/contentstore/management/commands/video_thumbnails.py index e5cb570783..7bfe8c2611 100644 --- a/cms/djangoapps/contentstore/management/commands/video_thumbnails.py +++ b/cms/djangoapps/contentstore/management/commands/video_thumbnails.py @@ -1,17 +1,19 @@ """ Command to scrape thumbnails and add them to the course-videos. """ +from __future__ import absolute_import + import logging -from six import text_type import edxval.api as edxval_api from django.core.management import BaseCommand from django.core.management.base import CommandError from opaque_keys import InvalidKeyError from opaque_keys.edx.keys import CourseKey +from six import text_type -from openedx.core.djangoapps.video_config.models import VideoThumbnailSetting from cms.djangoapps.contentstore.tasks import enqueue_update_thumbnail_tasks +from openedx.core.djangoapps.video_config.models import VideoThumbnailSetting log = logging.getLogger(__name__) diff --git a/cms/djangoapps/contentstore/management/commands/xlint.py b/cms/djangoapps/contentstore/management/commands/xlint.py index 5bcb0b3e2c..09dd5c764d 100644 --- a/cms/djangoapps/contentstore/management/commands/xlint.py +++ b/cms/djangoapps/contentstore/management/commands/xlint.py @@ -1,7 +1,8 @@ """ Verify the structure of courseware as to it's suitability for import """ -from __future__ import print_function +from __future__ import absolute_import, print_function + from argparse import REMAINDER from django.core.management.base import BaseCommand