Changeset 630ef3ed1f08…
Parent b0c0553dce30…
by
Changes to one file · Browse files at 630ef3ed1f08 Showing diff from parent b0c0553dce30 Diff from another changeset...
@@ -13,7 +13,7 @@ from PyQt4.QtCore import *
from PyQt4.QtGui import *
-from mercurial import url
+from mercurial import url, config
from tortoisehg.util import hglib
from tortoisehg.hgqt.i18n import _
@@ -114,25 +114,7 @@
def refresh(self):
fn = os.path.join(self.root, '.hg', 'hgrc')
- 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>.*)$')
- cfg = iniparse.INIConfig(file(fn), optionxformvalue=None)
- self.readonly = False
- except ImportError:
- from mercurial import config
- cfg = config.config()
- cfg.read(fn)
- self.readonly = True
- except Exception, e:
- qtlib.WarningMsgBox(_('Unable to parse a config file'),
- _('%s\nReverting to read-only mode.') % str(e),
- parent=self)
- self.readonly = True
- cfg = {}
+ cfg = self.loadIniFile([fn])
self.paths = {}
if 'paths' not in cfg:
return
@@ -141,6 +123,46 @@ 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'
|
Loading...