Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

copy any extra resources when converting

Files that were listed in the manifest weren't getting
copied over to the qti 2.0 output. This copies all those
files and puts them in a sinle resource object in the
output manifest file

Change-Id: Ie01055da7a42dd5783465ac215f11a751b0398ce
Reviewed-on: https://gerrit.instructure.com/6101
Reviewed-by: Brian Palmer <brianp@instructure.com>
Tested-by: Bracken Mosbacker <bracken@instructure.com>
  • Loading branch information...
commit 0df4e37d111843895ffaa598783f95d33fd8eeb5 1 parent 6e2b2e3
@bracken bracken authored
Showing with 92 additions and 1 deletion.
  1. +4 −1 lib/imscp.py
  2. +88 −0 lib/imsqtiv1.py
View
5 lib/imscp.py
@@ -253,8 +253,11 @@ def DumpToDirectory (self,path,create_error_files=None):
f.close()
else:
try:
+ dir = os.path.split(filepath)[0]
+ if not os.path.exists(dir):
+ os.makedirs(dir)
copyfile(self.dataPath,filepath)
- except IOError:
+ except IOError as (errno, strerror):
print 'Problem copying "%s" -> "%s"'%(self.dataPath,filepath)
if create_error_files:
f=codecs.open(filepath,'w',"utf8")
View
88 lib/imsqtiv1.py
@@ -296,6 +296,87 @@ def CheckLocation (self, expected_parents, tag, do_assert=True):
return True
+class Manifest(QTIObjectV1):
+ def __init__(self, name, attrs, parent):
+ self.resource=CPResource()
+ self.resource.SetType("webcontent")
+ self.parent = parent
+ self.files={}
+ self.path=None
+ self.cp=None
+
+ def SetPath (self,path):
+ self.path=path
+
+ def SetCP(self,cp):
+ self.cp=cp
+ self.cp.AddResource(self.resource)
+
+ def AddCPFile (self,uri):
+ print "\n\nHref: %s" % uri
+ if uri[-4:].lower() in ['.xml', '.dat', '.qti']:
+ return uri
+ if self.files.has_key(uri):
+ # We've already added this file to the content package
+ return self.files[uri]
+ cpf=CPFile()
+ cpf.SetHREF(uri)
+ root=self.GetRoot()
+ path=root.ResolveURI(uri)
+ cpf.SetDataPath(path)
+ self.resource.AddFile(cpf,0)
+ self.files[uri]=uri
+ return uri
+
+ def ResolveURI (self,uri):
+ # The base URI of this XML file is self.path
+ # resolve URI to make it a full path
+ path,discard=os.path.split(self.path)
+ segments=string.split(uri,'/')
+ for segment in segments:
+ if segment==".":
+ continue
+ elif segment=="..":
+ path,discard=os.path.split(path)
+ else:
+ path=os.path.join(path,DecodePathSegment(segment))
+ return path
+
+class Resources(QTIObjectV1):
+ def __init__(self, name, attrs, parent):
+ self.parent = parent
+ self.in_manifest = self.CheckLocation((Manifest),"<resources>", False)
+ if self.in_manifest:
+ self.manifest = parent
+
+ def AddCPFile(self, uri):
+ if self.in_manifest:
+ self.manifest.AddCPFile(uri)
+
+class Resource(QTIObjectV1):
+ def __init__(self, name, attrs, parent):
+ self.parent = parent
+ self.in_manifest = self.CheckLocation((Resources),"<resources>", False)
+ if self.in_manifest:
+ self.manifest = parent
+
+ def AddCPFile(self, uri):
+ if self.in_manifest:
+ self.manifest.AddCPFile(uri)
+
+class File(QTIObjectV1):
+ def __init__(self, name, attrs, parent):
+ self.parent = parent
+ self.in_manifest = self.CheckLocation((Resource),"<file>", False)
+ if self.in_manifest:
+ self.manifest = parent
+ self.ParseAttributes(attrs)
+
+ def SetAttribute_href (self,href):
+ if self.in_manifest:
+ self.manifest.AddCPFile(href)
+
+
# Unsupported
# -----------
#
@@ -5805,6 +5886,7 @@ def CloseObject (self):
'durlte':Unsupported,
'fieldentry':FieldEntry,
'fieldlabel':FieldLabel,
+ 'file':File,
'flow':FlowV1,
'flow_label':FlowLabel,
'flow_mat':FlowMat,
@@ -5823,6 +5905,7 @@ def CloseObject (self):
'itemproc_extension':ItemProcExtension,
'itemref':ItemRef,
'itemrubric':Unsupported,
+ 'manifest':Manifest,
'map_output':Unsupported,
'mat_extension':WCTMatExtension,
'mat_formattedtext':BBMatFormattedText,
@@ -5898,6 +5981,8 @@ def CloseObject (self):
'render_fib':RenderFib,
'render_hotspot':RenderHotspot,
'render_slider':RenderSlider,
+ 'resources':Resources,
+ 'resource':Resource,
'respcond_extension':Unsupported,
'respcondition':RespCondition,
'response_extension':Unsupported,
@@ -6046,6 +6131,9 @@ def startElement(self, name, attrs):
self.cObject.SetCP(self.cp)
self.cObject.SetPath(self.currPath)
self.cObject.SetParser(self)
+ if isinstance(self.cObject,Manifest):
+ self.cObject.SetCP(self.cp)
+ self.cObject.SetPath(self.currPath)
if self.options.prepend_path and isinstance(self.cObject,(MatThing)):
self.cObject.prepend_path = self.options.prepend_path
else:
Please sign in to comment.
Something went wrong with that request. Please try again.