1
# -*- coding: utf-8 -*-
3
# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79:
4
#Copyright (c) 2005-2006 The PIDA Project
6
#Permission is hereby granted, free of charge, to any person obtaining a copy
7
#of this software and associated documentation files (the "Software"), to deal
8
#in the Software without restriction, including without limitation the rights
9
#to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
#copies of the Software, and to permit persons to whom the Software is
11
#furnished to do so, subject to the following conditions:
13
#The above copyright notice and this permission notice shall be included in
14
#all copies or substantial portions of the Software.
16
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
#IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
#FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
#AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
#LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
#OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28
import pida.core.service as service
29
import pida.core.actions as actions
31
import pida.utils.vc as vc
33
defs = service.definitions
36
class version_control(service.service):
38
display_name = 'Version Control Integration'
40
class meld_integration(defs.optiongroup):
41
"""How much meld will be used."""
42
class use_meld_for_statuses(defs.option):
43
"""Whether Meld will be used for file listings."""
46
class use_meld_for_diff(defs.option):
47
"""Whether Meld (visual diff) will be used for file diffs."""
52
self.__currentfile = None
53
self.action_group.set_sensitive(False)
54
self.__cached_vcs = {}
56
def bnd_buffermanager_document_changed(self, document):
57
self.__currentfile = document.filename
58
self.action_group.set_sensitive(True)
60
def cmd_get_vcs_for_directory(self, directory):
61
vcs = vc.Vc(directory)
62
workdir = vcs.get_working_directory(directory)
63
if workdir in self.__cached_vcs:
64
vcs = self.__cached_vcs[workdir]
66
self.__cached_vcs[workdir] = vcs
69
def cmd_forget_directory(self, directory):
70
vcs = vc.Vc(directory)
71
workdir = vcs.get_working_directory(directory)
72
if workdir in self.__cached_vcs:
73
del self.__cached_vcs[workdir]
75
def cmd_statuses(self, directory):
76
if self.opt('meld_integration', 'use_meld_for_statuses'):
77
self.boss.call_command('meldembed', 'browse',
80
print 'not using meld'
82
def cmd_get_statuses(self, directory):
83
vcs = self.call('get_vcs_for_directory', directory=directory)
84
if vcs.NAME == 'Null':
85
self.log.info('"%s" is not version controlled', directory)
88
statuses = vcs.listdir(directory)
90
except NotImplementedError:
91
self.log.info('"%s" is not version controlled', directory)
93
def cmd_diff_file(self, filename):
94
if self.opt('meld_integration', 'use_meld_for_diff'):
95
self.boss.call_command('meldembed', 'diff',
98
directory = os.path.dirname(filename)
99
basename = os.path.basename(filename)
100
vcs = self.call('get_vcs_for_directory', directory=directory)
101
if vcs.NAME == 'Null':
102
self.log.info('"%s" is not version controlled', directory)
105
commandargs = vcs.diff_command() + [basename]
106
self.boss.call_command('terminal', 'execute',
107
command_args=commandargs,
108
icon_name='vcs_diff',
110
kwdict = {'directory':
112
short_title='Differences')
113
except NotImplementedError:
114
self.log.info('Not implemented for %s' % vcs.NAME)
116
def cmd_update(self, directory):
117
vcs = self.call('get_vcs_for_directory', directory=directory)
118
if vcs.NAME == 'Null':
119
self.log.info('"%s" is not version controlled', directory)
122
commandargs = vcs.update_command()
123
self.boss.call_command('terminal', 'execute',
124
command_args=commandargs,
125
icon_name='vcs_update',
126
kwdict = {'directory':
128
short_title='Update')
129
self._update_filemanager(directory)
130
except NotImplementedError:
131
self.log.info('"%s" is not version controlled', directory)
134
def cmd_commit(self, directory):
135
vcs = self.call('get_vcs_for_directory', directory=directory)
136
if vcs.NAME == 'Null':
137
self.log.info('"%s" is not version controlled', directory)
140
commandargs = vcs.commit_command(message)
141
self.boss.call_command('terminal', 'execute',
142
command_args=commandargs,
143
icon_name='vcs_commit',
144
kwdict = {'directory':
146
short_title='Commit')
147
self._update_filemanager(directory)
148
self.boss.call_command('window', 'input',
149
callback_function=commit,
150
prompt='%s commit message' % vcs.NAME)
152
def cmd_add_file(self, filename):
153
directory = os.path.dirname(filename)
154
basename = os.path.basename(filename)
155
vcs = self.call('get_vcs_for_directory', directory=directory)
156
if vcs.NAME == 'Null':
157
self.log.info('"%s" is not version controlled', directory)
160
commandargs = vcs.add_command() + [basename]
161
self.boss.call_command('terminal', 'execute',
162
command_args=commandargs,
164
kwdict = {'directory':
167
self._update_filemanager(directory)
168
except NotImplementedError:
169
self.log.info('Not implemented for %s' % vcs.NAME)
171
def cmd_remove_file(self, filename):
172
directory = os.path.dirname(filename)
173
basename = os.path.basename(filename)
174
vcs = self.call('get_vcs_for_directory', directory=directory)
175
if vcs.NAME == 'Null':
176
self.log.info('"%s" is not version controlled', directory)
179
commandargs = vcs.remove_command() + [basename]
180
self.boss.call_command('terminal', 'execute',
181
command_args=commandargs,
183
kwdict = {'directory':
185
short_title='Remove')
186
self._update_filemanager(directory)
187
except NotImplementedError:
188
self.log.info('Not implemented for %s' % vcs.NAME)
190
def cmd_revert_file(self, filename):
191
directory = os.path.dirname(filename)
192
basename = os.path.basename(filename)
193
vcs = self.call('get_vcs_for_directory', directory=directory)
194
if vcs.NAME == 'Null':
195
self.log.info('"%s" is not version controlled', directory)
198
commandargs = vcs.revert_command() + [basename]
199
self.boss.call_command('terminal', 'execute',
200
command_args=commandargs,
202
kwdict = {'directory':
204
short_title='Revert')
205
self._update_filemanager(directory)
206
except NotImplementedError:
207
self.log.info('Not implemented for %s' % vcs.NAME)
209
def _update_filemanager(self, directory):
210
fmdir = self.boss.call_command('filemanager', 'get_current_directory')
211
print fmdir, directory
212
if directory == fmdir:
213
self.call('forget_directory', directory=directory)
215
self.boss.call_command('filemanager', 'browse',
217
gobject.timeout_add(200, browse)
219
@actions.action(label='Differences',
221
default_accel='<Shift><Control>d',
223
def act_diff_file(self, action):
224
self.call('diff_file', filename=self.__currentfile)
226
def get_menu_definition(self):
231
<menu name="base_file" action="base_file_menu">
232
<placeholder name="SubSaveFileMenu" >
233
<menuitem name="diff_file" action="versioncontrol+diff_file" />
241
Service = version_control