Editorial Workflows

RV: Module Manager

public workflow

Install Workflow...

This workflow contains at least one Python script. Only use it if you trust the person who shared this with you, and if you know exactly what it does.

I understand, install the workflow!

This is a workflow for Editorial, a Markdown and plain text editor for iOS. To download it, you need to view this page on a device that has the app installed.

Description: Workflow to manage installed modules. Swipe to delete module or tap on module to see details where you can convert module back to workflow to be able to edit it as Python script with syntax highlighting.

Check RV: Workflow to Module [1] workflow for more information.

[1] http://www.editorial-workflows.com/workflow/5872675348021248/8rCIFNJ32iY

Shared by: @robertvojta

Comments: Comment Feed (RSS)

@robertvojta — 21 May 2015
2015-05-21 Update

* functionality to convert module back to workflow so you can edit it with Python syntax highlighting

+ Add Comment

Workflow Preview
Run Python Script ?
Source Code
#coding: utf-8
import workflow
import os
import ui
import uuid
import editor
import json
import console

def site_packages_path():
	return os.path.join(os.path.expanduser('~/Documents'), 'site-packages')	
	
def installed_modules():
	path = site_packages_path()
	return [m for m in os.listdir(path) if os.path.isfile(os.path.join(path,m))]	
		
def delete_module(module):
	path = site_packages_path()
	module_path = os.path.join(path, module)
	if os.path.exists(module_path):
		os.remove(module_path)
		
def workflow_name_for_module(module):
	return 'Module: %s' % module
	
def workflow_description_for_module(module):
	return 'Workflow with one Run Python Script action containing site-packages/%s module code.' % module
		
def command_entry_for_module(module):
	identifier = str(uuid.uuid4())
	return {
		'title' : workflow_name_for_module(module),
		'uuid'  : identifier,
		'filename' : '%s.wkflw' % identifier,
		'comment' : workflow_description_for_module(module)
	}
		
def workflow_data_for_module(module):
	path = os.path.join(site_packages_path(), module)
	with open(path, 'r') as file:
		script = file.read()
		
	action = {}
	action['class'] = 'WorkflowActionRunScript'
	action['customTitle'] = module
	action['pauseBeforeRunning'] = False
	action['pauseWithoutShowingParameters'] = False
	action['parameters'] = { 'script' : script }
	
	return {
		'name' : workflow_name_for_module(module),
		'type' : 'wkflw',
		'public' : False,
		'description' : workflow_description_for_module(module),
		'actions' : [action]
	}
		
def convert_module_to_workflow(module):
	print 'Converting module %s to workflow ...' % module
	command_entry = command_entry_for_module(module)
	data = workflow_data_for_module(module)
	
	data_path = os.path.join(editor.get_workflows_path(), command_entry['filename'])
	with open(data_path, 'w') as file:
		json.dump(data, file)
	print 'Workflow data written in %s file' % command_entry['filename']
	
	commands_path = os.path.join(editor.get_workflows_path(), 'Commands.edcmd')
	with open(commands_path, 'r') as file:
		commands = json.load(file)
		
	commands.insert(0, command_entry)
	with open(commands_path, 'w') as file:
		json.dump(commands, file)
		
	editor.reload_workflows()
	print 'Module converted'
	console.hud_alert('Module %s converted' % module, 'success', 1.0)	

class ModuleListView(ui.View):
	def __init__(self):
		self.name = 'Installed Modules'
		self.modules = []
		
		cancel_item = ui.ButtonItem(title='Cancel', action=self.cancel)
		self.left_button_items = [cancel_item]
		
		self.tableview = ui.TableView()
		self.tableview.frame = self.bounds
		self.tableview.flex = 'WH'
		self.tableview.delegate = self
		self.tableview.data_source = self
		self.add_subview(self.tableview)
		
		self.reload_modules()
				
	def cancel(self, sender):
		self.navigation_view.close()
		
	@ui.in_background
	def reload_modules(self):
		self.modules = installed_modules()
		self.tableview.reload_data()
		
	def tableview_number_of_sections(self, tableview):
		return 1

	def tableview_number_of_rows(self, tableview, section):
		return len(self.modules)
		
	def tableview_cell_for_row(self, tableview, section, row):
		# Create and return a cell for the given section/row
		cell = ui.TableViewCell()
		cell.text_label.text = self.modules[row]
		return cell
		
	@ui.in_background
	def tableview_did_select(self, tableview, section, row):
		tableview.selected_row = -1
		module = self.modules[row]
		button = console.alert(module, 'What would you like to do?', 'Convert to Workflow', 'Delete...', 'Cancel', hide_cancel_button=True)
					
		if button == 1:			
			self.navigation_view.close()
			convert_module_to_workflow(module)
			return
			
		if button != 2:
			return
			
		button = console.alert(module, 'Do you want to really delete it?', 'Delete', 'Cancel', hide_cancel_button=True)
		
		if button != 1:
			return
			
		delete_module(module)
		self.reload_modules()
		
	def tableview_can_delete(self, tableview, section, row):		
		return True

	def tableview_delete(self, tableview, section, row):
		delete_module(self.modules[row])
		self.reload_modules()
				
def main():
	module_list = ModuleListView()
	nav = ui.NavigationView(module_list)
	nav.present(style='sheet', hide_title_bar=True)
	
main()