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 init(self): self.update_blocks() self.main_window.menu.update_recent_files( System.get_preferences().recent_files) self.main_window.menu.update_examples(System.get_examples())