Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 2.1, 2.1.1, and 2.1.2

hglib: added setConfigValue() function
This function lets you set a config value on an ini file.

Changeset 4deed4173d6f

Parent 4840023dafe9

by Angel Ezquerra

Changes to one file · Browse files at 4deed4173d6f Showing diff from parent 4840023dafe9 Diff from another changeset...

 
16
17
18
 
 
 
19
20
21
 
719
720
721
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
17
18
19
20
21
22
23
24
 
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
@@ -16,6 +16,9 @@
 from mercurial import demandimport, revset  from mercurial import dispatch as hgdispatch   +from tortoisehg.hgqt import qtlib +from tortoisehg.util import wconfig +  demandimport.disable()  try:   # hg >= 1.9 @@ -719,3 +722,24 @@
  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