def load(cls, file_name): """ This method loads the code_template from XML file. Returns: * **Types** (:class:`boolean<boolean>`) """ # load the code_template if os.path.exists(file_name) is False: return parser = XMLParser(file_name) if parser.getTag(tag_name) is None: return None try: code_template = CodeTemplate() code_template.name = parser.getTagAttr(tag_name, "name") code_template.type = parser.getTagAttr(tag_name, "type") code_template.description = parser.getTagAttr( tag_name, "description") code_template.language = parser.getTagAttr(tag_name, "language") code_template.extension = parser.getTagAttr(tag_name, "extension") code_template.source = parser.getTagAttr(tag_name, "source") code_template.command = parser.getTag(tag_name).getTag( "command").getText() code_template.code = parser.getTag(tag_name).getTag( "code").getText() except: return None if code_template.name == "": return None return code_template
def __save(self): code_template = CodeTemplate() code_template.name = self.name.get_value() code_template.type = self.type.get_value() code_template.description = self.description.get_value() code_template.language = self.language.get_value() code_template.command = self.command.get_value() code_template.extension = self.extension.get_value() code_template.code = self.code.get_value() self.code_template_manager.add_code_template(code_template)
def test_add_code_template(self): #code_template = None #self.assertIsNone(self.main_control.add_code_template(code_template)) from mosaicode.model.codetemplate import CodeTemplate code_template = CodeTemplate() code_template.type = "c" code_template.name = "TESTE" code_template.source = "xml" self.assertIsNone(self.main_control.add_code_template(code_template))
def load_xml(cls, file_name): """ This method loads the code_template from XML file. Returns: * **Types** (:class:`boolean<boolean>`) """ # load the code_template if os.path.exists(file_name) is False: return None if os.path and os.path.isdir(file_name): return None parser = XMLParser(file_name) if parser.getTag(tag_name) is None: return None ct = parser.getTag(tag_name) code_template = CodeTemplate() code_template.name = parser.getTagAttr(tag_name, "name") code_template.type = parser.getTagAttr(tag_name, "type") code_template.description = parser.getTagAttr(tag_name, "description") code_template.language = parser.getTagAttr(tag_name, "language") code_template.command = parser.getTagAttr(tag_name, "command") parts = parser.getTag(tag_name) parts = parts.getTag("code_parts") if parts: parts = parts.getChildTags("code_part") for part in parts: code_template.code_parts.append(part.getAttr("value")) parts = parser.getTag(tag_name) parts = parts.getTag("files") if parts: parts = parts.getChildTags("file") for part in parts: code_template.files[part.getAttr("name_")] = part.getAttr( "value") parts = parser.getTag(tag_name) parts = parts.getTag("properties") if parts: parts = parts.getChildTags("property") for part in parts: code_template.properties.append( ast.literal_eval(part.getAttr("value"))) if code_template.name == "": return None return code_template
def load(cls, file_name): """ This method loads the code_template from XML file. Returns: * **Types** (:class:`boolean<boolean>`) """ # load the code_template if os.path.exists(file_name) is False: return None if os.path and os.path.isdir(file_name): return None code_template = CodeTemplate() data = "" try: data_file = open(file_name, 'r') data = json.load(data_file) data_file.close() if data["data"] != "CODE_TEMPLATE": return None code_template.version = data["version"] code_template.name = data["name"] code_template.type = data["type"] code_template.description = data["description"] code_template.language = data["language"] code_template.command = data["command"] props = data["properties"] for prop in props: code_template.properties.append(prop) codes = data["codes"] if codes: for key in codes: code_template.codes[key] = codes[key] parts = data["code_parts"] for part in parts: code_template.code_parts.append(part.strip()) except Exception as e: print(e) return None if code_template.name == "": return None return code_template
def test_add_code_template(self): code_template = CodeTemplate() self.assertIsNone( self.codetemplatemanager.add_code_template(code_template)) code_template.type = "Language Test" code_template.name = "Testando Code Template" code_template.description = "Um teste para code template em Add Code Template" code_template.language = "" code_template.command = "" code_template.extension = "teste" code_template.code = "Testando 1 2 3" code_template.source = "python" self.assertIsNone( self.codetemplatemanager.add_code_template(code_template))
def load(cls, file_name): """ This method loads the code_template from XML file. Returns: * **Types** (:class:`boolean<boolean>`) """ # load the code_template if os.path.exists(file_name) is False: return None parser = XMLParser(file_name) if parser.getTag(tag_name) is None: return None try: code_template = CodeTemplate() code_template.name = parser.getTagAttr(tag_name, "name") code_template.type = parser.getTagAttr(tag_name, "type") code_template.description = parser.getTagAttr( tag_name, "description") code_template.language = parser.getTagAttr(tag_name, "language") code_template.command = parser.getTag(tag_name).getTag( "command").getText() code_template.extension = parser.getTagAttr(tag_name, "extension") code_template.code = parser.getTag(tag_name).getTag( "code").getText() code_parts = parser.getTag(tag_name).getTag( "code_parts").getChildTags("code_part") for code_part in code_parts: code_template.code_parts.append(code_part.getAttr("value")) except Exception as e: print e return None if code_template.name == "": return None return code_template
def create_code_template(self): code_template = CodeTemplate() code_template.name = "webaudio" code_template.type = "Test" code_template.language = "Test" code_template.command = "python\n" code_template.description = "Javascript / webaudio code template" code_template.code_parts = [ "onload", "function", "declaration", "execution", "html" ] code_template.properties = [{ "name": "title", "label": "Title", "value": "Title", "type": MOSAICODE_STRING }] code_template.files["index.html"] = r""" <html> <head> <meta http-equiv="Cache-Control" content="no-store" /> <!-- $author$ $license$ --> <title>$prop[title]$</title> <link rel="stylesheet" type="text/css" href="theme.css"> <script src="functions.js"></script> <script> $single_code[function]$ function loadme(){ $single_code[onload]$ return; } var context = new (window.AudioContext || window.webkitAudioContext)(); //declaration block $code[declaration]$ //execution $code[execution]$ //connections $connections$ </script> </head> <body onload='loadme();'> $code[html]$ </body> </html> """ code_template.files["theme.css"] = r""" /* Developed by: $author$ */ html, body { background: #ffeead; color: #ff6f69; } h1, p { color: #ff6f69; } #navbar a { color: #ff6f69; } .item { background: #ffcc5c; } button { background: #ff6f69; color: #ffcc5c; } """ code_template.files["functions.js"] = r""" /* Developed by: $author$ */ $single_code[function]$ """ System.add_code_template(code_template) return code_template