forked from ukostas/robotframework-ride-tortoisesvn
/
TortoiseSVNPlugin.py
109 lines (95 loc) · 5.07 KB
/
TortoiseSVNPlugin.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import subprocess
import wx
from robotide.controller.filecontrollers import TestCaseFileController, ResourceFileController, \
TestDataDirectoryController
from robotide.pluginapi import Plugin, ActionInfo, SeparatorInfo
from robotide.widgets import PopupMenuItem
class TortoiseSVNPlugin(Plugin):
"""
Plugin adds a menu to call dialogs from TortoiseSVN
"""
MENU_NAME = 'TortoiseSVN'
SVN_INSTALLATION_URL = 'http://tortoisesvn.net/downloads.html'
TORTOISE_PROC_EXE = 'TortoiseProc.exe'
VERSION = '0.1.1'
# plugin metadata
metadata = {'Version': VERSION,
'Author': 'ukostas',
'URL': 'https://github.com/ukostas/robotframework-ride-tortoisesvn'}
# http://tortoisesvn.net/docs/release/TortoiseSVN_en/tsvn-automation.html
menu = [
{"name": "Check Project for modifications",
"action": ('%s /command:repostatus /path:"{path}"' % TORTOISE_PROC_EXE)},
{"name": "Show Project Commit Log", "action": ('%s /command:log /path:"{path}"' % TORTOISE_PROC_EXE)},
{"name": "Project Update", "action": ('%s /command:update /path:"{path}"' % TORTOISE_PROC_EXE)},
{"name": "Project Commit...", "action": ('%s /command:commit /path:"{path}"' % TORTOISE_PROC_EXE)},
{"name": "Project Revert...", "action": ('%s /command:revert /path:"{path}"' % TORTOISE_PROC_EXE)},
{"name": None},
{"name": "Item Revert...", "action": ('%s /command:revert /path:"{path}"' % TORTOISE_PROC_EXE)},
{"name": "Item Commit Log", "action": ('%s /command:log /path:"{path}"' % TORTOISE_PROC_EXE),
'context_menu': True},
{"name": "Item Blame", "action": ('%s /command:blame /path:"{path}"' % TORTOISE_PROC_EXE),
'context_menu': True},
{"name": "Item Diff", "action": ('%s /command:diff /path:"{path}"' % TORTOISE_PROC_EXE), 'context_menu': True},
{"name": None},
{"name": "About TortoiseSVN", "action": ('%s /command:about' % TORTOISE_PROC_EXE)},
{"name": "TortoiseSVN Installation", "action": SVN_INSTALLATION_URL}]
def __init__(self, application=None):
self.context_menu = [PopupMenuItem('---')]
self.context_menu += [
PopupMenuItem(item['name'], callable=self.create_callable(item['name'], item['action'])) for
item in filter(lambda x: x.get('context_menu', False), self.menu)]
Plugin.__init__(self, application, metadata=self.metadata)
def enable(self):
self.add_main_menu()
self.add_tree_context_menu()
def disable(self):
self.remove_main_menu()
self.remove_tree_context_menu()
def remove_tree_context_menu(self):
self.tree.unregister_context_menu_hook(self._context_menu_handler)
def remove_main_menu(self):
self.unregister_actions()
def add_main_menu(self):
self.unregister_actions()
for menuItem in self.menu:
if menuItem['name'] is None:
self.register_action(SeparatorInfo(self.MENU_NAME))
else:
action_info = ActionInfo(self.MENU_NAME, name=menuItem['name'],
action=self.create_callable(menuItem['name'], menuItem['action']))
self.register_action(action_info)
def create_callable(self, name, action):
def callable(event):
# check if this is for whole project or file/directory
if 'item' in name.lower(): # for one single item - file/directory
if not self.datafile:
return
full_cmd = action.format(path=self.datafile.source)
else: # for whole project - root file/directory
full_cmd = action.format(path=self.model.suite.source)
# RideLogMessage(name + " clicked: " + fullCmd).publish()
if full_cmd.lower().startswith('http'):
wx.LaunchDefaultBrowser(full_cmd)
else:
try:
subprocess.Popen(full_cmd)
except OSError as error:
s = "This is the error we got trying to execute {executor_name} executable file:\n" \
"\"{error}\"\n\n" \
"Probably this file in not in your PATH. Try to reinstall {executor_name}.\n" \
"Do you want to open download page?".format(error=error.strerror, executor_name=self.MENU_NAME)
dlg = wx.MessageDialog(parent=self.frame, caption="Hmm, something went wrong...", message=s,
style=wx.YES_NO | wx.CENTER | wx.ICON_INFORMATION)
if dlg.ShowModal() == wx.ID_YES:
wx.LaunchDefaultBrowser(self.SVN_INSTALLATION_URL)
dlg.Destroy()
return callable
def add_tree_context_menu(self):
self.tree.register_context_menu_hook(self._context_menu_handler)
def _context_menu_handler(self, item):
if isinstance(item, (
TestCaseFileController, ResourceFileController,
TestDataDirectoryController)):
return self.context_menu
return []