aboutsummaryrefslogtreecommitdiffstats
path: root/libbe
diff options
context:
space:
mode:
authorW. Trevor King <wking@drexel.edu>2009-06-19 15:16:49 -0400
committerW. Trevor King <wking@drexel.edu>2009-06-19 15:16:49 -0400
commit9fb7b0d84872c9db0bb33ea791874e147c7e5f0d (patch)
tree688a0020e70b5763ca4e8184c5d40d900a4b4fa1 /libbe
parent6215862d89ed606c18df896feafbecb31bbe8ec6 (diff)
downloadbugseverywhere-9fb7b0d84872c9db0bb33ea791874e147c7e5f0d.tar.gz
Allow defaults for config.get_val() in case of missing user-config file.
Fixes bug introduced by James Rowe's previous patch: $ be list Traceback (most recent call last): ... File ".../libbe/rcs.py", line 34, in _get_matching_rcs import arch File ".../libbe/arch.py", line 29, in <module> client = config.get_val("arch_client") File ".../libbe/config.py", line 70, in get_val File "/usr/lib/python2.5/codecs.py", line 817, in open file = __builtin__.open(filename, mode, buffering) IOError: [Errno 2] No such file or directory: '/home/wking/.bugs_everywhere'
Diffstat (limited to 'libbe')
-rw-r--r--libbe/arch.py6
-rw-r--r--libbe/config.py25
2 files changed, 17 insertions, 14 deletions
diff --git a/libbe/arch.py b/libbe/arch.py
index b6d01e1..a2d6bde 100644
--- a/libbe/arch.py
+++ b/libbe/arch.py
@@ -26,9 +26,9 @@ import config
from beuuid import uuid_gen
from rcs import RCS, RCStestCase, CommandError
-client = config.get_val("arch_client")
-if client is None:
- client = "tla"
+DEFAULT_CLIENT = "tla"
+
+client = config.get_val("arch_client", default=DEFAULT_CLIENT)
def new():
return Arch()
diff --git a/libbe/config.py b/libbe/config.py
index 94c700e..9b1682a 100644
--- a/libbe/config.py
+++ b/libbe/config.py
@@ -48,7 +48,7 @@ def set_val(name, value, section="DEFAULT", encoding=None):
config.write(f)
f.close()
-def get_val(name, section="DEFAULT", encoding=None):
+def get_val(name, section="DEFAULT", default=None, encoding=None):
"""
Get a value from the per-user config file
@@ -64,15 +64,18 @@ def get_val(name, section="DEFAULT", encoding=None):
>>> get_val("junk") is None
True
"""
- if encoding == None:
- encoding = default_encoding
- config = ConfigParser.ConfigParser()
- f = codecs.open(path(), "r", encoding)
- config.readfp(f, path())
- f.close()
- try:
- return config.get(section, name)
- except ConfigParser.NoOptionError:
- return None
+ if os.path.exists(path()):
+ if encoding == None:
+ encoding = default_encoding
+ config = ConfigParser.ConfigParser()
+ f = codecs.open(path(), "r", encoding)
+ config.readfp(f, path())
+ f.close()
+ try:
+ return config.get(section, name)
+ except ConfigParser.NoOptionError:
+ return default
+ else:
+ return default
suite = doctest.DocTestSuite()