From 2ad515d15a6b22395b37f64db786db227d0b96c5 Mon Sep 17 00:00:00 2001 From: Don Mitchell Date: Mon, 12 Aug 2013 13:27:22 -0400 Subject: [PATCH] Move singleton accessor w/ django dependencies to same place as modulestore() singleton accessor --- common/lib/xmodule/xmodule/modulestore/django.py | 16 ++++++++++++++++ .../{LocMapperStore.py => loc_mapper_store.py} | 16 ---------------- .../modulestore/tests/test_location_mapper.py | 2 +- 3 files changed, 17 insertions(+), 17 deletions(-) rename common/lib/xmodule/xmodule/modulestore/{LocMapperStore.py => loc_mapper_store.py} (97%) diff --git a/common/lib/xmodule/xmodule/modulestore/django.py b/common/lib/xmodule/xmodule/modulestore/django.py index 2f0cd126f9..fb427f49ec 100644 --- a/common/lib/xmodule/xmodule/modulestore/django.py +++ b/common/lib/xmodule/xmodule/modulestore/django.py @@ -8,6 +8,7 @@ from __future__ import absolute_import from importlib import import_module from django.conf import settings +from xmodule.modulestore.loc_mapper_store import LocMapperStore _MODULESTORES = {} @@ -53,3 +54,18 @@ def modulestore(name='default'): settings.MODULESTORE[name]['OPTIONS']) return _MODULESTORES[name] + +_loc_singleton = None +def loc_mapper(): + """ + Get the loc mapper which bidirectionally maps Locations to Locators. Used like modulestore() as + a singleton accessor. + """ + # pylint: disable=W0603 + global _loc_singleton + # pylint: disable=W0212 + if _loc_singleton is None: + # instantiate + _loc_singleton = LocMapperStore(settings.modulestore_options) + return _loc_singleton + diff --git a/common/lib/xmodule/xmodule/modulestore/LocMapperStore.py b/common/lib/xmodule/xmodule/modulestore/loc_mapper_store.py similarity index 97% rename from common/lib/xmodule/xmodule/modulestore/LocMapperStore.py rename to common/lib/xmodule/xmodule/modulestore/loc_mapper_store.py index b71f647a27..06d99cc664 100644 --- a/common/lib/xmodule/xmodule/modulestore/LocMapperStore.py +++ b/common/lib/xmodule/xmodule/modulestore/loc_mapper_store.py @@ -1,28 +1,15 @@ ''' Method for converting among our differing Location/Locator whatever reprs ''' -from __future__ import absolute_import from random import randint import re import pymongo -from django.conf import settings from xmodule.modulestore.exceptions import InvalidLocationError, ItemNotFoundError, DuplicateItemError from xmodule.modulestore.locator import BlockUsageLocator from xmodule.modulestore.mongo import draft from xmodule.modulestore import Location -def loc_mapper(): - """ - Get the loc mapper which bidirectionally maps Locations to Locators. Used like modulestore() as - a singleton accessor. - """ - # pylint: disable=W0212 - if LocMapperStore._singleton is None: - # instantiate - LocMapperStore(settings.modulestore_options) - return LocMapperStore._singleton - class LocMapperStore(object): ''' This store persists mappings among the addressing schemes. At this time, it's between the old i4x Location @@ -38,8 +25,6 @@ class LocMapperStore(object): or dominant store, but that's not a requirement. This store creates its own connection. ''' - _singleton = None - def __init__(self, host, db, collection, port=27017, user=None, password=None, **kwargs): ''' Constructor @@ -55,7 +40,6 @@ class LocMapperStore(object): self.location_map = self.db[collection + '.location_map'] self.location_map.write_concern = {'w': 1} - LocMapperStore._singleton = self # location_map functions diff --git a/common/lib/xmodule/xmodule/modulestore/tests/test_location_mapper.py b/common/lib/xmodule/xmodule/modulestore/tests/test_location_mapper.py index f4addd9ee9..95e9bc53d0 100644 --- a/common/lib/xmodule/xmodule/modulestore/tests/test_location_mapper.py +++ b/common/lib/xmodule/xmodule/modulestore/tests/test_location_mapper.py @@ -8,7 +8,7 @@ import uuid from xmodule.modulestore import Location from xmodule.modulestore.locator import BlockUsageLocator from xmodule.modulestore.exceptions import ItemNotFoundError, DuplicateItemError -from xmodule.modulestore.LocMapperStore import LocMapperStore +from xmodule.modulestore.loc_mapper_store import LocMapperStore class TestLocationMapper(unittest.TestCase):