Skip to content
Browse files

copy files referenced in superfluous manifest files

some vendors create a manifest file for each question and
related file, this makes it so that the files referenced
in there are copied and become part of the single manifest
when finished. It also grabs the expected output name from
the webct meta data.

refs #8051 #8671

Change-Id: I0e3f3211123dd5301335538f5f332717cc457746
Reviewed-on: https://gerrit.instructure.com/10936
Tested-by: Jenkins <jenkins@instructure.com>
Reviewed-by: Simon Williams <simon@instructure.com>
  • Loading branch information...
1 parent 805367b commit 385548ab9e605f36ce652415a5d6e3c9b847a8bc @bracken bracken committed May 22, 2012
Showing with 88 additions and 11 deletions.
  1. +13 −0 lib/imscp.py
  2. +75 −11 lib/imsqtiv1.py
View
13 lib/imscp.py
@@ -196,10 +196,23 @@ def GetQTIMD (self):
return self.qtiMD
def AddFile (self,cpf,entryPoint=0):
+ for file in self.files:
+ if file.href == cpf.href:
+ return
self.files.append(cpf)
if entryPoint:
self.entryPoint=cpf
+ def update_file_path(self, uri, dest_path, data_path):
+ cpf = None
+ for file in self.files:
+ if file.href == uri or file.href == dest_path or file.dataPath == data_path:
+ cpf = file
+ break
+ if cpf:
+ cpf.href = dest_path
+ cpf.dataPath = data_path
+
def DumpToDirectory (self,path,create_error_files=None):
for f in self.files:
f.DumpToDirectory(path,create_error_files)
View
86 lib/imsqtiv1.py
@@ -306,14 +306,14 @@ def __init__(self, name, attrs, parent):
self.cp=None
def SetPath (self,path):
- self.path=path
+ if self.path is None:
+ 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):
@@ -342,6 +342,13 @@ def ResolveURI (self,uri):
path=os.path.join(path,DecodePathSegment(segment))
return path
+ def update_file_path(self, path):
+ if len(self.files) == 1:
+ uri = self.files.values()[0]
+ if uri != path:
+ self.resource.update_file_path(uri, path, self.GetRoot().ResolveURI(uri))
+
+
class Resources(QTIObjectV1):
def __init__(self, name, attrs, parent):
self.parent = parent
@@ -779,6 +786,49 @@ def CloseObject (self):
self.parent.AppendElement(xhtml_text(self.data))
+# webct:ContentObject
+# -------------
+#
+class WCTContentObject(QTIObjectV1):
+ def __init__(self,name,attrs,parent):
+ QTIObjectV1.__init__(self,name,attrs,parent)
+ self.file_name = None
+ self.file_path = None
+ self.co_type
+ self.in_manifest = self.CheckLocation((Manifest),"<webct:ContentObject>", False)
+ self.ParseAttributes(attrs)
+
+ def SetAttribute_webct_coType (self,type):
+ self.co_type = type
+
+ def CloseObject(self):
+ if self.in_manifest and self.co_type == "webct.file" and self.file_name and self.file_path:
+ self.parent.update_file_path(os.path.join(self.file_path, self.file_name))
+
+# webct:Name
+# -------------
+#
+class WCTName(QTIObjectV1):
+ def __init__(self,name,attrs,parent):
+ QTIObjectV1.__init__(self,name,attrs,parent)
+ self.in_content_object = self.CheckLocation((WCTContentObject),"<webct:WCTName>", False)
+
+ def AddData (self,data):
+ if self.in_content_object:
+ self.parent.file_name = data
+
+# webct:Path
+# -------------
+#
+class WCTPath(QTIObjectV1):
+ def __init__(self,name,attrs,parent):
+ QTIObjectV1.__init__(self,name,attrs,parent)
+ self.in_content_object = self.CheckLocation((WCTContentObject),"<webct:WCTPath>", False)
+
+ def AddData (self,data):
+ if self.in_content_object:
+ self.parent.file_path = data
+
# material_table
# -------------
#
@@ -788,7 +838,7 @@ class WCTMaterialTable(QTIObjectV1):
def __init__(self,name,attrs,parent):
QTIObjectV1.__init__(self,name,attrs,parent)
self.PrintWarning('Warning: material_table not supported, looking inside for needed data')
-
+
def SetAttribute_label (self,id):
pass
@@ -3564,7 +3614,7 @@ def SetAttribute_label (self,value):
self.label=value
def SetAttribute_uri (self,value):
- self.uri=value
+ self.uri=value.lstrip('/')
def SetAttribute_entityref (self,value):
self.entityRef=value
@@ -6071,15 +6121,18 @@ def CloseObject (self):
'varsubset':VarSubset,
'varsubstring':VarSubstring,
'vocabulary':Vocabulary,
+ 'webct:answer':CalculatedAnswer,
'webct:calculated':CalculatedNode,
- 'webct:formula':CalculatedFormula,
- 'webct:var':WCTVar,
+ 'webct:calculated_answer':WCTCalculatedAnswer,
'webct:calculated_set':CalculatedVarSet,
'webct:calculated_var':WCTVar,
- 'webct:answer':CalculatedAnswer,
- 'webct:calculated_answer':WCTCalculatedAnswer,
+ 'webct:ContentObject':WCTContentObject,
+ 'webct:Name':WCTName,
+ 'webctfl:Path':WCTPath,
+ 'webct:formula':CalculatedFormula,
'webct:matching_ext_flow':WCTMatchingExtFlow,
- 'webct:matching_text_ext':WCTMatchingTextExt
+ 'webct:matching_text_ext':WCTMatchingTextExt,
+ 'webct:var':WCTVar,
}
class QTIParserV1(handler.ContentHandler, handler.ErrorHandler):
@@ -6093,6 +6146,8 @@ def __init__(self,options):
self.parser.setErrorHandler(self)
self.parser.setEntityResolver(self)
self.elements=QTIASI_ELEMENTS
+ self.manifest=None
+ self.manifest_path=None
if self.options.qmdExtensions:
self.elements['qmd_keywords']=QMDKeywords
self.elements['qmd_domain']=QMDDomain
@@ -6168,8 +6223,17 @@ def startElement(self, name, attrs):
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.currPath.endswith("imsmanifest.xml"):
+ self.cObject.SetCP(self.cp)
+ self.cObject.SetPath(self.currPath)
+ self.manifest = self.cObject
+ self.manifest_path = self.currPath.replace("imsmanifest.xml", '')
+ else:
+ if self.manifest:
+ self.cObject.SetCP(self.manifest.cp)
+ self.cObject.SetPath(self.manifest.path)
+ self.cObject.resource = self.manifest.resource
+
if self.options.prepend_path and isinstance(self.cObject,(MatThing)):
self.cObject.prepend_path = self.options.prepend_path
else:

0 comments on commit 385548a

Please sign in to comment.
Something went wrong with that request. Please try again.