Commit c08ccee4 by Ned Batchelder

Merge pull request #7450 from edx/ned/common-lib-to-openedx-core-lib

Move common/lib/*.py to openedx/core/lib so that we can import them.
parents 798f91ca 99430113
...@@ -11,7 +11,7 @@ from django.core.management.base import BaseCommand, CommandError ...@@ -11,7 +11,7 @@ from django.core.management.base import BaseCommand, CommandError
from tempfile import mkdtemp from tempfile import mkdtemp
import tarfile import tarfile
import shutil import shutil
from extract_tar import safetar_extractall from openedx.core.lib.extract_tar import safetar_extractall
from xmodule.modulestore.xml_exporter import convert_between_versions from xmodule.modulestore.xml_exporter import convert_between_versions
......
...@@ -10,7 +10,6 @@ from datetime import timedelta ...@@ -10,7 +10,6 @@ from datetime import timedelta
from fs.osfs import OSFS from fs.osfs import OSFS
from json import loads from json import loads
from path import path from path import path
from tempdir import mkdtemp_clean
from textwrap import dedent from textwrap import dedent
from uuid import uuid4 from uuid import uuid4
from functools import wraps from functools import wraps
...@@ -21,6 +20,7 @@ from django.contrib.auth.models import User ...@@ -21,6 +20,7 @@ from django.contrib.auth.models import User
from django.test import TestCase from django.test import TestCase
from django.test.utils import override_settings from django.test.utils import override_settings
from openedx.core.lib.tempdir import mkdtemp_clean
from contentstore.tests.utils import parse_json, AjaxEnabledTestClient, CourseTestCase from contentstore.tests.utils import parse_json, AjaxEnabledTestClient, CourseTestCase
from contentstore.views.component import ADVANCED_COMPONENT_TYPES from contentstore.views.component import ADVANCED_COMPONENT_TYPES
......
...@@ -33,7 +33,7 @@ from xmodule.modulestore import COURSE_ROOT, LIBRARY_ROOT ...@@ -33,7 +33,7 @@ from xmodule.modulestore import COURSE_ROOT, LIBRARY_ROOT
from student.auth import has_course_author_access from student.auth import has_course_author_access
from extract_tar import safetar_extractall from openedx.core.lib.extract_tar import safetar_extractall
from util.json_request import JsonResponse from util.json_request import JsonResponse
from util.views import ensure_valid_course_key from util.views import ensure_valid_course_key
......
...@@ -23,7 +23,7 @@ from contentstore.utils import reverse_course_url ...@@ -23,7 +23,7 @@ from contentstore.utils import reverse_course_url
from xmodule.modulestore.tests.factories import ItemFactory, LibraryFactory from xmodule.modulestore.tests.factories import ItemFactory, LibraryFactory
from contentstore.tests.utils import CourseTestCase from contentstore.tests.utils import CourseTestCase
from extract_tar import safetar_extractall from openedx.core.lib.extract_tar import safetar_extractall
from student import auth from student import auth
from student.roles import CourseInstructorRole, CourseStaffRole from student.roles import CourseInstructorRole, CourseStaffRole
......
...@@ -15,7 +15,7 @@ import json ...@@ -15,7 +15,7 @@ import json
from .common import * from .common import *
from logsettings import get_logger_config from openedx.core.lib.logsettings import get_logger_config
import os import os
from path import path from path import path
......
...@@ -159,7 +159,6 @@ GITHUB_REPO_ROOT = ENV_ROOT / "data" ...@@ -159,7 +159,6 @@ GITHUB_REPO_ROOT = ENV_ROOT / "data"
sys.path.append(REPO_ROOT) sys.path.append(REPO_ROOT)
sys.path.append(PROJECT_ROOT / 'djangoapps') sys.path.append(PROJECT_ROOT / 'djangoapps')
sys.path.append(COMMON_ROOT / 'djangoapps') sys.path.append(COMMON_ROOT / 'djangoapps')
sys.path.append(COMMON_ROOT / 'lib')
# For geolocation ip database # For geolocation ip database
GEOIP_PATH = REPO_ROOT / "common/static/data/geoip/GeoIP.dat" GEOIP_PATH = REPO_ROOT / "common/static/data/geoip/GeoIP.dat"
...@@ -416,7 +415,7 @@ EMBARGO_SITE_REDIRECT_URL = None ...@@ -416,7 +415,7 @@ EMBARGO_SITE_REDIRECT_URL = None
############################### Pipeline ####################################### ############################### Pipeline #######################################
STATICFILES_STORAGE = 'cms.lib.django_require.staticstorage.OptimizedCachedRequireJsStorage' STATICFILES_STORAGE = 'cms.lib.django_require.staticstorage.OptimizedCachedRequireJsStorage'
from rooted_paths import rooted_glob from openedx.core.lib.rooted_paths import rooted_glob
PIPELINE_CSS = { PIPELINE_CSS = {
'style-vendor': { 'style-vendor': {
......
...@@ -6,7 +6,7 @@ This config file runs the simplest dev environment""" ...@@ -6,7 +6,7 @@ This config file runs the simplest dev environment"""
# pylint: disable=wildcard-import, unused-wildcard-import # pylint: disable=wildcard-import, unused-wildcard-import
from .common import * from .common import *
from logsettings import get_logger_config from openedx.core.lib.logsettings import get_logger_config
# import settings from LMS for consistent behavior with CMS # import settings from LMS for consistent behavior with CMS
from lms.envs.dev import (WIKI_ENABLED) from lms.envs.dev import (WIKI_ENABLED)
......
...@@ -17,7 +17,7 @@ defined in the environment: ...@@ -17,7 +17,7 @@ defined in the environment:
import yaml import yaml
from .common import * from .common import *
from logsettings import get_logger_config from openedx.core.lib.logsettings import get_logger_config
from util.config_parse import convert_tokens from util.config_parse import convert_tokens
import os import os
......
...@@ -7,7 +7,7 @@ from django.conf import settings ...@@ -7,7 +7,7 @@ from django.conf import settings
# Force settings to run so that the python path is modified # Force settings to run so that the python path is modified
settings.INSTALLED_APPS # pylint: disable=pointless-statement settings.INSTALLED_APPS # pylint: disable=pointless-statement
from django_startup import autostartup from openedx.core.lib.django_startup import autostartup
from monkey_patch import django_utils_translation from monkey_patch import django_utils_translation
......
...@@ -8,7 +8,7 @@ from django.template.loaders.app_directories import Loader as AppDirectoriesLoad ...@@ -8,7 +8,7 @@ from django.template.loaders.app_directories import Loader as AppDirectoriesLoad
from edxmako.template import Template from edxmako.template import Template
import tempdir from openedx.core.lib.tempdir import mkdtemp_clean
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
...@@ -30,7 +30,7 @@ class MakoLoader(object): ...@@ -30,7 +30,7 @@ class MakoLoader(object):
if module_directory is None: if module_directory is None:
log.warning("For more caching of mako templates, set the MAKO_MODULE_DIR in settings!") log.warning("For more caching of mako templates, set the MAKO_MODULE_DIR in settings!")
module_directory = tempdir.mkdtemp_clean() module_directory = mkdtemp_clean()
self.module_directory = module_directory self.module_directory = module_directory
......
...@@ -16,8 +16,8 @@ from django.conf import settings ...@@ -16,8 +16,8 @@ from django.conf import settings
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.db import models, transaction from django.db import models, transaction
from html_to_text import html_to_text from openedx.core.lib.html_to_text import html_to_text
from mail_utils import wrap_message from openedx.core.lib.mail_utils import wrap_message
from xmodule_django.models import CourseKeyField from xmodule_django.models import CourseKeyField
from util.keyword_substitution import substitute_keywords_with_data from util.keyword_substitution import substitute_keywords_with_data
......
...@@ -19,7 +19,7 @@ Common traits: ...@@ -19,7 +19,7 @@ Common traits:
import json import json
from .common import * from .common import *
from logsettings import get_logger_config from openedx.core.lib.logsettings import get_logger_config
import os import os
from path import path from path import path
......
...@@ -389,7 +389,6 @@ DATA_DIR = COURSES_ROOT ...@@ -389,7 +389,6 @@ DATA_DIR = COURSES_ROOT
sys.path.append(REPO_ROOT) sys.path.append(REPO_ROOT)
sys.path.append(PROJECT_ROOT / 'djangoapps') sys.path.append(PROJECT_ROOT / 'djangoapps')
sys.path.append(COMMON_ROOT / 'djangoapps') sys.path.append(COMMON_ROOT / 'djangoapps')
sys.path.append(COMMON_ROOT / 'lib')
# For Node.js # For Node.js
...@@ -1070,7 +1069,7 @@ X_FRAME_OPTIONS = 'ALLOW' ...@@ -1070,7 +1069,7 @@ X_FRAME_OPTIONS = 'ALLOW'
STATICFILES_STORAGE = 'pipeline.storage.PipelineCachedStorage' STATICFILES_STORAGE = 'pipeline.storage.PipelineCachedStorage'
from rooted_paths import rooted_glob from openedx.core.lib.rooted_paths import rooted_glob
courseware_js = ( courseware_js = (
[ [
......
...@@ -18,7 +18,6 @@ sessions. Assumes structure: ...@@ -18,7 +18,6 @@ sessions. Assumes structure:
# pylint: disable=invalid-name # pylint: disable=invalid-name
from .common import * from .common import *
from logsettings import get_logger_config
DEBUG = True DEBUG = True
TEMPLATE_DEBUG = True TEMPLATE_DEBUG = True
......
...@@ -13,7 +13,7 @@ sessions. Assumes structure: ...@@ -13,7 +13,7 @@ sessions. Assumes structure:
# pylint: disable=wildcard-import, unused-wildcard-import # pylint: disable=wildcard-import, unused-wildcard-import
from .common import * from .common import *
from logsettings import get_logger_config from openedx.core.lib.logsettings import get_logger_config
STATIC_GRAB = True STATIC_GRAB = True
......
...@@ -16,7 +16,7 @@ defined in the environment: ...@@ -16,7 +16,7 @@ defined in the environment:
import yaml import yaml
from .common import * from .common import *
from logsettings import get_logger_config from openedx.core.lib.logsettings import get_logger_config
from util.config_parse import convert_tokens from util.config_parse import convert_tokens
import os import os
......
...@@ -9,7 +9,7 @@ from django.conf import settings ...@@ -9,7 +9,7 @@ from django.conf import settings
# Force settings to run so that the python path is modified # Force settings to run so that the python path is modified
settings.INSTALLED_APPS # pylint: disable=pointless-statement settings.INSTALLED_APPS # pylint: disable=pointless-statement
from django_startup import autostartup from openedx.core.lib.django_startup import autostartup
import edxmako import edxmako
import logging import logging
from monkey_patch import django_utils_translation from monkey_patch import django_utils_translation
......
...@@ -13,7 +13,10 @@ from django.conf import settings ...@@ -13,7 +13,10 @@ from django.conf import settings
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.http import Http404 from django.http import Http404
from django.test.client import RequestFactory from django.test.client import RequestFactory
import django_test_client_utils # monkey-patch for PATCH request method.
# monkey-patch for PATCH request method.
import openedx.core.lib.django_test_client_utils # pylint: disable=unused-import
from student.models import CourseEnrollment from student.models import CourseEnrollment
from student.tests.factories import UserFactory from student.tests.factories import UserFactory
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
......
...@@ -2,6 +2,9 @@ ...@@ -2,6 +2,9 @@
This file includes the monkey-patch for requests' PATCH method, as we are using This file includes the monkey-patch for requests' PATCH method, as we are using
older version of django that does not contains the PATCH method in its test client. older version of django that does not contains the PATCH method in its test client.
""" """
# pylint: disable=protected-access
from __future__ import unicode_literals from __future__ import unicode_literals
from urlparse import urlparse from urlparse import urlparse
...@@ -13,11 +16,13 @@ BOUNDARY = 'BoUnDaRyStRiNg' ...@@ -13,11 +16,13 @@ BOUNDARY = 'BoUnDaRyStRiNg'
MULTIPART_CONTENT = 'multipart/form-data; boundary=%s' % BOUNDARY MULTIPART_CONTENT = 'multipart/form-data; boundary=%s' % BOUNDARY
def request_factory_patch(self, path, data={}, content_type=MULTIPART_CONTENT, **extra): def request_factory_patch(self, path, data=None, content_type=MULTIPART_CONTENT, **extra):
""" """
Construct a PATCH request. Construct a PATCH request.
""" """
patch_data = self._encode_data(data, content_type) # pylint: disable=invalid-name
patch_data = self._encode_data(data or {}, content_type)
parsed = urlparse(path) parsed = urlparse(path)
r = { r = {
...@@ -32,11 +37,11 @@ def request_factory_patch(self, path, data={}, content_type=MULTIPART_CONTENT, * ...@@ -32,11 +37,11 @@ def request_factory_patch(self, path, data={}, content_type=MULTIPART_CONTENT, *
return self.request(**r) return self.request(**r)
def client_patch(self, path, data={}, content_type=MULTIPART_CONTENT, follow=False, **extra): def client_patch(self, path, data=None, content_type=MULTIPART_CONTENT, follow=False, **extra):
""" """
Send a resource to the server using PATCH. Send a resource to the server using PATCH.
""" """
response = super(Client, self).patch(path, data=data, content_type=content_type, **extra) response = super(Client, self).patch(path, data=data or {}, content_type=content_type, **extra)
if follow: if follow:
response = self._handle_redirects(response, **extra) response = self._handle_redirects(response, **extra)
return response return response
......
"""Get log settings."""
import os import os
import platform import platform
import sys import sys
......
"""Provides rooted_glob, for finding relative glob paths in another director."""
import glob2 import glob2
......
...@@ -6,7 +6,7 @@ import shutil ...@@ -6,7 +6,7 @@ import shutil
import tempfile import tempfile
def mkdtemp_clean(suffix="", prefix="tmp", dir=None): def mkdtemp_clean(suffix="", prefix="tmp", dir=None): # pylint: disable=redefined-builtin
"""Just like mkdtemp, but the directory will be deleted when the process ends.""" """Just like mkdtemp, but the directory will be deleted when the process ends."""
the_dir = tempfile.mkdtemp(suffix=suffix, prefix=prefix, dir=dir) the_dir = tempfile.mkdtemp(suffix=suffix, prefix=prefix, dir=dir)
atexit.register(cleanup_tempdir, the_dir) atexit.register(cleanup_tempdir, the_dir)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment