[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] r16879: {projects} Update name of config parser to be more reasonable, add impo (projects/gettor)



Author: ioerror
Date: 2008-09-12 21:18:00 -0400 (Fri, 12 Sep 2008)
New Revision: 16879

Added:
   projects/gettor/gettor_config.py
Removed:
   projects/gettor/gettor_readconfig.py
Modified:
   projects/gettor/gettor_log.py
Log:
Update name of config parser to be more reasonable, add import for logger.


Copied: projects/gettor/gettor_config.py (from rev 16875, projects/gettor/gettor_readconfig.py)
===================================================================
--- projects/gettor/gettor_config.py	                        (rev 0)
+++ projects/gettor/gettor_config.py	2008-09-13 01:18:00 UTC (rev 16879)
@@ -0,0 +1,98 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+'''
+This grabs configurable values from the users' gettor config file
+if that file is not present, it will supply reasonable defaults.
+'''
+
+import os
+import sys
+import ConfigParser
+
+class gettorConf:
+    '''
+    Initialize gettor with default values if one or more
+    values are missing from the config file.
+    This will return entirely default values if the configuration file is
+    missing. Our default file location is ~/.gettorrc for the current user.
+    '''
+
+    stateDir = "/var/lib/gettor/"
+    blStateDir = stateDir + "bl/"
+    srcEmail = "gettor@xxxxxxxxxxxxxx"
+    distDir = "/var/lib/gettor/pkg/"
+    locale = "en"
+    configFile = "~/.gettorrc"
+    config = ConfigParser.ConfigParser()
+
+    def __init__(self, path = os.path.expanduser(configFile)):
+
+        self.configFile = os.path.expanduser(path)
+
+        try:
+            if os.access(self.configFile, os.R_OK):
+                readableConfigFile = True
+            else:
+                readableConfigFile = False
+
+        except OSError:
+            readableConfigFile = False
+
+        if readableConfigFile: 
+            try:
+                # It's likely that a user will make a mistake in their config
+                # If they make a mistake for now we'll ignore *everything* :-)
+                self.config.read(self.configFile)
+            except:
+                self.config.add_section("global")
+        else:
+            self.config.add_section("global")
+
+        if self.config.has_option("global", "stateDir"):
+            self.stateDir = self.config.get("global", "stateDir")
+        else:
+            self.config.set("global", "stateDir", self.stateDir)
+
+        if self.config.has_option("global", "blStateDir"):
+            self.blStateDir = self.config.get("global", "blStateDir")
+        else:
+            self.config.set("global", "blStateDir", self.blStateDir)
+
+        if self.config.has_option("global", "srcEmail"):
+            self.srcEmail = self.config.get("global", "srcEmail")
+        else:
+            self.config.set("global", "srcEmail", self.srcEmail)
+
+        if self.config.has_option("global", "distDir"):
+            self.distDir = self.config.get("global", "distDir")
+        else:
+            self.config.set("global", "distDir", self.distDir)
+
+        if self.config.has_option("global", "locale"):
+            self.lang = self.config.get("global", "locale")
+        else:
+            self.config.set("global", "locale", self.locale)
+
+    def printConfiguration(self):
+        return self.config.write(sys.stdout)
+
+    # All getter routines live below
+    def getStateDir(self):
+        return self.stateDir
+
+    def getBlStateDir(self):
+        return self.blStateDir
+
+    def getSrcEmail(self):
+        return self.srcEmail
+
+    def getDistDir(self):
+        return self.distDir
+
+    def getLang(self):
+        return self.lang
+        
+if __name__ == "__main__" :
+    c = gettorConf()
+    print "# This is a suitable default configuration. Tune to fit your needs."
+    c.printConfiguration()

Modified: projects/gettor/gettor_log.py
===================================================================
--- projects/gettor/gettor_log.py	2008-09-13 01:03:05 UTC (rev 16878)
+++ projects/gettor/gettor_log.py	2008-09-13 01:18:00 UTC (rev 16879)
@@ -6,6 +6,8 @@
 The user can choose one of those four options in a configuration file.
 '''
 
+import gettor_config
+
 class gettorLogger:
     '''
     A configurable logging system for gettor.
@@ -13,6 +15,7 @@
 
     def _init_(self):  
         # parse the configuration file so we know how we're running 
+        config = gettorConf()
     
     def log(self, message):
         # Log the message

Deleted: projects/gettor/gettor_readconfig.py
===================================================================
--- projects/gettor/gettor_readconfig.py	2008-09-13 01:03:05 UTC (rev 16878)
+++ projects/gettor/gettor_readconfig.py	2008-09-13 01:18:00 UTC (rev 16879)
@@ -1,98 +0,0 @@
-#!/usr/bin/python
-# -*- coding: utf-8 -*-
-'''
-This grabs configurable values from the users' gettor config file
-if that file is not present, it will supply reasonable defaults.
-'''
-
-import os
-import sys
-import ConfigParser
-
-class gettorConf:
-    '''
-    Initialize gettor with default values if one or more
-    values are missing from the config file.
-    This will return entirely default values if the configuration file is
-    missing. Our default file location is ~/.gettorrc for the current user.
-    '''
-
-    stateDir = "/var/lib/gettor/"
-    blStateDir = stateDir + "bl/"
-    srcEmail = "gettor@xxxxxxxxxxxxxx"
-    distDir = "/var/lib/gettor/pkg/"
-    locale = "en"
-    configFile = "~/.gettorrc"
-    config = ConfigParser.ConfigParser()
-
-    def __init__(self, path = os.path.expanduser(configFile)):
-
-        self.configFile = os.path.expanduser(path)
-
-        try:
-            if os.access(self.configFile, os.R_OK):
-                readableConfigFile = True
-            else:
-                readableConfigFile = False
-
-        except OSError:
-            readableConfigFile = False
-
-        if readableConfigFile: 
-            try:
-                # It's likely that a user will make a mistake in their config
-                # If they make a mistake for now we'll ignore *everything* :-)
-                self.config.read(self.configFile)
-            except:
-                self.config.add_section("global")
-        else:
-            self.config.add_section("global")
-
-        if self.config.has_option("global", "stateDir"):
-            self.stateDir = self.config.get("global", "stateDir")
-        else:
-            self.config.set("global", "stateDir", self.stateDir)
-
-        if self.config.has_option("global", "blStateDir"):
-            self.blStateDir = self.config.get("global", "blStateDir")
-        else:
-            self.config.set("global", "blStateDir", self.blStateDir)
-
-        if self.config.has_option("global", "srcEmail"):
-            self.srcEmail = self.config.get("global", "srcEmail")
-        else:
-            self.config.set("global", "srcEmail", self.srcEmail)
-
-        if self.config.has_option("global", "distDir"):
-            self.distDir = self.config.get("global", "distDir")
-        else:
-            self.config.set("global", "distDir", self.distDir)
-
-        if self.config.has_option("global", "locale"):
-            self.lang = self.config.get("global", "locale")
-        else:
-            self.config.set("global", "locale", self.locale)
-
-    def printConfiguration(self):
-        return self.config.write(sys.stdout)
-
-    # All getter routines live below
-    def getStateDir(self):
-        return self.stateDir
-
-    def getBlStateDir(self):
-        return self.blStateDir
-
-    def getSrcEmail(self):
-        return self.srcEmail
-
-    def getDistDir(self):
-        return self.distDir
-
-    def getLang(self):
-        return self.lang
-        
-if __name__ == "__main__" :
-    c = gettorConf()
-    print "# This is a suitable default configuration. Tune to fit your needs."
-    c.printConfiguration()