Commit 95722486 by Calen Pennington

Allow for more flexible candidates for replacement filepaths

parent 4d821541
...@@ -6,6 +6,7 @@ import logging ...@@ -6,6 +6,7 @@ import logging
import traceback import traceback
import re import re
import StringIO import StringIO
import os
from datetime import timedelta from datetime import timedelta
from lxml import etree from lxml import etree
...@@ -507,6 +508,8 @@ class CapaDescriptor(RawDescriptor): ...@@ -507,6 +508,8 @@ class CapaDescriptor(RawDescriptor):
# TODO (cpennington): Delete this method once all fall 2012 course are being # TODO (cpennington): Delete this method once all fall 2012 course are being
# edited in the cms # edited in the cms
@classmethod @classmethod
def backcompat_path(cls, path): def backcompat_paths(cls, path):
if path.startswith('problem'): return [
return 'problems/' + path[7:] 'problems/' + path[8:],
path[8:],
]
import logging import logging
import os
from lxml import etree from lxml import etree
from xmodule.x_module import XModule from xmodule.x_module import XModule
...@@ -31,12 +32,15 @@ class HtmlDescriptor(RawDescriptor): ...@@ -31,12 +32,15 @@ class HtmlDescriptor(RawDescriptor):
# TODO (cpennington): Delete this method once all fall 2012 course are being # TODO (cpennington): Delete this method once all fall 2012 course are being
# edited in the cms # edited in the cms
@classmethod @classmethod
def backcompat_path(cls, path): def backcompat_paths(cls, path):
if path.startswith('html/html'):
path = path[5:]
if path.endswith('.html.html'): if path.endswith('.html.html'):
path = path[:-5] path = path[:-5]
return path candidates = []
while os.sep in path:
candidates.append(path)
_, _, path = path.partition(os.sep)
return candidates
@classmethod @classmethod
def file_to_xml(cls, file_object): def file_to_xml(cls, file_object):
......
...@@ -162,10 +162,12 @@ class XmlDescriptor(XModuleDescriptor): ...@@ -162,10 +162,12 @@ class XmlDescriptor(XModuleDescriptor):
# in the correct format. # in the correct format.
# This should go away once the CMS is online and has imported all current (fall 2012) # This should go away once the CMS is online and has imported all current (fall 2012)
# courses from xml # courses from xml
if not system.resources_fs.exists(filepath) and hasattr(cls, 'backcompat_path'): if not system.resources_fs.exists(filepath) and hasattr(cls, 'backcompat_paths'):
new_filepath = cls.backcompat_path(filepath) candidates = cls.backcompat_paths(filepath)
if new_filepath is not None and system.resources_fs.exists(new_filepath): for candidate in candidates:
filepath = new_filepath if system.resources_fs.exists(candidate):
filepath = candidate
break
log.debug('filepath=%s, resources_fs=%s' % (filepath, system.resources_fs)) log.debug('filepath=%s, resources_fs=%s' % (filepath, system.resources_fs))
try: 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