# HG changeset patch # User Chris Cannam # Date 1291379364 0 # Node ID 006630304b69332500e7f4e107490f5f9625562c # Parent e411bb42d93498bfdf97f9f22551ae3de8af23f3 * Some work on portable password prompting diff -r e411bb42d934 -r 006630304b69 easyhg.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/easyhg.py Fri Dec 03 12:29:24 2010 +0000 @@ -0,0 +1,81 @@ +# -*- coding: utf-8 -*- +# +# EasyMercurial +# +# Based on hgExplorer by Jari Korhonen +# Copyright (c) 2010 Jari Korhonen +# Copyright (c) 2010 Chris Cannam +# Copyright (c) 2010 Queen Mary, University of London +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 2 of the +# License, or (at your option) any later version. See the file +# COPYING included with this distribution for more information. + +import sys +from mercurial import ui, getpass, util +from mercurial.i18n import _ +from PyQt4 import QtGui + +# This is a gross hack throughout + +easyhg_qtapp = None +easyhg_userprompt = '' +easyhg_pwdprompt = '' + +def uisetup(ui): + ui.__class__.write = easyhg_write + ui.__class__.prompt = easyhg_prompt + ui.__class__.getpass = easyhg_getpass + global easyhg_qtapp, easyhg_pwdprompt, easyhg_userprompt + easyhg_qtapp = QtGui.QApplication([]) + easyhg_pwdprompt = '' + easyhg_userprompt = '' + +def easyhg_write(self, *args, **opts): + global easyhg_pwdprompt + global easyhg_userprompt + for a in args: + (pfx, div, sfx) = a.partition(': '); + if pfx == 'realm' and sfx != '': + easyhg_userprompt = easyhg_pwdprompt = '' + sfx + '
'; + elif pfx == 'user' and sfx != '': + easyhg_pwdprompt += _('Password for user') + ' ' + sfx + ':'; + sys.stdout.write(str(a)) + +def easyhg_prompt(self, msg, default="y"): + if not self.interactive(): + self.write(msg, ' ', default, "\n") + return default + if msg == _('user:'): + msg = _('User:') + global easyhg_userprompt, easyhg_pwdprompt + if easyhg_userprompt != '': + msg = easyhg_userprompt + msg; + (r,ok) = QtGui.QInputDialog.getText(None, _('Question'), + msg, QtGui.QLineEdit.Normal) + if not ok: + raise util.Abort(_('response expected')) + if not r: + easyhg_pwdprompt += _('Password:'); + return default + easyhg_pwdprompt += _('Password for user') + ' ' + r + ':'; + return r + +def easyhg_getpass(self, prompt=None, default=None): + if not self.interactive(): + return default + global easyhg_pwdprompt + if easyhg_pwdprompt != '': + msg = easyhg_pwdprompt + else: + msg = _('Password:'); + (r,ok) = QtGui.QInputDialog.getText(None, _('Password'), msg, + QtGui.QLineEdit.Password) + if not ok: + raise util.Abort(_('response expected')) + if not r: + return default + return r +