From b29649c49b6b7e3dfe398683d03c5f43df6035dc Mon Sep 17 00:00:00 2001 From: Calen Pennington Date: Wed, 11 Jul 2012 23:00:56 -0400 Subject: [PATCH] Allow for more flexible candidates for replacement filepaths --- common/lib/xmodule/xmodule/capa_module.py | 9 ++++++--- common/lib/xmodule/xmodule/html_module.py | 12 ++++++++---- common/lib/xmodule/xmodule/xml_module.py | 10 ++++++---- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/common/lib/xmodule/xmodule/capa_module.py b/common/lib/xmodule/xmodule/capa_module.py index f6f9bd52ec..527b0a6fa8 100644 --- a/common/lib/xmodule/xmodule/capa_module.py +++ b/common/lib/xmodule/xmodule/capa_module.py @@ -6,6 +6,7 @@ import logging import traceback import re import StringIO +import os from datetime import timedelta from lxml import etree @@ -507,6 +508,8 @@ class CapaDescriptor(RawDescriptor): # TODO (cpennington): Delete this method once all fall 2012 course are being # edited in the cms @classmethod - def backcompat_path(cls, path): - if path.startswith('problem'): - return 'problems/' + path[7:] + def backcompat_paths(cls, path): + return [ + 'problems/' + path[8:], + path[8:], + ] diff --git a/common/lib/xmodule/xmodule/html_module.py b/common/lib/xmodule/xmodule/html_module.py index a5554a8403..1555b96f82 100644 --- a/common/lib/xmodule/xmodule/html_module.py +++ b/common/lib/xmodule/xmodule/html_module.py @@ -1,4 +1,5 @@ import logging +import os from lxml import etree from xmodule.x_module import XModule @@ -31,12 +32,15 @@ class HtmlDescriptor(RawDescriptor): # TODO (cpennington): Delete this method once all fall 2012 course are being # edited in the cms @classmethod - def backcompat_path(cls, path): - if path.startswith('html/html'): - path = path[5:] + def backcompat_paths(cls, path): if path.endswith('.html.html'): path = path[:-5] - return path + candidates = [] + while os.sep in path: + candidates.append(path) + _, _, path = path.partition(os.sep) + + return candidates @classmethod def file_to_xml(cls, file_object): diff --git a/common/lib/xmodule/xmodule/xml_module.py b/common/lib/xmodule/xmodule/xml_module.py index 96d7da3fb1..b0bfaebab5 100644 --- a/common/lib/xmodule/xmodule/xml_module.py +++ b/common/lib/xmodule/xmodule/xml_module.py @@ -162,10 +162,12 @@ class XmlDescriptor(XModuleDescriptor): # in the correct format. # This should go away once the CMS is online and has imported all current (fall 2012) # courses from xml - if not system.resources_fs.exists(filepath) and hasattr(cls, 'backcompat_path'): - new_filepath = cls.backcompat_path(filepath) - if new_filepath is not None and system.resources_fs.exists(new_filepath): - filepath = new_filepath + if not system.resources_fs.exists(filepath) and hasattr(cls, 'backcompat_paths'): + candidates = cls.backcompat_paths(filepath) + for candidate in candidates: + if system.resources_fs.exists(candidate): + filepath = candidate + break log.debug('filepath=%s, resources_fs=%s' % (filepath, system.resources_fs)) try: