def add_new_block(cls, block): # Save it from mosaicode.system import System System() path = System.get_user_dir() + "/extensions/" path = path + block.language + "/" + block.framework + "/" BlockPersistence.save_xml(block, path)
def export_python(cls): from mosaicode.system import System System() blocks = System.get_blocks() for block in blocks: print "Exporting block " + block BlockPersistence.save_python(blocks[block])
def export_python(cls): from mosaicode.system import System System() blocks = System.get_blocks() for block in blocks: path = System.get_user_dir() + "/extensions/" path = path + block.language + "/" + block.framework + "/" BlockPersistence.save_python(blocks[block], path)
def test_save_no_permission(self): # Create, save and load a empty block block = BlockModel() block.label = "Empty block" persistence = BlockPersistence.save_xml(block, "/no_permission") assert not persistence persistence = BlockPersistence.save_xml(block, "/etc") assert not persistence
def load(cls, file_name): """ This method loads the block from XML file. Returns: * **Types** (:class:`boolean<boolean>`) """ BlockPersistence.load(file_name)
def add_new_block(cls, block): # Save it from mosaicode.system import System System() path = os.path.join(System.get_user_dir(),"extensions") path = os.path.join(path, block.language) path = os.path.join(path, "blocks") path = os.path.join(path, block.extension) path = os.path.join(path, block.group) BlockPersistence.save(block, path)
class TestBlockPersistence(TestCase): def setUp(self): """Do the test basic setup.""" self.blockpersistence = BlockPersistence() # ----------------------------------------------------------------------x def test_load(self): # TESTANDO COM NOME DE ARQUIVO = None file_name = "" self.assertIsNone(self.blockpersistence.load(file_name)) # TESTANDO COM NOME DE ARQUIVO INEXISTENTE file_name = "/home/lucas/mosaicode/extensions/teste.py" self.assertIsNone(self.blockpersistence.load(file_name)) # TESTANDO COM NOME DE ARQUIVO FALSO (INCOMPATÍVEL) file_name = "/home/lucas/mosaicode/extensions/a.py" self.assertIsNone(self.blockpersistence.load(file_name)) # TESTANDO COM NOME DE ARQUIVO VERDADEIRO file_name = "/home/lucas/mosaicode/extensions/mosaicode.model.blockmodel.xml" self.assertIsNone(self.blockpersistence.load(file_name)) # TESTANDO COM NOME DE ARQUIVO VERDADEIRO MAS COM RETORNO file_name = "/home/lucas/mosaicode/extensions/mosaicode.model.blockmodel_teste.xml" self.assertIsNotNone(self.blockpersistence.load(file_name)) # ----------------------------------------------------------------------x def test_save(self): # NÃO TRABALHA COM None # block = None # self.assertTrue(self.blockpersistence.save(block)) diagram = Diagram(MainWindow()) block = Block(diagram, None) self.assertTrue(self.blockpersistence.save(block)) diagram = Diagram(MainWindow()) blockmodel = BlockModel(None) block = Block(diagram, blockmodel) block.type = "teste_blockpersistence" self.assertTrue(self.blockpersistence.save(block)) # ----------------------------------------------------------------------x def test_save_python(self): # NÃO TRABALHA COM None # block = None # self.assertFalse(self.blockpersistence.save_python(block)) diagram = Diagram(MainWindow()) block = Block(diagram, None) self.assertTrue(self.blockpersistence.save_python(block)) diagram = Diagram(MainWindow()) blockmodel = BlockModel(None) block = Block(diagram, blockmodel) block.type = "teste_blockpersistence" self.assertTrue(self.blockpersistence.save_python(block))
def export_xml(cls): from mosaicode.system import System as System System() blocks = System.get_blocks() for key in blocks: path = System.get_user_dir() path = os.path.join(path, 'extensions', blocks[key].language, 'block', blocks[key].extension, blocks[key].group) BlockPersistence.save_xml(blocks[key], path)
def test_load_save(self): diagram_control = self.create_diagram_control() block = self.create_block(diagram_control) BlockPersistence.save_python(block, "/tmp/") file_name = "/tmp/" + block.label.lower().replace(' ', '_') + ".py" os.remove(file_name) BlockPersistence.save_xml(block, "/tmp/") file_name = "/tmp/" + block.type + ".xml" result = BlockPersistence.load_xml(file_name) os.remove(file_name)
def load(cls, file_name): """ This method loads the block from XML file. Returns: * **Types** (:class:`boolean<boolean>`) """ file_name = file_name.replace(" ", "\\ ") try: return BlockPersistence.load(file_name) except: from mosaicode.system import System System.log("Block " + file_name + " could not load")
def export_python(cls): from mosaicode.system import System as System System() for plugin in System.plugins: print "Exporting plugin " + plugin BlockPersistence.save_python(System.plugins[plugin])
def add_new_block(cls, block): # first, save it BlockPersistence.save(block) # Then add it to system from mosaicode.system import System System.blocks[block.type] = block
def test_load_wrong_file(self): # Try to load a different file file_name = os.path.abspath(__file__) result = BlockPersistence.load_xml(file_name) assert result is None
def setUp(self): """Do the test basic setup.""" self.blockpersistence = BlockPersistence()
def export_extensions(self): from mosaicode.system import System as System System() result = True folder = "extension-" + datetime.datetime.now().strftime("%Y-%m-%d") # Export ports ports = System.get_ports() for key in ports: path = System.get_user_dir() path = os.path.join(path, folder, ports[key].language, 'ports') result = result and PortPersistence.save(ports[key], path) # Export Blocks blocks = System.get_blocks() result = True for key in blocks: path = System.get_user_dir() path = os.path.join(path, folder, blocks[key].language, 'blocks', blocks[key].extension, blocks[key].group) result = result and BlockPersistence.save(blocks[key], path) # Export Code Templates code_templates = System.get_code_templates() result = True for key in code_templates: path = System.get_user_dir() path = os.path.join(path, folder, code_templates[key].language, 'codetemplates') result = result and CodeTemplatePersistence.save( code_templates[key], path) # Export examples path = System.get_user_dir() path = os.path.join(path, "extensions") examples = System.get_examples() for example in examples: relpath = os.path.relpath(example, path) path = System.get_user_dir() path = os.path.join(path, folder, relpath) os.makedirs(os.path.dirname(path), exist_ok=True) shutil.copy2(example, path) # Create a zip file to the extension path = System.get_user_dir() path = os.path.join(path, folder+".zip") zip_file = zipfile.ZipFile(path, 'w') path = System.get_user_dir() path = os.path.join(path, folder) for folderName, subfolders, filenames in os.walk(path): for filename in filenames: filePath = os.path.join(folderName, filename) #create complete filepath of file in directory # Add file to zip zip_file.write(filePath, os.path.relpath(filePath, path)) zip_file.close() path = System.get_user_dir() path = os.path.join(path, folder) shutil.rmtree(path) # create a publish file filename = "resource.txt" path = System.get_user_dir() path = os.path.join(path, filename) f = open(path, "w") f.write(folder + ".zip") f.close() if result: MessageDialog( "Success", "File " + folder + ".zip created successfully!", self.main_window).run() else: MessageDialog( "Error", "Could not export extension", self.main_window).run() return result
def add_plugin(cls, plugin): # first, save it BlockPersistence.save(plugin) # Then add it to system from mosaicode.system import System System.plugins[plugin.type] = plugin
def add_new_block(cls, block): # Save it BlockPersistence.save(block)
def test_load_save(self): # Create, save and load a empty block block = BlockModel() block.label = "Empty block" persistence = BlockPersistence.save_xml(block, "/tmp/") file_name = "/tmp/" + block.label + ".xml" assert persistence result = BlockPersistence.load_xml(file_name) assert result is None os.remove(file_name) # Create, save and load a block # save(path is None) and block.file = "/tmp/" + block.label + ".xml" diagram_control = self.create_diagram_control() block = self.create_block(diagram_control) block.file = "/tmp/" + block.label + ".xml" persistence = BlockPersistence.save_xml(block) assert persistence result = BlockPersistence.load_xml(block.file) os.remove(block.file) assert isinstance(result, BlockModel) # Create e save # save(path is None) and block.file = Nove diagram_control = self.create_diagram_control() block = self.create_block(diagram_control) block.file = None persistence = BlockPersistence.save_xml(block) assert not persistence # Create, save and load a block # save(path not None) diagram_control = self.create_diagram_control() block = self.create_block(diagram_control) persistence = BlockPersistence.save_xml(block, "/tmp/") file_name = "/tmp/" + block.label + ".xml" assert persistence result = BlockPersistence.load_xml(file_name) os.remove(file_name) assert isinstance(result, BlockModel) assert result.type == block.type assert result.language == block.language assert result.extension == block.extension assert result.help == block.help assert result.color == block.color assert result.label == block.label assert result.group == block.group assert result.file is not None #assert result.maxOI == block.maxOI # assert codes for key, value in result.codes.items(): assert key in block.codes.keys() assert result.codes[key] == block.codes[key] # assert properties for result_prop in result.properties: match_prop = False for block_prop in block.properties: match_attr = False for result_key, result_value in result_prop.items(): if result_key in block_prop: if result_value == block_prop[result_key]: match_attr = True continue else: match_attr = False break else: match_attr = False break if match_attr: match_prop = True break assert match_prop # assert ports for result_port in result.ports: assert isinstance(result_port, dict) match = False for block_port in block.ports: if result_port["type"] == block_port.type and \ result_port["name"] == block_port.name and \ result_port["label"] == block_port.label and \ result_port["conn_type"] == block_port.conn_type: match = True assert match
def test_load_non_existent(self): # Try to load a nonexistent file file_name = "nonexistent_file.nofile" result = BlockPersistence.load_xml(file_name) assert result is None
def export_python(cls): from mosaicode.system import System as System System() for block in System.blocks: print "Exporting block " + block BlockPersistence.save_python(System.blocks[block])