# Path: tracer/resources/exceptions.py
# class PathNotFound(OSError, Printable):
# 
# 	@property
# 	def message(self):
# 		return _(
# 			"Problem occurred - neither one of {0} paths exists\n"
# 			"Please contact maintainer of tracer package in your distribution.")
# 
# 	def __init__(self, name):
# 		OSError.__init__(self, self.message.format(name))
# 
# class TracerError(Exception, Printable):
# 	"""
# 	Unspecified tracer error
# 	"""
# 	def __init__(self, message):
# 		self.message = message


from xml.dom import minidom
from xml.parsers.expat import ExpatError
from tracer.paths import DATA_DIR, USER_CONFIG_DIRS
from tracer.resources.exceptions import PathNotFound, TracerError
from os.path import dirname
	def find(app_name):
		if not Rules._rules:
			Rules._load_definitions()

		for rule in Rules._rules:
			if rule.name == app_name:
				return rule

	@staticmethod
	def all():
		if not Rules._rules:
			Rules._load_definitions()

		return Rules._rules

	@staticmethod
	def _load_definitions():
		Rules._rules = []
		for file in Rules.DEFINITIONS:
			try: Rules._load(file);
			except PathNotFound as ex:
				if not dirname(file) in USER_CONFIG_DIRS:
					raise ex

	@staticmethod
	def _load(file):
		try:
			with open(file, "r") as f:
				xmldoc = minidom.parseString(f.read())
		except IOError:

# Path: tracer/resources/exceptions.py
# class PathNotFound(OSError, Printable):
# 
# 	@property
# 	def message(self):
# 		return _(
# 			"Problem occurred - neither one of {0} paths exists\n"
# 			"Please contact maintainer of tracer package in your distribution.")
# 
# 	def __init__(self, name):
# 		OSError.__init__(self, self.message.format(name))
# 
# class TracerError(Exception, Printable):
# 	"""
# 	Unspecified tracer error
# 	"""
# 	def __init__(self, message):
# 		self.message = message


# Path: tracer/resources/rules.py
from xml.dom import minidom
from xml.parsers.expat import ExpatError
from tracer.paths import DATA_DIR, USER_CONFIG_DIRS
from tracer.resources.exceptions import PathNotFound, TracerError
from os.path import dirname

	def find(app_name):
		if not Rules._rules:
			Rules._load_definitions()

		for rule in Rules._rules:
			if rule.name == app_name:
				return rule

	@staticmethod
	def all():
		if not Rules._rules:
			Rules._load_definitions()

		return Rules._rules

	@staticmethod
	def _load_definitions():
		Rules._rules = []
		for file in Rules.DEFINITIONS:
			try: Rules._load(file);
			except PathNotFound as ex:
				if not dirname(file) in USER_CONFIG_DIRS:
					raise ex

	@staticmethod
	def _load(file):
		try:
			with open(file, "r") as f:
				xmldoc = minidom.parseString(f.read())
		except IOError:

			raise PathNotFound('DATA_DIR')