# HG changeset patch
# User Simon Heimberg <sim...@besonet.ch>
# Date 1249881914 -7200
# Node ID 1d8aac63e43e6fdee3dd97e75edfd8146bb67fe7
# Parent  1e86b664098740ba0fb91fcf64e89ec852248879
thgconfig: fall back to read only mode when iniparse is not available

Does not raise an error anymore (after showing the warning message)
uses mercurial.config instead of iniparse

Do not convert to list where it is not necessary

diff -r 1e86b6640987 -r 1d8aac63e43e hggtk/thgconfig.py
--- a/hggtk/thgconfig.py        Mon Aug 03 15:45:15 2009 +0200
+++ b/hggtk/thgconfig.py        Mon Aug 10 07:25:14 2009 +0200
@@ -444,10 +444,9 @@
             iniparse.INIConfig
         except ImportError:
             dialog.error_dialog(self, _('Iniparse package not found'),
-                         _('Please install iniparse package'))
-            self.destroy()
+                         _('Please install iniparse package') + '\n' +
+                         _('Settings are only shown, no changing is possible'))
             print 'Please install http://code.google.com/p/iniparse/'
-            return
 
         # Catch close events
         self.connect('response', self.should_live)
@@ -540,7 +539,7 @@
         self.ini = self.load_config(self.rcpath)
         self.refresh_vlist()
         self.pathdata.clear()
-        if 'paths' in list(self.ini):
+        if 'paths' in self.ini:
             for name in self.ini['paths']:
                 path = self.ini['paths'][name]
                 safepath = hglib.toutf(url.hidepassword(path))
@@ -619,7 +618,7 @@
 
     def dirty_event(self, *args):
         if not self.dirty:
-            self._btn_apply.set_sensitive(True)
+            self._btn_apply.set_sensitive(not hasattr(self.ini, '_readonly'))
             self.dirty = True
 
     def _add_path(self, *args):
@@ -925,8 +924,15 @@
             f.write(_('# Generated by tortoisehg-config\n'))
             f.close()
         self.fn = fn
-        import iniparse
-        return iniparse.INIConfig(file(fn), optionxformvalue=None)
+        try:
+            import iniparse
+            return iniparse.INIConfig(file(fn), optionxformvalue=None)
+        except ImportError:
+            from mercurial import config
+            cfg = config.config()
+            cfg.read(fn)
+            cfg._readonly = True
+            return cfg
 
     def record_new_value(self, cpath, newvalue, keephistory=True):
         # 'newvalue' is converted to local encoding
@@ -937,7 +943,7 @@
             except KeyError:
                 pass
             return
-        if section not in list(self.ini):
+        if section not in self.ini:
             if hasattr(self.ini, '_new_namespace'):
                 self.ini._new_namespace(section)
             else:
@@ -952,6 +958,9 @@
         self.history.mrul(cpath).add(newvalue)
 
     def _apply_clicked(self, *args):
+        if hasattr(self.ini, '_readonly'):
+            #dialog? Read only access, please install ...
+            return
         # Reload history, since it may have been modified externally
         self.history.read()
 
@@ -968,7 +977,7 @@
                 cpath = '.'.join(['paths', name])
                 self.record_new_value(cpath, path, False)
                 refreshlist.append(name)
-            for name in list(self.ini.paths):
+            for name in self.ini.paths:
                 if name not in refreshlist:
                     del self.ini['paths'][name]
         elif 'paths' in list(self.ini):

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Tortoisehg-develop mailing list
Tortoisehg-develop@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tortoisehg-develop

Reply via email to