From: Gui Chen Date: Wed, 16 Oct 2013 07:59:03 +0000 (-0400) Subject: refine the error class module X-Git-Tag: 0.22~8 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=255257cda295d275ef2a9b4c4877b4fc55ada485;p=tools%2Fmic.git refine the error class module Change-Id: I1f619a4bb22d28e3d4c2fead7bf4d28bcce7baf5 Signed-off-by: Gui Chen --- diff --git a/mic/utils/errors.py b/mic/utils/errors.py index 8d720f9..f64b452 100644 --- a/mic/utils/errors.py +++ b/mic/utils/errors.py @@ -1,7 +1,5 @@ -#!/usr/bin/python -tt # -# Copyright (c) 2007 Red Hat, Inc. -# Copyright (c) 2011 Intel, Inc. +# Copyright (c) 2011~2013 Intel, Inc. # # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the Free @@ -16,11 +14,14 @@ # with this program; if not, write to the Free Software Foundation, Inc., 59 # Temple Place - Suite 330, Boston, MA 02111-1307, USA. +""" Collection of all error class """ + class CreatorError(Exception): - """An exception base class for all imgcreate errors.""" - keyword = '' + """ Based class for all mic creator errors """ + keyword = None def __init__(self, msg): + Exception.__init__(self) self.msg = msg def __str__(self): @@ -28,44 +29,50 @@ class CreatorError(Exception): self.msg = self.msg.encode('utf-8', 'ignore') else: self.msg = str(self.msg) - return self.keyword + self.msg + return self.msg -class Usage(CreatorError): - keyword = '' + def __repr__(self): + if not hasattr(self, 'keyword') or not self.keyword: + self.keyword = self.__class__.__name__ + return "<%s> %s" % (self.keyword, str(self)) - def __str__(self): - if isinstance(self.msg, unicode): - self.msg = self.msg.encode('utf-8', 'ignore') - else: - self.msg = str(self.msg) - return self.keyword + self.msg + ', please use "--help" for more info' +class Usage(CreatorError): + """ Error class for Usage """ + pass class Abort(CreatorError): - keyword = '' + """ Error class for Abort """ + pass class ConfigError(CreatorError): - keyword = '' + """ Error class for Config file """ + keyword = 'Config' class KsError(CreatorError): - keyword = '' + """ Error class for Kickstart module """ + keyword = 'Kickstart' class RepoError(CreatorError): - keyword = '' + """ Error class for Repository related """ + keyword = 'Repository' class RpmError(CreatorError): - keyword = '' + """ Error class for RPM related """ + keyword = 'RPM' class MountError(CreatorError): - keyword = '' + """ Error class for Mount related """ + keyword = 'Mount' class SnapshotError(CreatorError): - keyword = '' + """ Error class for Snapshot related """ + keyword = 'Snapshot' class SquashfsError(CreatorError): - keyword = '' + """ Error class for Squashfs related """ + keyword = 'Squashfs' class BootstrapError(CreatorError): - keyword = '' + """ Error class for Bootstrap related """ + keyword = 'Bootstrap' -class RuntimeError(CreatorError): - keyword = ''