Changeset cfb74e87f48a…
Parent 630ef3ed1f08…
by
Changes to one file · Browse files at cfb74e87f48a Showing diff from parent 630ef3ed1f08 Diff from another changeset...
|
|
@@ -13,12 +13,21 @@ from PyQt4.QtCore import *
from PyQt4.QtGui import *
-from mercurial import url, config
+from mercurial import config, url, util
from tortoisehg.util import hglib
from tortoisehg.hgqt.i18n import _
from tortoisehg.hgqt import qtlib
+try:
+ import iniparse
+ # Monkypatch this regex to prevent iniparse from considering
+ # 'rem' as a comment
+ iniparse.ini.CommentLine.regex = \
+ re.compile(r'^(?P<csep>[%;#])(?P<comment>.*)$')
+except ImportError:
+ iniparse = None
+
_schemes = ['local', 'ssh', 'http', 'https']
class SyncWidget(QWidget):
@@ -114,7 +123,7 @@
def refresh(self):
fn = os.path.join(self.root, '.hg', 'hgrc')
- cfg = self.loadIniFile([fn])
+ fn, cfg = loadIniFile([fn], self)
self.paths = {}
if 'paths' not in cfg:
return
@@ -123,47 +132,6 @@ tm = PathsModel(self.paths, self)
self.tv.setModel(tm)
- def loadIniFile(self, rcpath):
- for fn in rcpath:
- if os.path.exists(fn):
- break
- else:
- for fn in rcpath:
- # Try to create a file from rcpath
- try:
- f = open(fn, 'w')
- f.write('# Generated by TortoiseHg setting dialog\n')
- f.close()
- break
- except EnvironmentError:
- pass
- else:
- qtlib.WarningMsgBox(_('Unable to create a config file'),
- _('Insufficient access rights.'), parent=self)
- fn = rcpath[0]
- cfg = config.config()
- return cfg
- try:
- import iniparse
- # Monkypatch this regex to prevent iniparse from considering
- # 'rem' as a comment
- iniparse.ini.CommentLine.regex = \
- re.compile(r'^(?P<csep>[%;#])(?P<comment>.*)$')
- return iniparse.INIConfig(file(fn), optionxformvalue=None)
- except ImportError:
- cfg = config.config()
- cfg.read(fn)
- return cfg
- except Exception, e:
- qtlib.WarningMsgBox(_('Unable to parse a config file'),
- hglib.tounicode(e), parent=self)
- cfg = config.config()
- try:
- cfg.read(fn)
- except:
- pass
- return cfg
-
def refreshUrl(self):
'User has changed schema/host/port/path'
if self.updateInProgress:
@@ -263,6 +231,7 @@ dialog = SaveDialog(self.root, alias, url, self)
if dialog.exec_() == QDialog.Accepted:
self.curalias = unicode(dialog.aliasentry.text())
+ self.refresh()
def authclicked(self):
host = unicode(self.hostentry.text())
@@ -288,6 +257,7 @@ url = self.currentUrl(False)
print 'hg push', url
+
class SaveDialog(QDialog):
def __init__(self, root, alias, url, parent):
super(SaveDialog, self).__init__(parent)
@@ -316,6 +286,30 @@ QTimer.singleShot(0, lambda:self.aliasentry.setFocus())
def accept(self):
+ if iniparse is None:
+ qtlib.WarningMsgBox(_('Unable to save an URL'),
+ _('Iniparse must be installed.'), parent=self)
+ return
+ fn = os.path.join(self.root, '.hg', 'hgrc')
+ fn, cfg = loadIniFile([fn], self)
+ if fn is None:
+ return
+ if 'paths' not in cfg:
+ cfg.new_namespace('paths')
+ alias = hglib.fromunicode(self.aliasentry.text())
+ path = hglib.fromunicode(self.urlentry.text())
+ if alias in cfg['paths']:
+ if not qtlib.QuestionMsgBox(_('Confirm URL replace'),
+ _('%s already exists, replace URL?') % alias):
+ return
+ cfg['paths'][alias] = path
+ try:
+ f = util.atomictempfile(fn, 'w', createmode=None)
+ f.write(str(cfg))
+ f.rename()
+ except IOError, e:
+ qtlib.WarningMsgBox(_('Unable to write configuration file'),
+ hglib.tounicode(e), parent=self)
super(SaveDialog, self).accept()
def reject(self):
@@ -361,9 +355,20 @@ pass
def saveInRepo(self):
+ if iniparse is None:
+ qtlib.WarningMsgBox(_('Unable to save authentication'),
+ _('Iniparse must be installed.'), parent=self)
+ return
+ fn = os.path.join(self.root, '.hg', 'hgrc')
+ fn, cfg = loadIniFile([fn], self)
super(AuthDialog, self).accept()
def saveGlobal(self):
+ if iniparse is None:
+ qtlib.WarningMsgBox(_('Unable to save authentication'),
+ _('Iniparse must be installed.'), parent=self)
+ return
+ fn, cfg = loadIniFile(util.user_rcpath(), self)
super(AuthDialog, self).accept()
def reject(self):
@@ -456,6 +461,38 @@ return self.rows[index.row()][2]
+def loadIniFile(rcpath, parent):
+ for fn in rcpath:
+ if os.path.exists(fn):
+ break
+ else:
+ for fn in rcpath:
+ # Try to create a file from rcpath
+ try:
+ f = open(fn, 'w')
+ f.write('# Generated by TortoiseHg\n')
+ f.close()
+ break
+ except EnvironmentError:
+ pass
+ else:
+ qtlib.WarningMsgBox(_('Unable to create a config file'),
+ _('Insufficient access rights.'), parent=parent)
+ return None, {}
+ try:
+ if iniparse:
+ return fn, iniparse.INIConfig(file(fn), optionxformvalue=None)
+ else:
+ cfg = config.config()
+ cfg.read(fn)
+ return cfg
+ except Exception, e:
+ qtlib.WarningMsgBox(_('Unable to parse a config file'),
+ hglib.tounicode(e), parent=parent)
+ return None, {}
+
+
+
def run(ui, *pats, **opts):
from tortoisehg.util import paths
return SyncWidget(paths.find_root(), **opts)
|
Loading...