Chris@158
|
1 # -*- coding: utf-8 -*-
|
Chris@158
|
2 #
|
Chris@158
|
3 # EasyMercurial
|
Chris@158
|
4 #
|
Chris@158
|
5 # Based on hgExplorer by Jari Korhonen
|
Chris@158
|
6 # Copyright (c) 2010 Jari Korhonen
|
Chris@158
|
7 # Copyright (c) 2010 Chris Cannam
|
Chris@158
|
8 # Copyright (c) 2010 Queen Mary, University of London
|
Chris@158
|
9 #
|
Chris@158
|
10 # This program is free software; you can redistribute it and/or
|
Chris@158
|
11 # modify it under the terms of the GNU General Public License as
|
Chris@158
|
12 # published by the Free Software Foundation; either version 2 of the
|
Chris@158
|
13 # License, or (at your option) any later version. See the file
|
Chris@158
|
14 # COPYING included with this distribution for more information.
|
Chris@158
|
15
|
Chris@158
|
16 import sys
|
Chris@158
|
17 from mercurial import ui, getpass, util
|
Chris@158
|
18 from mercurial.i18n import _
|
Chris@188
|
19
|
Chris@188
|
20 # The value assigned here may be modified during installation, by
|
Chris@188
|
21 # replacing its default value with another one. We can't compare
|
Chris@188
|
22 # against its default value, because then the comparison text would
|
Chris@188
|
23 # get modified as well. So, compare using prefix only.
|
Chris@188
|
24 #
|
Chris@188
|
25 easyhg_import_path = 'NO_EASYHG_IMPORT_PATH'
|
Chris@188
|
26 if not easyhg_import_path.startswith('NO_'):
|
Chris@369
|
27 # We have an installation path: append it twice, once with
|
Chris@369
|
28 # the Python version suffixed
|
Chris@372
|
29 version_suffix = "Py" + str(sys.version_info[0]) + "." + str(sys.version_info[1]);
|
Chris@372
|
30 sys.path.append(easyhg_import_path + "/" + version_suffix)
|
Chris@188
|
31 sys.path.append(easyhg_import_path)
|
Chris@188
|
32
|
Chris@210
|
33 # Try to load the PyQt4 module that we need. If this fails, we should
|
Chris@210
|
34 # bail out later (in uisetup), because if we bail out now, Mercurial
|
Chris@210
|
35 # will just continue without us and report success. The invoking
|
Chris@210
|
36 # application needs to be able to discover whether the module load
|
Chris@210
|
37 # succeeded or not, so we need to ensure that Mercurial itself returns
|
Chris@210
|
38 # failure if it didn't.
|
Chris@210
|
39 #
|
Chris@210
|
40 easyhg_pyqt_ok = True
|
Chris@210
|
41 try:
|
Chris@210
|
42 from PyQt4 import QtGui
|
Chris@236
|
43 except ImportError:
|
Chris@210
|
44 easyhg_pyqt_ok = False
|
Chris@158
|
45
|
Chris@158
|
46 easyhg_qtapp = None
|
Chris@158
|
47
|
Chris@158
|
48 def uisetup(ui):
|
Chris@210
|
49 if not easyhg_pyqt_ok:
|
Chris@210
|
50 raise util.Abort(_('Failed to load PyQt4 module required by easyhg.py'))
|
Chris@158
|
51 ui.__class__.prompt = easyhg_prompt
|
Chris@158
|
52 ui.__class__.getpass = easyhg_getpass
|
Chris@160
|
53 global easyhg_qtapp
|
Chris@158
|
54 easyhg_qtapp = QtGui.QApplication([])
|
Chris@158
|
55
|
Chris@158
|
56 def easyhg_prompt(self, msg, default="y"):
|
Chris@158
|
57 if not self.interactive():
|
Chris@158
|
58 self.write(msg, ' ', default, "\n")
|
Chris@158
|
59 return default
|
Chris@426
|
60 isusername = False
|
Chris@158
|
61 if msg == _('user:'):
|
Chris@358
|
62 msg = _('Username for remote repository:')
|
Chris@426
|
63 isusername = True
|
Chris@258
|
64 d = QtGui.QInputDialog()
|
Chris@258
|
65 d.setInputMode(QtGui.QInputDialog.TextInput)
|
Chris@258
|
66 d.setTextEchoMode(QtGui.QLineEdit.Normal)
|
Chris@264
|
67 d.setLabelText(msg)
|
Chris@258
|
68 d.setWindowTitle(_('EasyMercurial: Information'))
|
Chris@258
|
69 d.show()
|
Chris@258
|
70 d.raise_()
|
Chris@258
|
71 ok = d.exec_()
|
Chris@258
|
72 r = d.textValue()
|
Chris@158
|
73 if not ok:
|
Chris@426
|
74 if isusername:
|
Chris@426
|
75 raise util.Abort(_('username entry cancelled'))
|
Chris@426
|
76 else:
|
Chris@426
|
77 raise util.Abort(_('information entry cancelled'))
|
Chris@158
|
78 if not r:
|
Chris@158
|
79 return default
|
Chris@158
|
80 return r
|
Chris@158
|
81
|
Chris@158
|
82 def easyhg_getpass(self, prompt=None, default=None):
|
Chris@158
|
83 if not self.interactive():
|
Chris@158
|
84 return default
|
Chris@160
|
85 if not prompt or prompt == _('password:'):
|
Chris@358
|
86 prompt = _('Password for remote repository:');
|
Chris@258
|
87 d = QtGui.QInputDialog()
|
Chris@258
|
88 d.setInputMode(QtGui.QInputDialog.TextInput)
|
Chris@258
|
89 d.setTextEchoMode(QtGui.QLineEdit.Password)
|
Chris@258
|
90 d.setLabelText(prompt)
|
Chris@258
|
91 d.setWindowTitle(_('EasyMercurial: Password'))
|
Chris@258
|
92 d.show()
|
Chris@258
|
93 d.raise_()
|
Chris@258
|
94 ok = d.exec_()
|
Chris@258
|
95 r = d.textValue()
|
Chris@158
|
96 if not ok:
|
Chris@358
|
97 raise util.Abort(_('password entry cancelled'))
|
Chris@158
|
98 if not r:
|
Chris@158
|
99 return default
|
Chris@158
|
100 return r
|
Chris@158
|
101
|
Chris@358
|
102
|