Commit b29649c4 by Calen Pennington

Allow for more flexible candidates for replacement filepaths

parent 379c6d16
......@@ -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:],
]
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):
......
......@@ -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:
......
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