[Idle-dev] CVS: idle configHandler.py,1.14,1.15

Stephen M. Gava elguavas@users.sourceforge.net
Tue, 29 Jan 2002 00:35:31 -0800


Update of /cvsroot/idlefork/idle
In directory usw-pr-cvs1:/tmp/cvs-serv3564

Modified Files:
	configHandler.py 
Log Message:
further work on config saving


Index: configHandler.py
===================================================================
RCS file: /cvsroot/idlefork/idle/configHandler.py,v
retrieving revision 1.14
retrieving revision 1.15
diff -C2 -r1.14 -r1.15
*** configHandler.py	2002/01/24 06:00:47	1.14
--- configHandler.py	2002/01/29 08:35:29	1.15
***************
*** 58,69 ****
  class IdleUserConfParser(IdleConfParser):
      """
!     IdleConfigParser specialised for user configuration handling
      """
      def Save(self):
          """
!         write loaded user configuration file back to disk
          """
!         # this is a user config, it can be written to disk
!         self.write()
  
  class IdleConf:
--- 58,126 ----
  class IdleUserConfParser(IdleConfParser):
      """
!     IdleConfigParser specialised for user configuration handling.
      """
+ 
+     def AddSection(self,section):
+         """
+         if section doesn't exist, add it
+         """
+         if not self.has_section(section):
+             self.add_section(section)
+     
+     def RemoveEmptySections(self):
+         """
+         remove any sections that have no options
+         """
+         for section in self.sections():
+             if not self.GetOptionList(section):
+                 self.remove_section(section) 
+     
+     def IsEmpty(self):
+         """
+         Remove empty sections and then return 1 if parser has no sections
+         left, else return 0.
+         """
+         self.RemoveEmptySections()
+         if self.sections():
+             return 0
+         else:
+             return 1
+     
+     def RemoveOption(self,section,option):
+         """
+         If section/option exists, remove it.
+         Returns 1 if option was removed, 0 otherwise.
+         """
+         if self.has_section(section):
+             return self.remove_option(section,option)
+     
+     def SetOption(self,section,option,value):
+         """
+         Sets option to value, adding section if required.
+         Returns 1 if option was added or changed, otherwise 0.
+         """
+         if self.has_option(section,option):
+             if self.get(section,option)==value:
+                 return 0
+             else:
+                 self.set(section,option,value)
+                 return 1
+         else:
+             if not self.has_section(section):
+                 self.add_section(section)
+             self.set(section,option,value)
+             return 1
+      
      def Save(self):
          """
!         If config isn't empty, write file to disk. If config is empty,
!         remove the file from disk if it exists.
          """
!         if not self.IsEmpty():
!             cfgFile=open(self.file,'w')
!             self.write(cfgFile)
!         else:
!             if os.path.exists(self.file):
!                 os.remove(self.file)    
  
  class IdleConf: