Plugins/VcsPlugins/vcsMercurial/BookmarksExtension/bookmarks.py

changeset 1018
949812411ab8
parent 1017
919147f2b518
child 1061
3e21869872e3
equal deleted inserted replaced
1017:919147f2b518 1018:949812411ab8
15 from ..HgDialog import HgDialog 15 from ..HgDialog import HgDialog
16 16
17 from .HgBookmarksListDialog import HgBookmarksListDialog 17 from .HgBookmarksListDialog import HgBookmarksListDialog
18 from .HgBookmarkDialog import HgBookmarkDialog 18 from .HgBookmarkDialog import HgBookmarkDialog
19 from .HgBookmarkRenameDialog import HgBookmarkRenameDialog 19 from .HgBookmarkRenameDialog import HgBookmarkRenameDialog
20 from .HgBookmarksInOutDialog import HgBookmarksInOutDialog
20 21
21 import Preferences 22 import Preferences
22 23
23 24
24 class Bookmarks(QObject): 25 class Bookmarks(QObject):
32 QObject.__init__(self, vcs) 33 QObject.__init__(self, vcs)
33 34
34 self.vcs = vcs 35 self.vcs = vcs
35 36
36 self.bookmarksListDlg = None 37 self.bookmarksListDlg = None
38 self.bookmarksInOutDlg = None
37 self.bookmarksList = [] 39 self.bookmarksList = []
38 40
39 def shutdown(self): 41 def shutdown(self):
40 """ 42 """
41 Public method used to shutdown the bookmarks interface. 43 Public method used to shutdown the bookmarks interface.
42 """ 44 """
43 if self.bookmarksListDlg is not None: 45 if self.bookmarksListDlg is not None:
44 self.bookmarksListDlg.close() 46 self.bookmarksListDlg.close()
47 if self.bookmarksInOutDlg is not None:
48 self.bookmarksInOutDlg.close()
45 49
46 def hgListBookmarks(self, path): 50 def hgListBookmarks(self, path):
47 """ 51 """
48 Public method used to list the available bookmarks. 52 Public method used to list the available bookmarks.
49 53
91 """ 95 """
92 Public method to define a bookmark. 96 Public method to define a bookmark.
93 97
94 @param name file/directory name (string) 98 @param name file/directory name (string)
95 """ 99 """
96 dname, fname = self.vcs.splitPath(name) 100 # find the root of the repo
97 101 repodir = self.vcs.splitPath(name)[0]
98 # find the root of the repo
99 repodir = str(dname)
100 while not os.path.isdir(os.path.join(repodir, self.vcs.adminDir)): 102 while not os.path.isdir(os.path.join(repodir, self.vcs.adminDir)):
101 repodir = os.path.dirname(repodir) 103 repodir = os.path.dirname(repodir)
102 if repodir == os.sep: 104 if repodir == os.sep:
103 return 105 return
104 106
125 """ 127 """
126 Public method to delete a bookmark. 128 Public method to delete a bookmark.
127 129
128 @param name file/directory name (string) 130 @param name file/directory name (string)
129 """ 131 """
130 dname, fname = self.vcs.splitPath(name) 132 # find the root of the repo
131 133 repodir = self.vcs.splitPath(name)[0]
132 # find the root of the repo
133 repodir = str(dname)
134 while not os.path.isdir(os.path.join(repodir, self.vcs.adminDir)): 134 while not os.path.isdir(os.path.join(repodir, self.vcs.adminDir)):
135 repodir = os.path.dirname(repodir) 135 repodir = os.path.dirname(repodir)
136 if repodir == os.sep: 136 if repodir == os.sep:
137 return 137 return
138 138
157 """ 157 """
158 Public method to rename a bookmark. 158 Public method to rename a bookmark.
159 159
160 @param name file/directory name (string) 160 @param name file/directory name (string)
161 """ 161 """
162 dname, fname = self.vcs.splitPath(name) 162 # find the root of the repo
163 163 repodir = self.vcs.splitPath(name)[0]
164 # find the root of the repo
165 repodir = str(dname)
166 while not os.path.isdir(os.path.join(repodir, self.vcs.adminDir)): 164 while not os.path.isdir(os.path.join(repodir, self.vcs.adminDir)):
167 repodir = os.path.dirname(repodir) 165 repodir = os.path.dirname(repodir)
168 if repodir == os.sep: 166 if repodir == os.sep:
169 return 167 return
170 168
187 """ 185 """
188 Public method to move a bookmark. 186 Public method to move a bookmark.
189 187
190 @param name file/directory name (string) 188 @param name file/directory name (string)
191 """ 189 """
192 dname, fname = self.vcs.splitPath(name) 190 # find the root of the repo
193 191 repodir = self.vcs.splitPath(name)[0]
194 # find the root of the repo
195 repodir = str(dname)
196 while not os.path.isdir(os.path.join(repodir, self.vcs.adminDir)): 192 while not os.path.isdir(os.path.join(repodir, self.vcs.adminDir)):
197 repodir = os.path.dirname(repodir) 193 repodir = os.path.dirname(repodir)
198 if repodir == os.sep: 194 if repodir == os.sep:
199 return 195 return
200 196
215 211
216 dia = HgDialog(self.trUtf8('Move Mercurial Bookmark')) 212 dia = HgDialog(self.trUtf8('Move Mercurial Bookmark'))
217 res = dia.startProcess(args, repodir) 213 res = dia.startProcess(args, repodir)
218 if res: 214 if res:
219 dia.exec_() 215 dia.exec_()
216
217 def hgBookmarkIncoming(self, name):
218 """
219 Public method to show a list of incoming bookmarks.
220
221 @param name file/directory name (string)
222 """
223 self.bookmarksInOutDlg = HgBookmarksInOutDialog(
224 self.vcs, HgBookmarksInOutDialog.INCOMING)
225 self.bookmarksInOutDlg.show()
226 self.bookmarksInOutDlg.start(name)
227
228 def hgBookmarkOutgoing(self, name):
229 """
230 Public method to show a list of outgoing bookmarks.
231
232 @param name file/directory name (string)
233 """
234 self.bookmarksInOutDlg = HgBookmarksInOutDialog(
235 self.vcs, HgBookmarksInOutDialog.OUTGOING)
236 self.bookmarksInOutDlg.show()
237 self.bookmarksInOutDlg.start(name)
238
239 def __getInOutBookmarks(self, repodir, incoming):
240 """
241 Public method to get the list of incoming or outgoing bookmarks.
242
243 @param repodir directory name of the repository (string)
244 @param incoming flag indicating to get incoming bookmarks (boolean)
245 @return list of bookmarks (list of string)
246 """
247 bookmarksList = []
248
249 ioEncoding = Preferences.getSystem("IOEncoding")
250 process = QProcess()
251 args = []
252 if incoming:
253 args.append('incoming')
254 else:
255 args.append('outgoing')
256 args.append('--bookmarks')
257 process.setWorkingDirectory(repodir)
258 process.start('hg', args)
259 procStarted = process.waitForStarted()
260 if procStarted:
261 finished = process.waitForFinished(30000)
262 if finished and process.exitCode() == 0:
263 output = \
264 str(process.readAllStandardOutput(), ioEncoding, 'replace')
265 for line in output.splitlines():
266 if line.startswith(" "):
267 l = line.strip().split()
268 del l[-1]
269 name = " ".join(l)
270 bookmarksList.append(name)
271
272 return bookmarksList
273
274 def hgBookmarkPull(self, name):
275 """
276 Public method to pull a bookmark from a remote repository.
277
278 @param name file/directory name (string)
279 """
280 # find the root of the repo
281 repodir = self.vcs.splitPath(name)[0]
282 while not os.path.isdir(os.path.join(repodir, self.vcs.adminDir)):
283 repodir = os.path.dirname(repodir)
284 if repodir == os.sep:
285 return
286
287 bookmarks = self.__getInOutBookmarks(repodir, True)
288
289 bookmark, ok = QInputDialog.getItem(
290 None,
291 self.trUtf8("Pull Bookmark"),
292 self.trUtf8("Select the bookmark to be pulled:"),
293 [""] + sorted(bookmarks),
294 0, True)
295 if ok and bookmark:
296 args = []
297 args.append('pull')
298 args.append('--bookmark')
299 args.append(bookmark)
300
301 dia = HgDialog(self.trUtf8('Pulling bookmark from a remote Mercurial repository'))
302 res = dia.startProcess(args, repodir)
303 if res:
304 dia.exec_()
305
306 def hgBookmarkPush(self, name):
307 """
308 Public method to push a bookmark to a remote repository.
309
310 @param name file/directory name (string)
311 """
312 # find the root of the repo
313 repodir = self.vcs.splitPath(name)[0]
314 while not os.path.isdir(os.path.join(repodir, self.vcs.adminDir)):
315 repodir = os.path.dirname(repodir)
316 if repodir == os.sep:
317 return
318
319 bookmarks = self.__getInOutBookmarks(repodir, False)
320
321 bookmark, ok = QInputDialog.getItem(
322 None,
323 self.trUtf8("Push Bookmark"),
324 self.trUtf8("Select the bookmark to be push:"),
325 [""] + sorted(bookmarks),
326 0, True)
327 if ok and bookmark:
328 args = []
329 args.append('push')
330 args.append('--bookmark')
331 args.append(bookmark)
332
333 dia = HgDialog(self.trUtf8('Pushing bookmark to a remote Mercurial repository'))
334 res = dia.startProcess(args, repodir)
335 if res:
336 dia.exec_()

eric ide

mercurial