示例#1
0
class TemplatesetController:
	def __init__(self,controller):
		'''
		initialize TemplatesetController
		'''
		self.controller = controller
		self.emailcontroller = self.controller.getEmailController()
		self.model = TemplatesetModel(self,settings.DB_PATH,settings.TEMPLATESETS_REPO,settings.TEMPLATESETS_PATH)

	def getTemplatesetPath(self,setname,version):
		'''
		Return the path of templateset named setname of version
		@param setname: name of templateset to get path of
		@type setname: wx.Notebook
		@param version: version of templateset
		@type version: wx.Notebook
		@return: templateset path
		@rtype: wx.Notebook
		'''
		tspath = self.model.getTemplatesetPath(setname,str(version))
		if tspath is not None:
			return tspath
		else:
			templatesetpath = self.model.dlTemplateset(name,version)
			self.model.addTemplateset(name,version,templatesetpath)
			return templatesetpath

	def validateTemplateset(self,templatesetdir):
		'''
		validate ALL files of a template set: config.json & all templates
		@param templatesetdir: name of the templateset directory containing config.json file for the templateset
		@type templatesetdir: string
		'''
		configschemafile = open(settings.CONFIG_SCHEMA_PATH,'r')
		configschema = simplejson.load(configschemafile)
		try:
			configfile = open(settings.TEMPLATESETS_PATH+templatesetdir+'/config.json','r')
		except IOError:
			raise IOError,"Templateset directory has no config.json."

		try:
			configdata = simplejson.load(configfile)
		except JSONDecodeError, e:
			print "config.json JSON Decoding error: ",e
			raise TemplatesetError("simplejson.load( config.json ) raised JSONDecodeError")
		
		try:
			validictory.validate(configdata,configschema)
		except SchemaError, e:
			print "config.json Schema validation error: ",e
			raise TemplatesetError("validictory.validate( config.json, config-schema.json) raised SchemaError")
示例#2
0
	def __init__(self,controller):
		'''
		initialize TemplatesetController
		'''
		self.controller = controller
		self.emailcontroller = self.controller.getEmailController()
		self.model = TemplatesetModel(self,settings.DB_PATH,settings.TEMPLATESETS_REPO,settings.TEMPLATESETS_PATH)