[kupfer] config: get_data_file raises if data file not found



commit bacec9af52d998d65af3e834d6394fecd48f1587
Author: Ulrik Sverdrup <ulrik sverdrup gmail com>
Date:   Mon Sep 14 05:33:22 2009 +0200

    config: get_data_file raises if data file not found
    
    Let us design some of the config functions so that they raise if
    nothing found. However, there is a difference between the ones where
    lookup is critical and others only opportunistic.
    
    fix msg

 kupfer/config.py |   11 +++++++++--
 1 files changed, 9 insertions(+), 2 deletions(-)
---
diff --git a/kupfer/config.py b/kupfer/config.py
index 194556d..5607c4f 100644
--- a/kupfer/config.py
+++ b/kupfer/config.py
@@ -7,6 +7,9 @@ import os
 
 PACKAGE_NAME="kupfer"
 
+class ResourceLookupError (StandardError):
+	pass
+
 def get_cache_home():
 	"""
 	Directory where cache files should be put
@@ -32,7 +35,7 @@ def get_cache_file(path=()):
 def get_data_file(filename, package=PACKAGE_NAME):
 	"""
 	Return path to @filename if it exists
-	anywhere in the data paths, else return None
+	anywhere in the data paths, else raise ResourceLookupError.
 	"""
 	data_paths = []
 	try:
@@ -51,7 +54,11 @@ def get_data_file(filename, package=PACKAGE_NAME):
 		file_path = os.path.join(direc, filename)
 		if os.path.exists(file_path):
 			return file_path
-	return None
+	if package == PACKAGE_NAME:
+		raise ResourceLookupError("Resource %s not found" % filename)
+	else:
+		raise ResourceLookupError("Resource %s in package %s not found" %
+			(filename, package))
 
 def save_data_file(filename):
 	"""



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