Commits

Michał Górny committed 7ba8924

Use custom exceptions for os.access() results.

Comments (0)

Files changed (1)

ecleankernel/kernel.py

 from functools import partial
 from glob import glob
 
+class ReadAccessError(Exception):
+	def __init__(self, path):
+		self._path = path
+		Exception.__init__(self, '%s not readable, unable to proceed.' % path)
+
+class WriteAccessError(Exception):
+	def __init__(self, path):
+		self._path = path
+		Exception.__init__(self, '%s not writable, refusing to proceed.' % path)
+
 class PathRef(str):
 	def __init__(self, path):
 		str.__init__(self)
 	def ref(self):
 		if self._refs == 0:
 			if not os.access(self, os.R_OK):
-				raise OSError('%s not readable, unable to proceed.' % self)
+				raise ReadAccessError(self)
 		self._refs += 1
 
 	def unref(self):
 		for path in (self.vmlinuz, self.systemmap, self.config,
 				self.initramfs, self.modules, self.build):
 			if path and not os.access(path, os.W_OK):
-				raise OSError('%s not writable, refusing to proceed' % path)
+				raise WriteAccessError(path)
 
 	def __repr__(self):
 		return "Kernel(%s, '%s%s%s%s%s')" % (repr(self.version),