Changeset 8db65cfc4e1f…
Parent a4b404ee094c…
by
Changes to 7 files · Browse files at 8db65cfc4e1f Showing diff from parent a4b404ee094c Diff from another changeset...
@@ -16,6 +16,7 @@ from tortoisehg.hgqt.i18n import _
from tortoisehg.util import hglib, shlib, wconfig, bugtraq
from tortoisehg.hgqt import qtlib, qscilib, status, cmdui, branchop, revpanel
+from tortoisehg.hgqt import hgrcutil
# Technical Debt for CommitWidget
# disable commit button while no message is entered or no files are selected
@@ -803,7 +804,7 @@ self.saveToPath(hglib.user_rcpath())
def saveToPath(self, path):
- fn, cfg = qtlib.loadIniFile(path, self)
+ fn, cfg = hgrcutil.loadIniFile(path, self)
if not hasattr(cfg, 'write'):
qtlib.WarningMsgBox(_('Unable to save username'),
_('Iniparse must be installed.'), parent=self)
@@ -826,7 +827,7 @@
def savePushAfter(self):
path = os.path.join(self.repo.root, '.hg', 'hgrc')
- fn, cfg = qtlib.loadIniFile([path], self)
+ fn, cfg = hgrcutil.loadIniFile([path], self)
if not hasattr(cfg, 'write'):
qtlib.WarningMsgBox(_('Unable to save after commit push'),
_('Iniparse must be installed.'), parent=self)
@@ -849,7 +850,7 @@
def saveAutoInc(self):
path = os.path.join(self.repo.root, '.hg', 'hgrc')
- fn, cfg = qtlib.loadIniFile([path], self)
+ fn, cfg = hgrcutil.loadIniFile([path], self)
if not hasattr(cfg, 'write'):
qtlib.WarningMsgBox(_('Unable to save auto include list'),
_('Iniparse must be installed.'), parent=self)
|
|
@@ -0,0 +1,56 @@ + # hgrcutils.py - Functions to manipulate hgrc (or similar) files
+#
+# Copyright 2011 Angel Ezquerra <angel.ezquerra@gmail.com>
+#
+# This software may be used and distributed according to the terms of the
+# GNU General Public License version 2 or any later version.
+
+import os
+
+from tortoisehg.hgqt import qtlib
+from tortoisehg.util import wconfig
+
+def loadIniFile(rcpath, parent=None):
+ 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, {}
+
+ return fn, wconfig.readfile(fn)
+
+def setConfigValue(rcfilepath, cfgpath, value):
+ '''
+ Set a value on a config file, such as an hgrc or a .ini file
+
+ rcpfilepath: Absolute path to a configuration file
+ cfgpath: Full "path" of a configurable key
+ Format is section.keyNamee.g. 'web.name')
+ value: String value for the selected config key
+ '''
+ fn, cfg = loadIniFile([rcfilepath])
+ if not hasattr(cfg, 'write'):
+ return False
+ if fn is None:
+ return False
+ cfgFullKey = cfgpath.split('.')
+ if len(cfgFullKey) < 2:
+ return False
+ cfg.set(cfgFullKey[0], cfgFullKey[1], value)
+ try:
+ wconfig.writefile(cfg, fn)
+ except EnvironmentError, e:
+ return False
+ return True
|
@@ -17,7 +17,7 @@
from mercurial import extensions, error, util
-from tortoisehg.util import hglib, paths, wconfig
+from tortoisehg.util import hglib, paths
from tortoisehg.hgqt.i18n import _
from hgext.color import _styles
@@ -68,27 +68,6 @@ return
QDesktopServices.openUrl(QUrl(fullurl))
-def loadIniFile(rcpath, parent=None):
- 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:
- WarningMsgBox(_('Unable to create a config file'),
- _('Insufficient access rights.'), parent=parent)
- return None, {}
-
- return fn, wconfig.readfile(fn)
-
def editfiles(repo, files, lineno=None, search=None, parent=None):
if len(files) == 1:
path = repo.wjoin(files[0])
|
@@ -12,7 +12,7 @@
from tortoisehg.util import hglib
from tortoisehg.hgqt.i18n import _
-from tortoisehg.hgqt import qtlib
+from tortoisehg.hgqt import qtlib, hgrcutil
from PyQt4.QtCore import *
from PyQt4.QtGui import *
@@ -288,7 +288,7 @@ if column == 0:
shortname = hglib.fromunicode(value.toString())
abshgrcpath = os.path.join(self.rootpath(), '.hg', 'hgrc')
- if not hglib.setConfigValue(abshgrcpath, 'web.name', shortname):
+ if not hgrcutil.setConfigValue(abshgrcpath, 'web.name', shortname):
qtlib.WarningMsgBox(_('Unable to update repository name'),
_('An error occurred while updating the repository hgrc '
'file (%s)' % abshgrcpath))
|
@@ -21,9 +21,9 @@
from mercurial import error, node, merge as mergemod
-from tortoisehg.util import hglib, paths
+from tortoisehg.util import hglib, paths
from tortoisehg.hgqt.i18n import _
-from tortoisehg.hgqt import cmdui, csinfo, qtlib, thgrepo, resolve
+from tortoisehg.hgqt import cmdui, csinfo, thgrepo, resolve, hgrcutil
from tortoisehg.hgqt.update import UpdateDialog
class rUpdateDialog(UpdateDialog):
@@ -34,7 +34,7 @@ # Get configured paths
self.paths = {}
fn = self.repo.join('hgrc')
- fn, cfg = qtlib.loadIniFile([fn], self)
+ fn, cfg = hgrcutil.loadIniFile([fn], self)
if 'paths' in cfg:
for alias in cfg['paths']:
self.paths[ alias ] = cfg['paths'][alias]
|
@@ -19,7 +19,7 @@
from tortoisehg.util import hglib, wconfig
from tortoisehg.hgqt.i18n import _
-from tortoisehg.hgqt import qtlib, cmdui, thgrepo, rebase, resolve
+from tortoisehg.hgqt import qtlib, cmdui, thgrepo, rebase, resolve, hgrcutil
def parseurl(path):
if path.startswith('ssh://'):
@@ -349,7 +349,7 @@ # Refresh configured paths
self.paths = {}
fn = self.repo.join('hgrc')
- fn, cfg = qtlib.loadIniFile([fn], self)
+ fn, cfg = hgrcutil.loadIniFile([fn], self)
if 'paths' in cfg:
for alias in cfg['paths']:
self.paths[ alias ] = cfg['paths'][ alias ]
@@ -897,7 +897,7 @@ def removeAlias(self, alias):
alias = hglib.fromunicode(alias)
fn = self.repo.join('hgrc')
- fn, cfg = qtlib.loadIniFile([fn], self)
+ fn, cfg = hgrcutil.loadIniFile([fn], self)
if not hasattr(cfg, 'write'):
qtlib.WarningMsgBox(_('Unable to remove URL'),
_('Iniparse must be installed.'), parent=self)
@@ -995,7 +995,7 @@
def accept(self):
path = self.repo.join('hgrc')
- fn, cfg = qtlib.loadIniFile([path], self)
+ fn, cfg = hgrcutil.loadIniFile([path], self)
if not hasattr(cfg, 'write'):
qtlib.WarningMsgBox(_('Unable to save post pull operation'),
_('Iniparse must be installed.'), parent=self)
@@ -1065,7 +1065,7 @@
def accept(self):
fn = self.repo.join('hgrc')
- fn, cfg = qtlib.loadIniFile([fn], self)
+ fn, cfg = hgrcutil.loadIniFile([fn], self)
if not hasattr(cfg, 'write'):
qtlib.WarningMsgBox(_('Unable to save an URL'),
_('Iniparse must be installed.'), parent=self)
@@ -1233,7 +1233,7 @@
def accept(self):
path = hglib.user_rcpath()
- fn, cfg = qtlib.loadIniFile(path, self)
+ fn, cfg = hgrcutil.loadIniFile(path, self)
if not hasattr(cfg, 'write'):
qtlib.WarningMsgBox(_('Unable to save authentication'),
_('Iniparse must be installed.'), parent=self)
|
@@ -16,8 +16,6 @@ from mercurial import demandimport, revset
from mercurial import dispatch as hgdispatch
-from tortoisehg.hgqt import qtlib
-from tortoisehg.util import wconfig
demandimport.disable()
try:
@@ -722,24 +720,3 @@ else:
# hg <= 1.8
return hgdispatch._dispatch(ui, args)
-
-def setConfigValue(rcfilepath, cfgpath, value):
- '''
- rcpfilepath - absolute path to a configuration file
- cfpath - full path of a configurable, ex 'web.name'
- value - string value or None. if None, the configurable is removed
- '''
- fn, cfg = qtlib.loadIniFile([rcfilepath])
- if not hasattr(cfg, 'write'):
- return False
- if fn is None:
- return False
- cfgpath = cfgpath.split('.')
- if len(cfgpath) < 2:
- return False
- cfg.set(cfgpath[0], cfgpath[1], value)
- try:
- wconfig.writefile(cfg, fn)
- except EnvironmentError, e:
- return False
- return True
|
Loading...