Commits

Eric Wald  committed 33ae640

Switching to the standard library's ConfigParser in place of iniparse.

  • Participants
  • Parent commits 102a8ca

Comments (0)

Files changed (1)

File boundmode.py

 
 from mercurial.i18n import _
 from mercurial import commands, cmdutil, extensions, hg, util
-import iniparse
+from ConfigParser import RawConfigParser
 import os, sys
 
 class boundrc:
     def parserc(self, fn):
         if not os.path.exists(fn):
             return None, None, None
-        ini = iniparse.INIConfig(file(fn))
-        boundpush, autopush, isbound = None, None, False
-        try:
-            boundpush = ini['paths']['bound-push']
-        except KeyError:
-            pass;
-        try:
-            autopush = ini['paths']['auto-push']
-        except KeyError:
-            pass;
-        try:
-            isbound = ini['ui']['bound']
-        except KeyError:
-            pass;
+        
+        ini = RawConfigParser({
+                'bound-push': None,
+                'auto-push': None,
+                'bound': False,
+        })
+        
+        ini.read([fn])
+        boundpush = ini.get('paths', 'bound-push')
+        autopush = ini.get('paths', 'auto-push')
+        isbound = ini.get('ui', 'bound')
         return boundpush, autopush, isbound
 
     def __init__(self, ui, repo):
         self.userisbound = i
         
     def isbound(self):
-        if self.userisbound != None:
+        if self.userisbound is not None:
             return self.userisbound == 'True'
         return self.repoisbound == 'True'
         
         self.userboundpush = None
 
     def saveitem(self, ini, section, name, value):
-        if value == None:
-            try:
-                del ini[section][name]
-            except KeyError:
-                return
-        else:
-            if section not in list(ini):
-                # ini.new_namespace(section) (doesn't work outside tortoisehg)
-                raise util.Abort(_('section unavailable: %s') % (section))
-            ini[section][name] = value
+        if value is not None:
+            if not ini.has_section(section):
+                ini.add_section(section)
+            ini.set(section, name, value)
 
     def saverc(self):
         addline = False
         fn = self.userrc
-        if not os.path.exists(fn):
-            f = open(fn, "w")
-            #apparently there is a bug in iniparse
-            #it doesn't like an empty file
-            f.write('\n[paths]\n\n[ui]\n')
-            f.close()
-            addline = True
-        ini = iniparse.INIConfig(file(fn))
+        ini = RawConfigParser()
         self.saveitem(ini, 'paths', 'bound-push', self.userboundpush)
         self.saveitem(ini, 'paths', 'auto-push', self.userautopush)
         self.saveitem(ini, 'ui', 'bound', self.userisbound)
+        
         try:
             f = open(fn, "w")
-            f.write(str(ini))
-            if addline: f.write('\n')
+            ini.write(f)
             f.close()
         except IOError:
             return 1