Permalink
Browse files

Made logging for for local directories

Logging now looks at the calling function for its path
then looks in _that_ directory for a config file.

To reference a directory pass that directory as an arg:
ConfigFile("foo") => "./foo.cfg" relative to the .py file calling it
ConfigFile("configs","foo") => "./configs/foo.cfg")
ConfigFile("configs","foo","bar","baz") => "./configs/foo/bar/baz.cfg"
etc..
  • Loading branch information...
1 parent 7808263 commit accc6871c993eb9c2195b2f108bd95b9aa0a0be0 @theepicsnail committed Mar 23, 2011
Showing with 11 additions and 3 deletions.
  1. +11 −3 Configuration.py
View
@@ -1,11 +1,19 @@
#!/usr/bin/python
import os.path, os, ConfigParser
+import inspect
class ConfigFile:
_Valid = False
_Config = None
- def __init__(self,name):
- path=os.path.join(os.getcwd(),"Config",name+".cfg")
+ def __init__(self,*parts):
+ #get the parent's directory
+ stk = inspect.stack()
+ path = stk[1][0].f_code.co_filename
+ base = os.path.sep.join(path.split(os.path.sep)[:-1])
+ #join it with the provided parts
+ path = os.path.join(base,*parts)+".cfg"
+
+
config = ConfigParser.ConfigParser()
if not config.read(path): return; # log an error?
@@ -36,7 +44,7 @@ def __getitem__(self,arg):
def __iter__(self):
if not self._Valid: return
for i in self._Config.sections():
- yield i
+ yield i
if __name__=="__main__":
cf = ConfigFile("Foo")

0 comments on commit accc687

Please sign in to comment.