def save_python(cls, block, path): """ This method save the port in user space in python extension. Returns: * **Types** (:class:`boolean<boolean>`) """ parser = PythonParser() parser.class_name = block.label.replace(' ', '') parser.dependencies = [{'from':'mosaicode.model.blockmodel', 'import':'BlockModel'}] parser.inherited_classes = ['BlockModel'] parser.setAttribute('id', block.id) parser.setAttribute('type', block.type) parser.setAttribute('language', block.language) parser.setAttribute('framework', 'python') parser.setAttribute('help', block.help) parser.setAttribute('label', block.label) parser.setAttribute('color', block.color) parser.setAttribute('group', block.group) parser.setAttribute('help', block.help) parser.setAttribute('ports', block.ports) parser.setAttribute('properties', block.properties) parser.setAttribute('codes', block.codes) if not Persistence.create_dir(path): return False try: file_name = path + block.label.lower().replace(' ', '_') + ".py" parser.save(file_name) except IOError as e: return False return True
def save_xml(cls, code_template, path): """ This method save the code_template in user space. Returns: * **Types** (:class:`boolean<boolean>`) """ code_template.source = "xml" parser = XMLParser() parser.addTag(CodeTemplatePersistence.tag_name) for prop in CodeTemplatePersistence.properties: if hasattr(code_template, prop): parser.setTagAttr(CodeTemplatePersistence.tag_name, prop, code_template.__dict__[prop]) parser.appendToTag(CodeTemplatePersistence.tag_name, 'code_parts') for key in code_template.code_parts: parser.appendToTag('code_parts', 'code_part', value=key.strip()) if not Persistence.create_dir(path): return False try: file_name = code_template.name code_template_file = file(os.path.join(path, file_name + '.xml'), 'w') code_template_file.write(parser.prettify()) code_template_file.close() except IOError as e: return False return True
def save_xml(cls, port, path): """ This method save the port in user space. Returns: * **Types** (:class:`boolean<boolean>`) """ port.source = "xml" parser = XMLParser() parser.addTag(tag_name) parser.setTagAttr(tag_name, 'type', port.type) parser.setTagAttr(tag_name, 'language', port.language) parser.setTagAttr(tag_name, 'hint', port.hint) parser.setTagAttr(tag_name, 'color', port.color) parser.setTagAttr(tag_name, 'multiple', port.multiple) parser.setTagAttr(tag_name, 'var_name', port.var_name) parser.appendToTag(tag_name, 'code').string = str(port.code) if not Persistence.create_dir(path): return False try: file_name = port.hint port_file = file(os.path.join(path, file_name + '.xml'), 'w') port_file.write(parser.prettify()) port_file.close() except IOError as e: return False return True
def save_python(cls, code_template, path): """ This method save the codetemplate in user space in python extension. Returns: * **Types** (:class:`boolean<boolean>`) """ parser = PythonParser() parser.class_name = code_template.name.replace(' ', '') parser.dependencies = [{ 'from': 'mosaicode.model.codetemplate', 'import': 'CodeTemplate' }] parser.inherited_classes = ['CodeTemplate'] parser.setAttribute('name', code_template.name) parser.setAttribute('description', code_template.description) parser.setAttribute('language', code_template.language) parser.setAttribute('command', code_template.command) # parser.setAttribute('extension', code_template.extension) # parser.setAttribute('code', code_template.code) parser.setAttribute('code_parts', code_template.code_parts) if not Persistence.create_dir(path): return False file_name = path + code_template.name.lower().replace(' ', '_') + ".py" try: parser.save(file_name) except IOError as e: return False return True
def save_python(cls, port, path): """ This method save the port in user space in python extension. Returns: * **Types** (:class:`boolean<boolean>`) """ parser = PythonParser() parser.class_name = port.label.replace(' ', '') parser.dependencies = [{ 'from': 'mosaicode.model.port', 'import': 'Port' }] parser.inherited_classes = ['Port'] parser.setAttribute('type', port.type) parser.setAttribute('language', port.language) parser.setAttribute('label', port.label) parser.setAttribute('color', port.color) parser.setAttribute('multiple', port.multiple) parser.setAttribute('code', str(port.code)) if not Persistence.create_dir(path): return False try: file_name = path + port.label.lower().replace(' ', '_') + ".py" parser.save(file_name) except IOError as e: return False return True
def save(cls, port, path): """ This method save the port in user space. Returns: * **Types** (:class:`boolean<boolean>`) """ x = { "source": "JSON", "data": "PORT", "version": port.version, "type": port.type, "language": port.language, "hint": port.hint, "color": port.color, "multiple": port.multiple, "var_name": port.var_name, "code": port.code } if not Persistence.create_dir(path): return False try: data_file = open(os.path.join(path, port.type + '.json'), 'w') data_file.write(json.dumps(x, indent=4)) data_file.close() except IOError as e: return False return True
def save_xml(cls, block, path=None): """ This method save the block in user space. Returns: * **Types** (:class:`boolean<boolean>`) """ block.source = "xml" parser = XMLParser() main = parser.addTag(tag_name) parser.setTagAttr(tag_name, 'type', block.type) parser.setTagAttr(tag_name, 'language', block.language) parser.setTagAttr(tag_name, 'extension', block.extension) parser.setTagAttr(tag_name, 'help', block.help) parser.setTagAttr(tag_name, 'label', block.label) parser.setTagAttr(tag_name, 'color', block.color) parser.setTagAttr(tag_name, 'group', block.group) parser.setTagAttr(tag_name, 'maxIO', block.maxIO) parser.setTagAttr(tag_name, 'codes', block.codes) parser.appendToTag(tag_name, 'properties') for key in block.properties: parser.appendToTag('properties', 'property', value=key) parser.appendToTag(tag_name, 'ports') for port in block.ports: parser.appendToTag('ports', 'port', conn_type=port.conn_type, name_=port.name, label=port.label, type_=port.type) if (path is not None) and not Persistence.create_dir(path): return False if (path is None) and (block.file is not None): path = block.file elif (path is not None): file_name = block.label path = os.path.join(path, file_name + '.xml') else: return False parser.setTagAttr(tag_name, 'file', path) try: block_file = file(path, 'w') block_file.write(parser.getXML()) block_file.close() except IOError as e: return False return True
def save_xml(cls, code_template, path): """ This method save the code_template in user space. Returns: * **Types** (:class:`boolean<boolean>`) """ code_template.source = "xml" parser = XMLParser() parser.addTag(tag_name) parser.setTagAttr(tag_name, 'name', code_template.name) parser.setTagAttr(tag_name, 'type', code_template.type) parser.setTagAttr(tag_name, 'description', code_template.description) parser.setTagAttr(tag_name, 'language', code_template.language) parser.setTagAttr(tag_name, 'command', code_template.command) parser.appendToTag(tag_name, 'code_parts') for key in code_template.code_parts: parser.appendToTag('code_parts', 'code_part', value=key.strip()) parser.appendToTag(tag_name, 'files') for key in code_template.files: parser.appendToTag('files', 'file', name_=key, value=code_template.files[key]) parser.appendToTag(tag_name, 'properties') for key in code_template.properties: parser.appendToTag('properties', 'property', value=key) if not Persistence.create_dir(path): return False try: file_name = code_template.name code_template_file = file(os.path.join(path, file_name + '.xml'), 'w') code_template_file.write(parser.prettify()) code_template_file.close() except IOError as e: from mosaicode.system import System System() System.log(e) return False return True
def save_xml(cls, block, path): """ This method save the block in user space. Returns: * **Types** (:class:`boolean<boolean>`) """ block.source = "xml" parser = XMLParser() main = parser.addTag(tag_name) parser.setTagAttr(tag_name,'type', block.type) parser.setTagAttr(tag_name,'language', block.language) parser.setTagAttr(tag_name,'framework', block.framework) parser.setTagAttr(tag_name,'label', block.label) parser.setTagAttr(tag_name,'group', block.group) parser.setTagAttr(tag_name,'color', block.color) parser.setTagAttr(tag_name,'help', block.help) for code in block.codes: parser.appendToTag(tag_name, code, value=block.codes[code]) parser.appendToTag(tag_name, 'properties') for key in block.properties: parser.appendToTag('properties', 'property', value=key) parser.appendToTag(tag_name, 'ports') for port in block.ports: parser.appendToTag('ports', 'port', conn_type=port.conn_type, name_=port.name, label=port.label, type_=port.type) if not Persistence.create_dir(path): return False try: file_name = path + block.type + ".xml" block_file = file(os.path.expanduser(file_name), 'w') block_file.write(parser.getXML()) block_file.close() except IOError as e: return False return True
def save(cls, code_template, path): """ This method save the code_template in user space. Returns: * **Types** (:class:`boolean<boolean>`) """ x = { "source": "JSON", "data": "CODE_TEMPLATE", "version": code_template.version, 'name': code_template.name, 'type': code_template.type, 'description': code_template.description, 'language': code_template.language, 'command': code_template.command, "code_parts": code_template.code_parts, "properties": [], "codes": {} } for key in code_template.properties: x["properties"].append(key) for key in code_template.codes: x["codes"][key] = code_template.codes[key] if not Persistence.create_dir(path): from mosaicode.system import System as System System.log("Problem creating dir to save Code templates") return False try: file_name = code_template.name data_file = open(os.path.join(path, file_name + '.json'), 'w') data_file.write(json.dumps(x, indent=4)) data_file.close() except IOError as e: from mosaicode.system import System as System System.log("Problem saving Code template: " + e) return False return True
def save(cls, prefs, path): """ This method save the preference in user space. Returns: * **Types** (:class:`boolean<boolean>`) """ x = { 'data': "PREFERENCES", 'author': prefs.author, 'license': prefs.license, 'version': prefs.version, 'default_directory': prefs.default_directory, 'default_filename': prefs.default_filename, 'grid': prefs.grid, 'width': prefs.width, 'height': prefs.height, 'hpaned_work_area': prefs.hpaned_work_area, 'vpaned_bottom': prefs.vpaned_bottom, 'vpaned_left': prefs.vpaned_left, 'recent_files': [] } for key in prefs.recent_files: x['recent_files'].append(key) if not Persistence.create_dir(path): return False try: file_name = path + "/" + prefs.conf_file_path + ".json" data_file = open(file_name, 'w') data_file.write(json.dumps(x, indent=4)) data_file.close() except IOError as e: return False return True
def test_create_dir(self): Persistence.create_dir(None) Persistence.create_dir("/etc/") Persistence.create_dir("/tmp/test") os.rmdir("/tmp/test")
def save(cls, block, path=None): """ This method save the block in user space. Returns: * **Types** (:class:`boolean<boolean>`) """ x = { "source": "JSON", "data": "BLOCK", "version": block.version, "type": block.type, "language": block.language, "extension": block.extension, "help": block.help, "label": block.label, "color": block.color, "group": block.group, "codes": [], "properties": [], "ports": [] } for key in block.codes: x["codes"].append({"name": key, "code": block.codes[key]}) for key in block.properties: x["properties"].append(key) for port in block.ports: x["ports"].append({ "conn_type": port.conn_type, "name": port.name, "label": port.label, "type": port.type }) if (path is not None) and not Persistence.create_dir(path): from mosaicode.system import System as System System.log("Problem saving Blocks") return False if (path is None) and (block.file is not None): path = block.file elif (path is not None): file_name = block.label path = os.path.join(path, file_name + '.json') else: from mosaicode.system import System as System System.log("Problem saving Blocks") return False try: data_file = open(path, 'w') data_file.write(json.dumps(x, indent=4)) data_file.close() except IOError as e: from mosaicode.system import System as System System.log("Problem saving Blocks") return False return True