Chris@158: # -*- coding: utf-8 -*- Chris@158: # Chris@158: # EasyMercurial Chris@158: # Chris@158: # Based on hgExplorer by Jari Korhonen Chris@158: # Copyright (c) 2010 Jari Korhonen Chris@158: # Copyright (c) 2010 Chris Cannam Chris@158: # Copyright (c) 2010 Queen Mary, University of London Chris@158: # Chris@158: # This program is free software; you can redistribute it and/or Chris@158: # modify it under the terms of the GNU General Public License as Chris@158: # published by the Free Software Foundation; either version 2 of the Chris@158: # License, or (at your option) any later version. See the file Chris@158: # COPYING included with this distribution for more information. Chris@158: Chris@158: import sys Chris@158: from mercurial import ui, getpass, util Chris@158: from mercurial.i18n import _ Chris@158: from PyQt4 import QtGui Chris@158: Chris@158: # This is a gross hack throughout Chris@158: Chris@158: easyhg_qtapp = None Chris@158: easyhg_userprompt = '' Chris@158: easyhg_pwdprompt = '' Chris@158: Chris@158: def uisetup(ui): Chris@158: ui.__class__.write = easyhg_write Chris@158: ui.__class__.prompt = easyhg_prompt Chris@158: ui.__class__.getpass = easyhg_getpass Chris@158: global easyhg_qtapp, easyhg_pwdprompt, easyhg_userprompt Chris@158: easyhg_qtapp = QtGui.QApplication([]) Chris@158: easyhg_pwdprompt = '' Chris@158: easyhg_userprompt = '' Chris@158: Chris@158: def easyhg_write(self, *args, **opts): Chris@158: global easyhg_pwdprompt Chris@158: global easyhg_userprompt Chris@158: for a in args: Chris@158: (pfx, div, sfx) = a.partition(': '); Chris@158: if pfx == 'realm' and sfx != '': Chris@158: easyhg_userprompt = easyhg_pwdprompt = '' + sfx + '
'; Chris@158: elif pfx == 'user' and sfx != '': Chris@158: easyhg_pwdprompt += _('Password for user') + ' ' + sfx + ':'; Chris@158: sys.stdout.write(str(a)) Chris@158: Chris@158: def easyhg_prompt(self, msg, default="y"): Chris@158: if not self.interactive(): Chris@158: self.write(msg, ' ', default, "\n") Chris@158: return default Chris@158: if msg == _('user:'): Chris@158: msg = _('User:') Chris@158: global easyhg_userprompt, easyhg_pwdprompt Chris@158: if easyhg_userprompt != '': Chris@158: msg = easyhg_userprompt + msg; Chris@158: (r,ok) = QtGui.QInputDialog.getText(None, _('Question'), Chris@158: msg, QtGui.QLineEdit.Normal) Chris@158: if not ok: Chris@158: raise util.Abort(_('response expected')) Chris@158: if not r: Chris@158: easyhg_pwdprompt += _('Password:'); Chris@158: return default Chris@158: easyhg_pwdprompt += _('Password for user') + ' ' + r + ':'; Chris@158: return r Chris@158: Chris@158: def easyhg_getpass(self, prompt=None, default=None): Chris@158: if not self.interactive(): Chris@158: return default Chris@158: global easyhg_pwdprompt Chris@158: if easyhg_pwdprompt != '': Chris@158: msg = easyhg_pwdprompt Chris@158: else: Chris@158: msg = _('Password:'); Chris@158: (r,ok) = QtGui.QInputDialog.getText(None, _('Password'), msg, Chris@158: QtGui.QLineEdit.Password) Chris@158: if not ok: Chris@158: raise util.Abort(_('response expected')) Chris@158: if not r: Chris@158: return default Chris@158: return r Chris@158: