From b7d9b425ff757e6cc224770e94135c9fd9212e4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Luttringer?= Date: Wed, 19 Jun 2013 15:56:59 +0200 Subject: [PATCH] Payload directory is not mandatory execpt if there is build directory --- installsystems/exception.py | 12 +++++++++++- installsystems/image.py | 28 +++++++++++++++++----------- 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/installsystems/exception.py b/installsystems/exception.py index ff5137e..2ba9a2b 100644 --- a/installsystems/exception.py +++ b/installsystems/exception.py @@ -31,7 +31,7 @@ class ISException(Exception): Base exception class ''' - def __init__(self, message="", exception=None): + def __init__(self, message=u"", exception=None): self.message = unicode(message) self.exception = None if exception is None else sys.exc_info() @@ -71,6 +71,7 @@ class ISException(Exception): # reset color out("#R#", fd=fd, endl="") + class ISError(ISException): ''' Installsystems error; this exception will stop execution @@ -81,3 +82,12 @@ class ISWarning(ISException): ''' Installsystems warning; this exception do not stop execution ''' + + +class InvalidSourceImage(ISError): + ''' + Invalid source image errors + ''' + + def __init(self, message=u"", exception=None): + ISException(self, u"Invalid source image: " + message, exception) diff --git a/installsystems/image.py b/installsystems/image.py index 11a8089..3e48cba 100644 --- a/installsystems/image.py +++ b/installsystems/image.py @@ -336,22 +336,26 @@ class SourceImage(Image): def check_source_image(self): ''' Check if we are a valid SourceImage directories - ''' - # setup and payload are the only needed dirs - # setup are mandatory to do something - # payload directory is needed because build script chroot into payload directory - for d in (self.setup_path, self.payload_path): - if not os.path.exists(d): - raise ISError(u"Invalid source image: directory %s is missing" % d) + A vaild SourceImage contains at least a description and a setup directory. + Payload directory is mandatory is build scripts are present + ''' + # Ensure setup_path exists + if not os.path.exists(self.setup_path): + raise InvalidSourceImage(u"setup directory is missing.") + # Ensure description exists + if not os.path.exists(os.path.join(self.base_path, u"description")): + raise InvalidSourceImage(u"no description file.") + # Ensure payload directory exists if there is build directory + if not os.path.exists(self.payload_path) and os.path.exists(self.build_path): + raise InvalidSourceImage(u"payload directory is mandatory with a build directory.") + # Ensure directories are directories and accessible for d in (self.base_path, self.build_path, self.parser_path, self.setup_path, self.payload_path, self.lib_path): if os.path.exists(d): if not os.path.isdir(d): - raise ISError(u"Invalid source image: %s is not a directory" % d) + raise InvalidSourceImage(u"%s is not a directory." % d) if not os.access(d, os.R_OK|os.X_OK): - raise ISError(u"Invalid source image: unable to access to %s" % d) - if not os.path.exists(os.path.join(self.base_path, "description")): - raise ISError("Invalid source image: no description file") + raise InvalidSourceImage(u"unable to access to %s." % d) def build(self, force=False, force_payload=False, check=True, script=True): ''' @@ -450,6 +454,8 @@ class SourceImage(Image): ''' Return a generator on image payloads ''' + if not os.path.isdir(self.payload_path): + raise StopIteration() for payname in os.listdir(self.payload_path): yield payname -- GitLab