Plugins/VcsPlugins/vcsMercurial/BookmarksExtension/bookmarks.py

branch
Py2 comp.
changeset 3484
645c12de6b0c
parent 3178
f25fc1364c88
parent 3302
e92f0dd51979
equal deleted inserted replaced
3456:96232974dcdb 3484:645c12de6b0c
7 Module implementing the bookmarks extension interface. 7 Module implementing the bookmarks extension interface.
8 """ 8 """
9 9
10 from __future__ import unicode_literals 10 from __future__ import unicode_literals
11 try: 11 try:
12 str = unicode # __IGNORE_WARNING__ 12 str = unicode
13 except (NameError): 13 except NameError:
14 pass 14 pass
15 15
16 import os 16 import os
17 17
18 from PyQt4.QtCore import QProcess 18 from PyQt4.QtCore import QProcess
19 from PyQt4.QtGui import QDialog, QInputDialog 19 from PyQt4.QtGui import QDialog, QInputDialog
20 20
21 from ..HgExtension import HgExtension 21 from ..HgExtension import HgExtension
22 from ..HgDialog import HgDialog 22 from ..HgDialog import HgDialog
23
24 import Preferences
25 23
26 24
27 class Bookmarks(HgExtension): 25 class Bookmarks(HgExtension):
28 """ 26 """
29 Class implementing the bookmarks extension interface. 27 Class implementing the bookmarks extension interface.
67 Public method to get the list of bookmarks. 65 Public method to get the list of bookmarks.
68 66
69 @param repodir directory name of the repository (string) 67 @param repodir directory name of the repository (string)
70 @return list of bookmarks (list of string) 68 @return list of bookmarks (list of string)
71 """ 69 """
72 args = [] 70 args = self.vcs.initCommand("bookmarks")
73 args.append('bookmarks')
74 71
75 client = self.vcs.getClient() 72 client = self.vcs.getClient()
76 output = "" 73 output = ""
77 if client: 74 if client:
78 output = client.runcommand(args)[0] 75 output = client.runcommand(args)[0]
79 else: 76 else:
80 ioEncoding = Preferences.getSystem("IOEncoding")
81 process = QProcess() 77 process = QProcess()
82 process.setWorkingDirectory(repodir) 78 process.setWorkingDirectory(repodir)
83 process.start('hg', args) 79 process.start('hg', args)
84 procStarted = process.waitForStarted(5000) 80 procStarted = process.waitForStarted(5000)
85 if procStarted: 81 if procStarted:
86 finished = process.waitForFinished(30000) 82 finished = process.waitForFinished(30000)
87 if finished and process.exitCode() == 0: 83 if finished and process.exitCode() == 0:
88 output = str( 84 output = str(process.readAllStandardOutput(),
89 process.readAllStandardOutput(), ioEncoding, 85 self.vcs.getEncoding(), 'replace')
90 'replace')
91 86
92 self.bookmarksList = [] 87 self.bookmarksList = []
93 for line in output.splitlines(): 88 for line in output.splitlines():
94 li = line.strip().split() 89 li = line.strip().split()
95 if li[-1][0] in "1234567890": 90 if li[-1][0] in "1234567890":
121 self.vcs.hgGetBranchesList(repodir), 116 self.vcs.hgGetBranchesList(repodir),
122 self.hgGetBookmarksList(repodir)) 117 self.hgGetBookmarksList(repodir))
123 if dlg.exec_() == QDialog.Accepted: 118 if dlg.exec_() == QDialog.Accepted:
124 rev, bookmark = dlg.getData() 119 rev, bookmark = dlg.getData()
125 120
126 args = [] 121 args = self.vcs.initCommand("bookmarks")
127 args.append("bookmarks")
128 if rev: 122 if rev:
129 args.append("--rev") 123 args.append("--rev")
130 args.append(rev) 124 args.append(rev)
131 args.append(bookmark) 125 args.append(bookmark)
132 126
133 dia = HgDialog(self.trUtf8('Mercurial Bookmark'), self.vcs) 127 dia = HgDialog(self.tr('Mercurial Bookmark'), self.vcs)
134 res = dia.startProcess(args, repodir) 128 res = dia.startProcess(args, repodir)
135 if res: 129 if res:
136 dia.exec_() 130 dia.exec_()
137 131
138 def hgBookmarkDelete(self, name): 132 def hgBookmarkDelete(self, name):
148 if os.path.splitdrive(repodir)[1] == os.sep: 142 if os.path.splitdrive(repodir)[1] == os.sep:
149 return 143 return
150 144
151 bookmark, ok = QInputDialog.getItem( 145 bookmark, ok = QInputDialog.getItem(
152 None, 146 None,
153 self.trUtf8("Delete Bookmark"), 147 self.tr("Delete Bookmark"),
154 self.trUtf8("Select the bookmark to be deleted:"), 148 self.tr("Select the bookmark to be deleted:"),
155 [""] + sorted(self.hgGetBookmarksList(repodir)), 149 [""] + sorted(self.hgGetBookmarksList(repodir)),
156 0, True) 150 0, True)
157 if ok and bookmark: 151 if ok and bookmark:
158 args = [] 152 args = self.vcs.initCommand("bookmarks")
159 args.append("bookmarks")
160 args.append("--delete") 153 args.append("--delete")
161 args.append(bookmark) 154 args.append(bookmark)
162 155
163 dia = HgDialog(self.trUtf8('Delete Mercurial Bookmark'), self.vcs) 156 dia = HgDialog(self.tr('Delete Mercurial Bookmark'), self.vcs)
164 res = dia.startProcess(args, repodir) 157 res = dia.startProcess(args, repodir)
165 if res: 158 if res:
166 dia.exec_() 159 dia.exec_()
167 160
168 def hgBookmarkRename(self, name): 161 def hgBookmarkRename(self, name):
181 from .HgBookmarkRenameDialog import HgBookmarkRenameDialog 174 from .HgBookmarkRenameDialog import HgBookmarkRenameDialog
182 dlg = HgBookmarkRenameDialog(self.hgGetBookmarksList(repodir)) 175 dlg = HgBookmarkRenameDialog(self.hgGetBookmarksList(repodir))
183 if dlg.exec_() == QDialog.Accepted: 176 if dlg.exec_() == QDialog.Accepted:
184 newName, oldName = dlg.getData() 177 newName, oldName = dlg.getData()
185 178
186 args = [] 179 args = self.vcs.initCommand("bookmarks")
187 args.append("bookmarks")
188 args.append("--rename") 180 args.append("--rename")
189 args.append(oldName) 181 args.append(oldName)
190 args.append(newName) 182 args.append(newName)
191 183
192 dia = HgDialog(self.trUtf8('Rename Mercurial Bookmark'), self.vcs) 184 dia = HgDialog(self.tr('Rename Mercurial Bookmark'), self.vcs)
193 res = dia.startProcess(args, repodir) 185 res = dia.startProcess(args, repodir)
194 if res: 186 if res:
195 dia.exec_() 187 dia.exec_()
196 188
197 def hgBookmarkMove(self, name): 189 def hgBookmarkMove(self, name):
213 self.vcs.hgGetBranchesList(repodir), 205 self.vcs.hgGetBranchesList(repodir),
214 self.hgGetBookmarksList(repodir)) 206 self.hgGetBookmarksList(repodir))
215 if dlg.exec_() == QDialog.Accepted: 207 if dlg.exec_() == QDialog.Accepted:
216 rev, bookmark = dlg.getData() 208 rev, bookmark = dlg.getData()
217 209
218 args = [] 210 args = self.vcs.initCommand("bookmarks")
219 args.append("bookmarks")
220 args.append("--force") 211 args.append("--force")
221 if rev: 212 if rev:
222 args.append("--rev") 213 args.append("--rev")
223 args.append(rev) 214 args.append(rev)
224 args.append(bookmark) 215 args.append(bookmark)
225 216
226 dia = HgDialog(self.trUtf8('Move Mercurial Bookmark'), self.vcs) 217 dia = HgDialog(self.tr('Move Mercurial Bookmark'), self.vcs)
227 res = dia.startProcess(args, repodir) 218 res = dia.startProcess(args, repodir)
228 if res: 219 if res:
229 dia.exec_() 220 dia.exec_()
230 221
231 def hgBookmarkIncoming(self, name): 222 def hgBookmarkIncoming(self, name):
260 @param incoming flag indicating to get incoming bookmarks (boolean) 251 @param incoming flag indicating to get incoming bookmarks (boolean)
261 @return list of bookmarks (list of string) 252 @return list of bookmarks (list of string)
262 """ 253 """
263 bookmarksList = [] 254 bookmarksList = []
264 255
265 args = []
266 if incoming: 256 if incoming:
267 args.append('incoming') 257 args = self.vcs.initCommand("incoming")
268 else: 258 else:
269 args.append('outgoing') 259 args = self.vcs.initCommand("outgoing")
270 args.append('--bookmarks') 260 args.append('--bookmarks')
271 261
272 client = self.vcs.getClient() 262 client = self.vcs.getClient()
273 output = "" 263 output = ""
274 if client: 264 if client:
275 output = client.runcommand(args)[0] 265 output = client.runcommand(args)[0]
276 else: 266 else:
277 ioEncoding = Preferences.getSystem("IOEncoding")
278 process = QProcess() 267 process = QProcess()
279 process.setWorkingDirectory(repodir) 268 process.setWorkingDirectory(repodir)
280 process.start('hg', args) 269 process.start('hg', args)
281 procStarted = process.waitForStarted(5000) 270 procStarted = process.waitForStarted(5000)
282 if procStarted: 271 if procStarted:
283 finished = process.waitForFinished(30000) 272 finished = process.waitForFinished(30000)
284 if finished and process.exitCode() == 0: 273 if finished and process.exitCode() == 0:
285 output = str( 274 output = str(process.readAllStandardOutput(),
286 process.readAllStandardOutput(), ioEncoding, 275 self.vcs.getEncoding(), 'replace')
287 'replace')
288 276
289 for line in output.splitlines(): 277 for line in output.splitlines():
290 if line.startswith(" "): 278 if line.startswith(" "):
291 li = line.strip().split() 279 li = line.strip().split()
292 del li[-1] 280 del li[-1]
310 298
311 bookmarks = self.__getInOutBookmarks(repodir, True) 299 bookmarks = self.__getInOutBookmarks(repodir, True)
312 300
313 bookmark, ok = QInputDialog.getItem( 301 bookmark, ok = QInputDialog.getItem(
314 None, 302 None,
315 self.trUtf8("Pull Bookmark"), 303 self.tr("Pull Bookmark"),
316 self.trUtf8("Select the bookmark to be pulled:"), 304 self.tr("Select the bookmark to be pulled:"),
317 [""] + sorted(bookmarks), 305 [""] + sorted(bookmarks),
318 0, True) 306 0, True)
319 if ok and bookmark: 307 if ok and bookmark:
320 args = [] 308 args = self.vcs.initCommand("pull")
321 args.append('pull')
322 args.append('--bookmark') 309 args.append('--bookmark')
323 args.append(bookmark) 310 args.append(bookmark)
324 311
325 dia = HgDialog(self.trUtf8( 312 dia = HgDialog(self.tr(
326 'Pulling bookmark from a remote Mercurial repository'), 313 'Pulling bookmark from a remote Mercurial repository'),
327 self.vcs) 314 self.vcs)
328 res = dia.startProcess(args, repodir) 315 res = dia.startProcess(args, repodir)
329 if res: 316 if res:
330 dia.exec_() 317 dia.exec_()
344 331
345 bookmarks = self.__getInOutBookmarks(repodir, False) 332 bookmarks = self.__getInOutBookmarks(repodir, False)
346 333
347 bookmark, ok = QInputDialog.getItem( 334 bookmark, ok = QInputDialog.getItem(
348 None, 335 None,
349 self.trUtf8("Push Bookmark"), 336 self.tr("Push Bookmark"),
350 self.trUtf8("Select the bookmark to be push:"), 337 self.tr("Select the bookmark to be push:"),
351 [""] + sorted(bookmarks), 338 [""] + sorted(bookmarks),
352 0, True) 339 0, True)
353 if ok and bookmark: 340 if ok and bookmark:
354 args = [] 341 args = self.vcs.initCommand("push")
355 args.append('push')
356 args.append('--bookmark') 342 args.append('--bookmark')
357 args.append(bookmark) 343 args.append(bookmark)
358 344
359 dia = HgDialog(self.trUtf8( 345 dia = HgDialog(self.tr(
360 'Pushing bookmark to a remote Mercurial repository'), 346 'Pushing bookmark to a remote Mercurial repository'),
361 self.vcs) 347 self.vcs)
362 res = dia.startProcess(args, repodir) 348 res = dia.startProcess(args, repodir)
363 if res: 349 if res:
364 dia.exec_() 350 dia.exec_()

eric ide

mercurial