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 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070
|
#----------------------------------------------------------------------------
# Name: SVNService.py
# Purpose: Subversion Service for pydocview
#
# Author: Morgan Hua
#
# Created: 5/13/05
# CVS-ID: $Id$
# Copyright: (c) 2005 ActiveGrid, Inc.
# License: wxWindows License
#----------------------------------------------------------------------------
import wx
import os
import os.path
import ProjectEditor
import MessageService
import sys # for errors
import traceback # for errors
try:
import pysvn # python-subversion integration
SVN_INSTALLED = True
except ImportError:
SVN_INSTALLED = False
_ = wx.GetTranslation
#----------------------------------------------------------------------------
# Constants
#----------------------------------------------------------------------------
SVN_CONFIG_DIR = "SVNConfigDir"
SVN_REPOSITORY_URL = "SVNRepositoryURLs"
SPACE = 10
HALF_SPACE = 5
#----------------------------------------------------------------------------
# Classes
#----------------------------------------------------------------------------
class SVNService(wx.lib.pydocview.DocService):
SVN_UPDATE_ALL_ID = wx.NewId()
SVN_UPDATE_ID = wx.NewId()
SVN_CHECKIN_ID = wx.NewId()
SVN_CHECKIN_ALL_ID = wx.NewId()
SVN_CHECKOUT_ID = wx.NewId()
SVN_REVERT_ID = wx.NewId()
SVN_ADD_ID = wx.NewId()
SVN_DELETE_ID = wx.NewId()
SVN_COMMAND_LIST = [SVN_UPDATE_ALL_ID, SVN_CHECKIN_ALL_ID, SVN_UPDATE_ID, SVN_CHECKIN_ID, SVN_CHECKOUT_ID, SVN_REVERT_ID, SVN_ADD_ID, SVN_DELETE_ID]
def __init__(self):
self._defaultURL = "svn://"
global SVN_INSTALLED
if SVN_INSTALLED:
config = wx.ConfigBase_Get()
configDir = config.Read(SVN_CONFIG_DIR, "")
self._client = pysvn.Client(configDir)
try:
self._defaultURL = self._client.info('.').url
except:
pass
self._client.callback_cancel = self.IfCancel
self._client.callback_notify = self.UpdateStatus
self._client.callback_get_log_message = self.GetLogMessage
self._client.callback_get_login = self.GetLogin
self._client.callback_ssl_server_trust_prompt = self.GetSSLServerTrust
self._client.callback_ssl_client_cert_password_prompt = self.SSLClientPassword
self._client.callback_ssl_client_cert_prompt = self.SSLClientCert
self._client.callback_ssl_server_prompt = self.SSLServerPrompt
#----------------------------------------------------------------------------
# pysvn.Client() Callback Methods
#----------------------------------------------------------------------------
def IfCancel(self):
""" return True if user wants to cancel current command """
return False
def UpdateStatus(self, eventDict):
messageService = wx.GetApp().GetService(MessageService.MessageService)
messageService.ShowWindow()
view = messageService.GetView()
view.AddLines(_("%s %s\n") % (eventDict['action'], eventDict['path']))
def GetLogMessage(self):
dlg = wx.TextEntryDialog(wx.GetApp().GetTopWindow(),
_("Comment"),
_("SVN Log Message"))
dlg.CenterOnParent()
if dlg.ShowModal() == wx.ID_OK:
retcode = True
message = dlg.GetValue()
else:
retcode = False
message = _("Cancel Action")
dlg.Destroy()
return retcode, message
def GetLogin(self, realm, username, maySave):
dlg = wx.Dialog(wx.GetApp().GetTopWindow(), -1, _("SVN Login"))
sizer = wx.FlexGridSizer(cols = 2, hgap = 5, vgap = 5)
sizer.Add(wx.StaticText(dlg, -1, _("Username:")), 0, wx.ALIGN_CENTER_VERTICAL)
usernameTxt = wx.TextCtrl(dlg, -1, username, size = (200, -1))
sizer.Add(usernameTxt, 0, wx.ALIGN_CENTER_VERTICAL)
sizer.Add(wx.StaticText(dlg, -1, _("Password:")), 0, wx.ALIGN_CENTER_VERTICAL)
passwordTxt = wx.TextCtrl(dlg, -1, size=(200, -1), style=wx.TE_PASSWORD)
sizer.Add(passwordTxt, 0, wx.ALIGN_CENTER_VERTICAL)
savePasswordCheckbox = wx.CheckBox(dlg, -1, _("Remember Username and Password"))
if not maySave:
savePasswordCheckbox.Enable(False)
buttonSizer = wx.BoxSizer(wx.HORIZONTAL)
okBtn = wx.Button(dlg, wx.ID_OK)
okBtn.SetDefault()
buttonSizer.Add(okBtn, 0, wx.RIGHT, HALF_SPACE)
buttonSizer.Add(wx.Button(dlg, wx.ID_CANCEL), 0)
contentSizer = wx.BoxSizer(wx.VERTICAL)
contentSizer.Add(sizer, 0, wx.LEFT|wx.TOP|wx.RIGHT, SPACE)
contentSizer.Add(savePasswordCheckbox, 0, wx.TOP|wx.LEFT|wx.BOTTOM, SPACE)
contentSizer.Add(buttonSizer, 0, wx.ALL|wx.ALIGN_RIGHT, SPACE)
dlg.SetSizer(contentSizer)
dlg.Fit()
dlg.Layout()
dlg.CenterOnParent()
if dlg.ShowModal() == wx.ID_OK:
retcode = True
username = usernameTxt.GetValue().strip()
password = passwordTxt.GetValue()
save = savePasswordCheckbox.IsChecked()
else:
retcode = False
username = None
password = None
save = False
dlg.Destroy()
return retcode, username, password, save
def SSLServerPrompt(self):
""" Not implemented, as per pysvn documentation """
return
def GetSSLServerTrust(self, trustDict):
dlg = wx.Dialog(wx.GetApp().GetTopWindow(), -1, _("SSL Server Certificate"))
sizer = wx.FlexGridSizer(cols = 2, hgap = 5, vgap = 5)
for k in ['hostname', 'valid_from', 'valid_to', 'issuer_dname', 'realm']:
if trustDict.has_key(k):
sizer.Add(wx.StaticText(dlg, -1, "%s:" % k), 0, wx.ALIGN_CENTER_VERTICAL)
sizer.Add(wx.StaticText(dlg, -1, "%s" % trustDict[k]), 0, wx.ALIGN_CENTER_VERTICAL)
box = wx.StaticBoxSizer(wx.StaticBox(dlg, -1, _("Certificate Info")), wx.VERTICAL)
box.Add(sizer, 0, wx.EXPAND)
certRadio = wx.RadioBox(dlg, -1, _("Certificate"), choices=[_("Accept Always"), _("Accept Once"), _("Reject")], majorDimension=1, style=wx.RA_SPECIFY_COLS)
buttonSizer = wx.BoxSizer(wx.HORIZONTAL)
okBtn = wx.Button(dlg, wx.ID_OK)
okBtn.SetDefault()
buttonSizer.Add(okBtn, 0, wx.RIGHT, HALF_SPACE)
buttonSizer.Add(wx.Button(dlg, wx.ID_CANCEL), 0)
contentSizer = wx.BoxSizer(wx.VERTICAL)
contentSizer.Add(box, 0, wx.TOP|wx.LEFT|wx.RIGHT|wx.EXPAND, SPACE)
contentSizer.Add(certRadio, 0, wx.TOP|wx.LEFT|wx.RIGHT|wx.BOTTOM|wx.EXPAND, SPACE)
contentSizer.Add(buttonSizer, 0, wx.ALL|wx.ALIGN_RIGHT, SPACE)
dlg.SetSizer(contentSizer)
dlg.Fit()
dlg.Layout()
# default values for reject
retcode = False
acceptedFailures = 0
save = False
dlg.CenterOnParent()
if dlg.ShowModal() == wx.ID_OK:
cert = certRadio.GetStringSelection()
if cert == _("Accept Always"):
retcode = True
acceptedFailures = trustDict.get('failures')
save = True
elif cert == _("Accept Once"):
retcode = True
acceptedFailures = trustDict.get('failures')
save = False
dlg.Destroy()
return retcode, acceptedFailures, save
def SSLClientPassword(self, realm, maySave):
dlg = wx.Dialog(wx.GetApp().GetTopWindow(), -1, _("SSL Client Certificate Login"))
sizer = wx.FlexGridSizer(cols = 2, hgap = 5, vgap = 5)
sizer.Add(wx.StaticText(dlg, -1, _("Realm:")), 0, wx.ALIGN_CENTER_VERTICAL)
sizer.Add(wx.StaticText(dlg, -1, realm), 0, wx.ALIGN_CENTER_VERTICAL)
sizer.Add(wx.StaticText(dlg, -1, _("Password:")), 0, wx.ALIGN_CENTER_VERTICAL)
passwordTxt = wx.TextCtrl(dlg, -1, size=(200, -1), style=wx.TE_PASSWORD)
sizer.Add(passwordTxt, 0, wx.ALIGN_CENTER_VERTICAL)
savePasswordCheckbox = wx.CheckBox(dlg, -1, _("Remember Password"))
if not maySave:
savePasswordCheckbox.Enable(False)
buttonSizer = wx.BoxSizer(wx.HORIZONTAL)
okBtn = wx.Button(dlg, wx.ID_OK)
okBtn.SetDefault()
buttonSizer.Add(okBtn, 0, wx.RIGHT, HALF_SPACE)
buttonSizer.Add(wx.Button(dlg, wx.ID_CANCEL), 0)
contentSizer = wx.BoxSizer(wx.VERTICAL)
contentSizer.Add(sizer, 0, wx.LEFT|wx.TOP|wx.RIGHT, SPACE)
contentSizer.Add(savePasswordCheckbox, 0, wx.TOP|wx.LEFT|wx.BOTTOM, SPACE)
contentSizer.Add(buttonSizer, 0, wx.ALL|wx.ALIGN_RIGHT, SPACE)
dlg.SetSizer(contentSizer)
dlg.Fit()
dlg.Layout()
dlg.CenterOnParent()
if dlg.ShowModal() == wx.ID_OK:
retcode = True
password = passwordTxt.GetValue()
save = savePasswordCheckbox.IsChecked()
else:
retcode = False
password = None
save = False
dlg.Destroy()
return retcode, password, save
def SSLClientCert(self):
dlg = wx.FileDialog(wx.GetApp().GetTopWindow(),
message="Choose certificate",
style=wx.OPEN|wx.FILE_MUST_EXIST|wx.CHANGE_DIR
)
# dlg.CenterOnParent() # wxBug: caused crash with wx.FileDialog
if dlg.ShowModal() == wx.ID_OK:
retcode = True
certfile = dlg.GetPath()
else:
retcode = False
certfile = None
dlg.Destroy()
return retcode, certfile
#----------------------------------------------------------------------------
# Service Methods
#----------------------------------------------------------------------------
def InstallControls(self, frame, menuBar = None, toolBar = None, statusBar = None, document = None):
menu = menuBar.GetMenu(menuBar.FindMenu(_("Project")))
menu.AppendSeparator()
wx.EVT_MENU(frame, SVNService.SVN_UPDATE_ALL_ID, self.ProcessEvent)
wx.EVT_UPDATE_UI(frame, SVNService.SVN_UPDATE_ALL_ID, self.ProcessUpdateUIEvent)
menu.Append(SVNService.SVN_UPDATE_ALL_ID, _("SVN Update All in Project"), _("Update all files in a project from Subversion"))
wx.EVT_MENU(frame, SVNService.SVN_CHECKIN_ALL_ID, self.ProcessEvent)
wx.EVT_UPDATE_UI(frame, SVNService.SVN_CHECKIN_ALL_ID, self.ProcessUpdateUIEvent)
menu.Append(SVNService.SVN_CHECKIN_ALL_ID, _("SVN Commit All in Project..."), _("Commit all files changes in a project to Subversion"))
wx.EVT_MENU(frame, SVNService.SVN_UPDATE_ID, self.ProcessEvent)
wx.EVT_UPDATE_UI(frame, SVNService.SVN_UPDATE_ID, self.ProcessUpdateUIEvent)
menu.Append(SVNService.SVN_UPDATE_ID, _("SVN Update"), _("Update file from Subversion"))
wx.EVT_MENU(frame, SVNService.SVN_CHECKIN_ID, self.ProcessEvent)
wx.EVT_UPDATE_UI(frame, SVNService.SVN_CHECKIN_ID, self.ProcessUpdateUIEvent)
menu.Append(SVNService.SVN_CHECKIN_ID, _("SVN Commit..."), _("Commit file changes to Subversion"))
wx.EVT_MENU(frame, SVNService.SVN_CHECKOUT_ID, self.ProcessEvent)
wx.EVT_UPDATE_UI(frame, SVNService.SVN_CHECKOUT_ID, self.ProcessUpdateUIEvent)
menu.Append(SVNService.SVN_CHECKOUT_ID, _("SVN Checkout..."), _("Checkout file from Subversion"))
wx.EVT_MENU(frame, SVNService.SVN_REVERT_ID, self.ProcessEvent)
wx.EVT_UPDATE_UI(frame, SVNService.SVN_REVERT_ID, self.ProcessUpdateUIEvent)
menu.Append(SVNService.SVN_REVERT_ID, _("SVN Revert"), _("Revert file from Subversion"))
menu.AppendSeparator()
wx.EVT_MENU(frame, SVNService.SVN_ADD_ID, self.ProcessEvent)
wx.EVT_UPDATE_UI(frame, SVNService.SVN_ADD_ID, self.ProcessUpdateUIEvent)
menu.Append(SVNService.SVN_ADD_ID, _("SVN Add"), _("Add file to Subversion"))
wx.EVT_MENU(frame, SVNService.SVN_DELETE_ID, self.ProcessEvent)
wx.EVT_UPDATE_UI(frame, SVNService.SVN_DELETE_ID, self.ProcessUpdateUIEvent)
menu.Append(SVNService.SVN_DELETE_ID, _("SVN Delete"), _("Delete file from Subversion"))
def ProcessEvent(self, event):
id = event.GetId()
if not SVN_INSTALLED:
if id in SVNService.SVN_COMMAND_LIST:
wx.MessageBox(_("pysvn not found. Please install pysvn"), _("Python Subversion"))
return True
return False
try:
if id == SVNService.SVN_UPDATE_ID:
wx.GetApp().GetTopWindow().SetCursor(wx.StockCursor(wx.CURSOR_WAIT))
filenames = self.GetCurrentDocuments()
if filenames:
filenames = filenames[:]
filenames.sort(self.BasenameCaseInsensitiveCompare)
else:
folderPath = self.GetCurrentFolder()
if folderPath:
filenames = [folderPath]
messageService = wx.GetApp().GetService(MessageService.MessageService)
messageService.ShowWindow()
view = messageService.GetView()
view.ClearLines()
view.AddLines(_("SVN Update:\n"))
for filename in filenames:
view.AddLines("%s\n" % filename)
try:
status = self._client.update(filename)
if status.number > 0:
view.AddLines(_("Updated to revision %s\n") % status.number)
openDocs = wx.GetApp().GetDocumentManager().GetDocuments()
for doc in openDocs:
if doc.GetFilename() == filename:
yesNoMsg = wx.MessageDialog(wx.GetApp().GetTopWindow(),
_("Updated file '%s' is currently open. Close it?") % os.path.basename(filename),
_("Close File"),
wx.YES_NO|wx.ICON_QUESTION)
yesNoMsg.CenterOnParent()
status = yesNoMsg.ShowModal()
yesNoMsg.Destroy()
if status == wx.ID_YES:
doc.DeleteAllViews()
break
else:
view.AddLines(_("Update failed.\n"))
except pysvn.ClientError, e:
view.AddLines("%s\n" % str(e))
wx.MessageBox(str(e), _("SVN Update"), wx.OK | wx.ICON_EXCLAMATION)
except:
extype, ex, tb = sys.exc_info()
view.AddLines("Update failed: (%s) %s\n" % (extype, str(ex)))
for line in traceback.format_tb(tb):
view.AddLines(line)
wx.MessageBox(_("Update failed."), _("SVN Update"), wx.OK | wx.ICON_EXCLAMATION)
wx.GetApp().GetTopWindow().SetCursor(wx.StockCursor(wx.CURSOR_DEFAULT))
return True
elif id == SVNService.SVN_UPDATE_ALL_ID:
wx.GetApp().GetTopWindow().SetCursor(wx.StockCursor(wx.CURSOR_WAIT))
messageService = wx.GetApp().GetService(MessageService.MessageService)
messageService.ShowWindow()
view = messageService.GetView()
view.ClearLines()
view.AddLines(_("SVN Update:\n"))
project = self.GetCurrentProject()
if project:
openDocs = wx.GetApp().GetDocumentManager().GetDocuments()
for doc in openDocs:
if doc.GetFilename() == project:
filenames = doc.GetFiles()[:] # make a copy and sort it.
filenames.sort(self.BasenameCaseInsensitiveCompare)
for filename in filenames:
view.AddLines("%s\n" % filename)
try:
status = self._client.update(filename)
if status.number > 0:
view.AddLines(_("Updated to revision %s\n") % status.number)
openDocs = wx.GetApp().GetDocumentManager().GetDocuments()
for doc in openDocs:
if doc.GetFilename() == filename:
yesNoMsg = wx.MessageDialog(wx.GetApp().GetTopWindow(),
_("Updated file '%s' is currently open. Close it?") % os.path.basename(filename),
_("Close File"),
wx.YES_NO|wx.CANCEL|wx.ICON_QUESTION)
yesNoMsg.CenterOnParent()
status = yesNoMsg.ShowModal()
yesNoMsg.Destroy()
if status == wx.ID_YES:
doc.DeleteAllViews()
elif status == wx.ID_NO:
pass
else: # elif status == wx.CANCEL:
wx.GetApp().GetTopWindow().SetCursor(wx.StockCursor(wx.CURSOR_DEFAULT))
return True
break
else:
view.AddLines(_("Update failed.\n"))
except pysvn.ClientError, e:
view.AddLines("%s\n" % str(e))
wx.MessageBox(str(e), _("SVN Update"), wx.OK | wx.ICON_EXCLAMATION)
except:
extype, ex, tb = sys.exc_info()
view.AddLines("Update failed: (%s) %s\n" % (extype, str(ex)))
for line in traceback.format_tb(tb):
view.AddLines(line)
wx.MessageBox(_("Update failed."), _("SVN Update"), wx.OK | wx.ICON_EXCLAMATION)
wx.GetApp().GetTopWindow().SetCursor(wx.StockCursor(wx.CURSOR_DEFAULT))
return True
elif id == SVNService.SVN_CHECKIN_ALL_ID:
filenames = []
project = self.GetCurrentProject()
if project:
openDocs = wx.GetApp().GetDocumentManager().GetDocuments()
for doc in openDocs:
if doc.GetFilename() == project:
for filename in doc.GetFiles():
if filename not in filenames:
filenames.append(filename)
filenames.sort(self.BasenameCaseInsensitiveCompare)
# ask user if dirty files should be saved first
openDocs = wx.GetApp().GetDocumentManager().GetDocuments()
for filename in filenames:
for doc in openDocs:
if doc.GetFilename() == filename and doc.IsModified():
yesNoMsg = wx.MessageDialog(wx.GetApp().GetTopWindow(),
_("'%s' has unsaved modifications. Save it before commit?") % os.path.basename(filename),
_("SVN Commit"),
wx.YES_NO|wx.CANCEL|wx.ICON_QUESTION)
yesNoMsg.CenterOnParent()
status = yesNoMsg.ShowModal()
yesNoMsg.Destroy()
if status == wx.ID_YES:
doc.Save()
elif status == wx.ID_NO:
pass
else: # elif status == wx.CANCEL:
return True
break
shortFilenames = []
for i, filename in enumerate(filenames):
shortFilename = os.path.basename(filename)
shortFilenames.append(shortFilename)
dlg = wx.Dialog(wx.GetApp().GetTopWindow(), -1, _("SVN Commit"))
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(wx.StaticText(dlg, -1, _("Comment:")), 0, wx.ALIGN_CENTER_VERTICAL)
commentText = wx.TextCtrl(dlg, -1, size=(250,-1), style=wx.TE_MULTILINE)
sizer.Add(commentText, 1, wx.EXPAND|wx.TOP, HALF_SPACE)
sizer.Add(wx.StaticText(dlg, -1, _("Files:")), 0, wx.ALIGN_CENTER_VERTICAL|wx.TOP, SPACE)
fileList = wx.CheckListBox(dlg, -1, choices = shortFilenames)
for i in range(fileList.GetCount()):
fileList.Check(i, True)
sizer.Add(fileList, 0, wx.EXPAND|wx.TOP, HALF_SPACE)
buttonSizer = wx.StdDialogButtonSizer()
okBtn = wx.Button(dlg, wx.ID_OK)
okBtn.SetDefault()
buttonSizer.AddButton(okBtn)
buttonSizer.AddButton(wx.Button(dlg, wx.ID_CANCEL))
buttonSizer.Realize()
contentSizer = wx.BoxSizer(wx.VERTICAL)
contentSizer.Add(sizer, 0, wx.ALL, SPACE)
contentSizer.Add(buttonSizer, 0, wx.ALL|wx.ALIGN_RIGHT, SPACE)
dlg.SetSizer(contentSizer)
dlg.Fit()
dlg.Layout()
dlg.CenterOnParent()
if dlg.ShowModal() == wx.ID_OK:
wx.GetApp().GetTopWindow().SetCursor(wx.StockCursor(wx.CURSOR_WAIT))
messageService = wx.GetApp().GetService(MessageService.MessageService)
messageService.ShowWindow()
view = messageService.GetView()
view.ClearLines()
view.AddLines(_("SVN Commit:\n"))
try:
selFilenames = []
for i in range(fileList.GetCount()):
if fileList.IsChecked(i):
selFilenames.append(filenames[i])
view.AddLines("%s\n" % filenames[i])
if len(selFilenames):
comment = commentText.GetValue()
status = self._client.checkin(selFilenames, comment)
if status is None:
view.AddLines(_("Nothing to commit.\n"))
elif status.number > 0:
view.AddLines(_("Committed as revision %s.\n") % status.number)
else:
view.AddLines(_("Commit failed.\n"))
except pysvn.ClientError, e:
view.AddLines("%s\n" % str(e))
wx.MessageBox(str(e), _("SVN Commit"), wx.OK | wx.ICON_EXCLAMATION)
except:
extype, ex, tb = sys.exc_info()
view.AddLines("Commit failed: (%s) %s\n" % (extype, str(ex)))
for line in traceback.format_tb(tb):
view.AddLines(line)
wx.MessageBox(_("Commit failed."), _("SVN Commit"), wx.OK | wx.ICON_EXCLAMATION)
wx.GetApp().GetTopWindow().SetCursor(wx.StockCursor(wx.CURSOR_DEFAULT))
dlg.Destroy()
return True
elif id == SVNService.SVN_CHECKIN_ID:
filenames = self.GetCurrentDocuments()[:]
filenames.sort(self.BasenameCaseInsensitiveCompare)
# ask user if dirty files should be saved first
openDocs = wx.GetApp().GetDocumentManager().GetDocuments()
for filename in filenames:
for doc in openDocs:
if doc.GetFilename() == filename and doc.IsModified():
yesNoMsg = wx.MessageDialog(wx.GetApp().GetTopWindow(),
_("'%s' has unsaved modifications. Save it before commit?") % os.path.basename(filename),
_("SVN Commit"),
wx.YES_NO|wx.CANCEL|wx.ICON_QUESTION)
yesNoMsg.CenterOnParent()
status = yesNoMsg.ShowModal()
yesNoMsg.Destroy()
if status == wx.ID_YES:
doc.Save()
elif status == wx.ID_NO:
pass
else: # elif status == wx.CANCEL:
return True
break
shortFilenames = []
for i, filename in enumerate(filenames):
shortFilename = os.path.basename(filename)
shortFilenames.append(shortFilename)
dlg = wx.Dialog(wx.GetApp().GetTopWindow(), -1, _("SVN Commit"))
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(wx.StaticText(dlg, -1, _("Comment:")), 0, wx.ALIGN_CENTER_VERTICAL)
commentText = wx.TextCtrl(dlg, -1, size=(250,-1), style=wx.TE_MULTILINE)
sizer.Add(commentText, 1, wx.EXPAND|wx.TOP, HALF_SPACE)
sizer.Add(wx.StaticText(dlg, -1, _("Files:")), 0, wx.ALIGN_CENTER_VERTICAL|wx.TOP, SPACE)
fileList = wx.CheckListBox(dlg, -1, choices = shortFilenames)
for i in range(fileList.GetCount()):
fileList.Check(i, True)
sizer.Add(fileList, 0, wx.EXPAND|wx.TOP, HALF_SPACE)
buttonSizer = wx.StdDialogButtonSizer()
okBtn = wx.Button(dlg, wx.ID_OK)
okBtn.SetDefault()
buttonSizer.AddButton(okBtn)
buttonSizer.AddButton(wx.Button(dlg, wx.ID_CANCEL))
buttonSizer.Realize()
contentSizer = wx.BoxSizer(wx.VERTICAL)
contentSizer.Add(sizer, 0, wx.ALL, SPACE)
contentSizer.Add(buttonSizer, 0, wx.ALL|wx.ALIGN_RIGHT, SPACE)
dlg.SetSizer(contentSizer)
dlg.Fit()
dlg.Layout()
dlg.CenterOnParent()
if dlg.ShowModal() == wx.ID_OK:
wx.GetApp().GetTopWindow().SetCursor(wx.StockCursor(wx.CURSOR_WAIT))
messageService = wx.GetApp().GetService(MessageService.MessageService)
messageService.ShowWindow()
view = messageService.GetView()
view.ClearLines()
view.AddLines(_("SVN Commit:\n"))
try:
selFilenames = []
for i in range(fileList.GetCount()):
if fileList.IsChecked(i):
selFilenames.append(filenames[i])
view.AddLines("%s\n" % filenames[i])
if len(selFilenames):
comment = commentText.GetValue()
status = self._client.checkin(selFilenames, comment)
if status is None:
view.AddLines(_("Nothing to commit.\n"))
elif status.number > 0:
view.AddLines(_("Committed as revision %s.\n") % status.number)
else:
view.AddLines(_("Commit failed.\n"))
except pysvn.ClientError, e:
view.AddLines("%s\n" % str(e))
wx.MessageBox(str(e), _("SVN Commit"), wx.OK | wx.ICON_EXCLAMATION)
except:
extype, ex, tb = sys.exc_info()
view.AddLines("Commit failed: (%s) %s\n" % (extype, str(ex)))
for line in traceback.format_tb(tb):
view.AddLines(line)
wx.MessageBox(_("Commit failed."), _("SVN Commit"), wx.OK | wx.ICON_EXCLAMATION)
wx.GetApp().GetTopWindow().SetCursor(wx.StockCursor(wx.CURSOR_DEFAULT))
dlg.Destroy()
return True
elif id == SVNService.SVN_CHECKOUT_ID:
config = wx.ConfigBase_Get()
svnUrl = config.Read(SVN_REPOSITORY_URL, self._defaultURL)
dlg = wx.Dialog(wx.GetApp().GetTopWindow(), -1, _("SVN Checkout"))
gridSizer = wx.FlexGridSizer(cols = 2, hgap = 5, vgap = 5)
gridSizer.Add(wx.StaticText(dlg, -1, _("Repository URL:")), 0, wx.ALIGN_CENTER_VERTICAL|wx.RIGHT|wx.TOP, HALF_SPACE)
svnUrlList = ReadSvnUrlList()
svnURLCombobox = wx.ComboBox(dlg, -1, size=(200, -1), choices=svnUrlList, style=wx.CB_DROPDOWN)
if len(svnUrlList):
svnURLCombobox.SetToolTipString(svnUrlList[0])
svnURLCombobox.SetStringSelection(svnUrlList[0])
else:
svnURLCombobox.SetToolTipString(_("Set Repository URL"))
gridSizer.Add(svnURLCombobox, 0)
gridSizer.Add(wx.StaticText(dlg, -1, _("Checkout to dir:")), 0, wx.ALIGN_CENTER_VERTICAL|wx.RIGHT|wx.TOP, HALF_SPACE)
localPath = wx.TextCtrl(dlg, -1, size = (200, -1))
localPath.SetToolTipString(_("Path in local file system where files will be located."))
findDirButton = wx.Button(dlg, -1, _("Browse..."))
def OnBrowseButton(event):
dirDlg = wx.DirDialog(wx.GetApp().GetTopWindow(), _("Choose a directory:"), style=wx.DD_DEFAULT_STYLE)
dir = localPath.GetValue()
if len(dir):
dirDlg.SetPath(dir)
dirDlg.CenterOnParent()
if dirDlg.ShowModal() == wx.ID_OK:
localPath.SetValue(dirDlg.GetPath())
localPath.SetToolTipString(localPath.GetValue())
localPath.SetInsertionPointEnd()
dirDlg.Destroy()
wx.EVT_BUTTON(findDirButton, -1, OnBrowseButton)
sizer = wx.BoxSizer(wx.HORIZONTAL)
sizer.Add(localPath, 1, wx.EXPAND)
sizer.Add(findDirButton, 0, wx.LEFT, HALF_SPACE)
gridSizer.Add(sizer, 0)
buttonSizer = wx.StdDialogButtonSizer()
okBtn = wx.Button(dlg, wx.ID_OK)
okBtn.SetDefault()
buttonSizer.AddButton(okBtn)
buttonSizer.AddButton(wx.Button(dlg, wx.ID_CANCEL))
buttonSizer.Realize()
contentSizer = wx.BoxSizer(wx.VERTICAL)
contentSizer.Add(gridSizer, 0, wx.ALL, SPACE)
contentSizer.Add(buttonSizer, 0, wx.ALL|wx.ALIGN_RIGHT, SPACE)
dlg.SetSizer(contentSizer)
dlg.Fit()
dlg.Layout()
dlg.CenterOnParent()
if dlg.ShowModal() == wx.ID_OK:
wx.GetApp().GetTopWindow().SetCursor(wx.StockCursor(wx.CURSOR_WAIT))
WriteSvnUrlList(svnURLCombobox)
messageService = wx.GetApp().GetService(MessageService.MessageService)
messageService.ShowWindow()
view = messageService.GetView()
view.ClearLines()
view.AddLines(_("SVN Checkout:\n"))
svnUrl = svnURLCombobox.GetValue()
toLocation = localPath.GetValue()
try:
self._client.checkout(svnUrl, toLocation)
view.AddLines(_("Checkout completed.\n"))
except pysvn.ClientError, e:
view.AddLines(_("Checkout failed. %s\n") % str(e))
wx.MessageBox(_("Checkout failed. %s") % str(e), _("SVN Checkout"), wx.OK | wx.ICON_EXCLAMATION)
except:
extype, ex, tb = sys.exc_info()
view.AddLines("Checkout failed: (%s) %s\n" % (extype, str(ex)))
for line in traceback.format_tb(tb):
view.AddLines(line)
wx.MessageBox(_("Checkout failed."), _("SVN Checkout"), wx.OK | wx.ICON_EXCLAMATION)
wx.GetApp().GetTopWindow().SetCursor(wx.StockCursor(wx.CURSOR_DEFAULT))
dlg.Destroy()
return True
elif id == SVNService.SVN_REVERT_ID:
wx.GetApp().GetTopWindow().SetCursor(wx.StockCursor(wx.CURSOR_WAIT))
filenames = self.GetCurrentDocuments()
messageService = wx.GetApp().GetService(MessageService.MessageService)
messageService.ShowWindow()
view = messageService.GetView()
view.ClearLines()
view.AddLines(_("SVN Revert:\n"))
for filename in filenames:
view.AddLines("%s\n" % filename)
try:
self._client.revert(filenames)
view.AddLines(_("Revert completed.\n"))
openDocs = wx.GetApp().GetDocumentManager().GetDocuments()
for doc in openDocs[:]: # need to make a copy of the list otherwise ordinality changes as we close the files
if doc.GetFilename() in filenames:
yesNoMsg = wx.MessageDialog(wx.GetApp().GetTopWindow(),
_("Reverted file '%s' is currently open. Close it?") % os.path.basename(doc.GetFilename()),
_("Close File"),
wx.YES_NO|wx.ICON_QUESTION)
yesNoMsg.CenterOnParent()
status = yesNoMsg.ShowModal()
yesNoMsg.Destroy()
if status == wx.ID_YES:
doc.DeleteAllViews()
except pysvn.ClientError, e:
view.AddLines("%s\n" % str(e))
wx.MessageBox(str(e), _("SVN Revert"), wx.OK | wx.ICON_EXCLAMATION)
except:
extype, ex, tb = sys.exc_info()
view.AddLines("Revert failed: (%s) %s\n" % (extype, str(ex)))
for line in traceback.format_tb(tb):
view.AddLines(line)
wx.MessageBox(_("Revert failed."), _("SVN Revert"), wx.OK | wx.ICON_EXCLAMATION)
wx.GetApp().GetTopWindow().SetCursor(wx.StockCursor(wx.CURSOR_DEFAULT))
return True
elif id == SVNService.SVN_ADD_ID:
wx.GetApp().GetTopWindow().SetCursor(wx.StockCursor(wx.CURSOR_WAIT))
filenames = self.GetCurrentDocuments()
messageService = wx.GetApp().GetService(MessageService.MessageService)
messageService.ShowWindow()
view = messageService.GetView()
view.ClearLines()
view.AddLines(_("SVN Add:\n"))
for filename in filenames:
view.AddLines("%s\n" % filename)
try:
self._client.add(filenames)
view.AddLines(_("Add completed.\n"))
except pysvn.ClientError, e:
view.AddLines("%s\n" % str(e))
wx.MessageBox(str(e), _("SVN Add"), wx.OK | wx.ICON_EXCLAMATION)
except:
extype, ex, tb = sys.exc_info()
view.AddLines("Add failed: (%s) %s\n" % (extype, str(ex)))
for line in traceback.format_tb(tb):
view.AddLines(line)
wx.MessageBox(_("Add failed."), _("SVN Add"), wx.OK | wx.ICON_EXCLAMATION)
wx.GetApp().GetTopWindow().SetCursor(wx.StockCursor(wx.CURSOR_DEFAULT))
return True
elif id == SVNService.SVN_DELETE_ID:
wx.GetApp().GetTopWindow().SetCursor(wx.StockCursor(wx.CURSOR_WAIT))
filenames = self.GetCurrentDocuments()
messageService = wx.GetApp().GetService(MessageService.MessageService)
messageService.ShowWindow()
view = messageService.GetView()
view.ClearLines()
view.AddLines(_("SVN Delete:\n"))
for filename in filenames:
view.AddLines("%s\n" % filename)
try:
self._client.remove(filenames)
view.AddLines(_("Delete completed.\n"))
except pysvn.ClientError, e:
view.AddLines("%s\n" % str(e))
wx.MessageBox(str(e), _("SVN Delete"), wx.OK | wx.ICON_EXCLAMATION)
except:
extype, ex, tb = sys.exc_info()
view.AddLines("Delete failed: (%s) %s\n" % (extype, str(ex)))
for line in traceback.format_tb(tb):
view.AddLines(line)
wx.MessageBox(_("Delete failed."), _("SVN Delete"), wx.OK | wx.ICON_EXCLAMATION)
wx.GetApp().GetTopWindow().SetCursor(wx.StockCursor(wx.CURSOR_DEFAULT))
return True
return False
finally:
wx.GetApp().GetTopWindow().SetCursor(wx.StockCursor(wx.CURSOR_DEFAULT))
def ProcessUpdateUIEvent(self, event):
id = event.GetId()
if id in [SVNService.SVN_CHECKIN_ID,
SVNService.SVN_REVERT_ID,
SVNService.SVN_ADD_ID,
SVNService.SVN_DELETE_ID]:
if self.GetCurrentDocuments():
event.Enable(True)
else:
event.Enable(False)
return True
elif id == SVNService.SVN_UPDATE_ID:
if self.GetCurrentDocuments() or self.GetCurrentFolder():
event.Enable(True)
else:
event.Enable(False)
return True
elif id == SVNService.SVN_CHECKOUT_ID:
event.Enable(True)
return True
elif (id == SVNService.SVN_UPDATE_ALL_ID
or id == SVNService.SVN_CHECKIN_ALL_ID):
if self.GetCurrentProject():
event.Enable(True)
else:
event.Enable(False)
return True
return False
def GetCurrentProject(self):
projectService = wx.GetApp().GetService(ProjectEditor.ProjectService)
if projectService:
projView = projectService.GetView()
return projView.GetSelectedProject()
return None
def GetCurrentDocuments(self):
projectService = wx.GetApp().GetService(ProjectEditor.ProjectService)
if projectService:
projView = projectService.GetView()
if projView.FilesHasFocus():
filenames = projView.GetSelectedFiles()
if len(filenames):
return filenames
else:
return None
doc = wx.GetApp().GetTopWindow().GetDocumentManager().GetCurrentDocument()
if doc:
filenames = [doc.GetFilename()]
else:
filenames = None
return filenames
def GetCurrentFolder(self):
projectService = wx.GetApp().GetService(ProjectEditor.ProjectService)
if projectService:
projView = projectService.GetView()
if projView.FilesHasFocus():
folderPath = projView.GetSelectedPhysicalFolder()
if folderPath:
return folderPath
return None
def BasenameCaseInsensitiveCompare(self, s1, s2):
s1L = os.path.basename(s1).lower()
s2L = os.path.basename(s2).lower()
if s1L == s2L:
return 0
elif s1L < s2L:
return -1
else:
return 1
class SVNOptionsPanel(wx.Panel):
def __init__(self, parent, id):
wx.Panel.__init__(self, parent, id)
config = wx.ConfigBase_Get()
configDir = config.Read(SVN_CONFIG_DIR, "")
borderSizer = wx.BoxSizer(wx.VERTICAL)
sizer = wx.FlexGridSizer(cols = 2, hgap = 5, vgap = 5)
sizer.AddGrowableCol(1, 1)
sizer.Add(wx.StaticText(self, -1, _("SVN Config Dir:")), 0, wx.ALIGN_CENTER_VERTICAL)
self._svnConfigDir = wx.TextCtrl(self, -1, configDir, size = (200, -1))
if configDir == "":
self._svnConfigDir.SetToolTipString(_("Path Subversion configuration directory."))
else:
self._svnConfigDir.SetToolTipString(configDir)
findDirButton = wx.Button(self, -1, _("Browse..."))
def OnBrowseButton(event):
dirDlg = wx.DirDialog(self, _("Choose a directory:"), style=wx.DD_DEFAULT_STYLE)
dir = self._svnConfigDir.GetValue()
if len(dir):
dirDlg.SetPath(dir)
dirDlg.CenterOnParent()
if dirDlg.ShowModal() == wx.ID_OK:
self._svnConfigDir.SetValue(dirDlg.GetPath())
self._svnConfigDir.SetToolTipString(self._svnConfigDir.GetValue())
self._svnConfigDir.SetInsertionPointEnd()
dirDlg.Destroy()
wx.EVT_BUTTON(findDirButton, -1, OnBrowseButton)
hsizer = wx.BoxSizer(wx.HORIZONTAL)
hsizer.Add(self._svnConfigDir, 1, wx.EXPAND)
hsizer.Add(findDirButton, 0, wx.LEFT, HALF_SPACE)
sizer.Add(hsizer, 0, wx.EXPAND)
svnUrlList = ReadSvnUrlList()
sizer.Add(wx.StaticText(self, -1, _("SVN URL:")), 0, wx.ALIGN_CENTER_VERTICAL)
self._svnURLCombobox = wx.ComboBox(self, -1, size=(200, -1), choices=svnUrlList, style=wx.CB_DROPDOWN)
if len(svnUrlList):
self._svnURLCombobox.SetToolTipString(svnUrlList[0])
self._svnURLCombobox.SetStringSelection(svnUrlList[0])
else:
self._svnURLCombobox.SetToolTipString(_("Set Repository URL"))
sizer.Add(self._svnURLCombobox, 0, wx.EXPAND)
sizer.Add(wx.StaticText(self, -1, _("SVN_SSH:")), 0, wx.ALIGN_CENTER_VERTICAL)
svnSSH = os.getenv("SVN_SSH")
if not svnSSH or svnSSH == "":
self._svnSSH = wx.TextCtrl(self, -1, size = (200, -1))
else:
self._svnSSH = wx.TextCtrl(self, -1, svnSSH, size = (200, -1))
self._svnSSH.SetToolTipString(_("Override SVN_SSH environment variable temporarily."))
findSSHButton = wx.Button(self, -1, _("Browse..."))
def OnBrowseFileButton(event):
dirDlg = wx.FileDialog(self, _("Choose a file:"), style=wx.OPEN|wx.CHANGE_DIR)
# dirDlg.CenterOnParent() # wxBug: caused crash with wx.FileDialog
if dirDlg.ShowModal() == wx.ID_OK:
self._svnSSH.SetValue(dirDlg.GetPath())
self._svnSSH.SetToolTipString(self._svnSSH.GetValue())
self._svnSSH.SetInsertionPointEnd()
dirDlg.Destroy()
wx.EVT_BUTTON(findSSHButton, -1, OnBrowseFileButton)
hsizer = wx.BoxSizer(wx.HORIZONTAL)
hsizer.Add(self._svnSSH, 1, wx.EXPAND)
hsizer.Add(findSSHButton, 0, wx.LEFT, HALF_SPACE)
sizer.Add(hsizer, 0, wx.EXPAND)
borderSizer.Add(sizer, 0, wx.ALL|wx.EXPAND, SPACE)
self.SetSizer(borderSizer)
self.Layout()
parent.AddPage(self, _("SVN"))
def GetIcon(self):
return wx.NullIcon
def OnOK(self, optionsDialog):
config = wx.ConfigBase_Get()
config.Write(SVN_CONFIG_DIR, self._svnConfigDir.GetValue())
WriteSvnUrlList(self._svnURLCombobox)
os.environ["SVN_SSH"] = self._svnSSH.GetValue()
def ReadSvnUrlList():
""" Read in list of SNV repository URLs. First in list is the last one path used. """
config = wx.ConfigBase_Get()
urlStringList = config.Read(SVN_REPOSITORY_URL)
if len(urlStringList):
urlList = eval(urlStringList)
else:
urlList = []
if len(urlList) == 0:
svnService = wx.GetApp().GetService(SVNService)
if svnService and hasattr(svnService, "_defaultURL"):
urlList.append(svnService._defaultURL)
return urlList
def WriteSvnUrlList(comboBox):
""" Save out list of SVN repository URLs from combobox. Put on top the current selection. Only save out first 10 from the list """
urlList = []
url = comboBox.GetValue()
if len(url):
urlList.append(url)
for i in range(min(comboBox.GetCount(), 10)):
url = comboBox.GetString(i)
if url not in urlList:
urlList.append(url)
config = wx.ConfigBase_Get()
config.Write(SVN_REPOSITORY_URL, urlList.__repr__())
|