* improve error handling
- make Checks less redundant - use Checks uniformly - metadata.package.release must exist
This commit is contained in:
@@ -75,6 +75,7 @@ class Installer:
|
|||||||
|
|
||||||
def check_requirements(self):
|
def check_requirements(self):
|
||||||
"""check system requirements"""
|
"""check system requirements"""
|
||||||
|
|
||||||
#TODO: IS THERE ENOUGH SPACE?
|
#TODO: IS THERE ENOUGH SPACE?
|
||||||
# what to do if / is split into /usr, /var, etc.
|
# what to do if / is split into /usr, /var, etc.
|
||||||
pass
|
pass
|
||||||
|
|||||||
+10
-8
@@ -49,7 +49,7 @@ class SourceInfo:
|
|||||||
def has_errors(self):
|
def has_errors(self):
|
||||||
if not self.name:
|
if not self.name:
|
||||||
return [ _("SourceInfo should have a Name") ]
|
return [ _("SourceInfo should have a Name") ]
|
||||||
return None
|
return []
|
||||||
|
|
||||||
|
|
||||||
class PackageInfo(specfile.PackageInfo):
|
class PackageInfo(specfile.PackageInfo):
|
||||||
@@ -88,13 +88,15 @@ class PackageInfo(specfile.PackageInfo):
|
|||||||
def has_errors(self):
|
def has_errors(self):
|
||||||
# FIXME: there should be real error msgs
|
# FIXME: there should be real error msgs
|
||||||
# and comment the logic here please, it isn't very clear -gurer
|
# and comment the logic here please, it isn't very clear -gurer
|
||||||
ret = (specfile.PackageInfo.has_errors(self) == None)
|
err = Checks()
|
||||||
ret = ret and self.distribution!=None
|
err.join(specfile.PackageInfo.has_errors(self))
|
||||||
ret = ret and self.distributionRelease!=None
|
err.has_tag(self.version, 'Package', 'Version')
|
||||||
ret = ret and self.architecture!=None and self.installedSize!=None
|
err.has_tag(self.release, 'Package', 'Release')
|
||||||
if ret:
|
err.has_tag(self.distribution, 'Package', 'Distribution')
|
||||||
return None
|
err.has_tag(self.distributionRelease, 'Package', 'DistributionRelease')
|
||||||
return [ _("Some error in package metadata") ]
|
err.has_tag(self.architecture, 'Package', 'Architecture')
|
||||||
|
err.has_tag(self.installedSize, 'Package', 'InstalledSize')
|
||||||
|
return err.list
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
s = specfile.PackageInfo.__str__(self)
|
s = specfile.PackageInfo.__str__(self)
|
||||||
|
|||||||
+4
-1
@@ -27,6 +27,7 @@ import pisi.archive as archive
|
|||||||
from pisi.uri import URI
|
from pisi.uri import URI
|
||||||
from pisi.metadata import MetaData
|
from pisi.metadata import MetaData
|
||||||
from pisi.files import Files
|
from pisi.files import Files
|
||||||
|
import pisi.util as util
|
||||||
|
|
||||||
class Error(pisi.Error):
|
class Error(pisi.Error):
|
||||||
pass
|
pass
|
||||||
@@ -99,7 +100,9 @@ class Package:
|
|||||||
|
|
||||||
self.metadata = MetaData()
|
self.metadata = MetaData()
|
||||||
self.metadata.read( join(outdir, ctx.const.metadata_xml) )
|
self.metadata.read( join(outdir, ctx.const.metadata_xml) )
|
||||||
if self.metadata.has_errors():
|
errs = self.metadata.has_errors()
|
||||||
|
if errs:
|
||||||
|
util.Checks.print_errors(errs)
|
||||||
raise Error, _("MetaData format wrong")
|
raise Error, _("MetaData format wrong")
|
||||||
|
|
||||||
self.files = Files()
|
self.files = Files()
|
||||||
|
|||||||
+3
-3
@@ -123,7 +123,7 @@ class PatchInfo:
|
|||||||
def has_errors(self):
|
def has_errors(self):
|
||||||
if not self.filename:
|
if not self.filename:
|
||||||
return [ _("Patch should have a filename string") ]
|
return [ _("Patch should have a filename string") ]
|
||||||
return None
|
return []
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
s = self.filename
|
s = self.filename
|
||||||
@@ -187,7 +187,7 @@ class PathInfo:
|
|||||||
def has_errors(self):
|
def has_errors(self):
|
||||||
if not self.pathname:
|
if not self.pathname:
|
||||||
return [ _("Path tag should have a name string") ]
|
return [ _("Path tag should have a name string") ]
|
||||||
return None
|
return []
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
s = self.pathname
|
s = self.pathname
|
||||||
@@ -209,7 +209,7 @@ class ComarProvide:
|
|||||||
def has_errors(self):
|
def has_errors(self):
|
||||||
if not self.om or not self.script:
|
if not self.om or not self.script:
|
||||||
return [ _("COMAR provide should have something :)") ]
|
return [ _("COMAR provide should have something :)") ]
|
||||||
return None
|
return []
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
s = self.script
|
s = self.script
|
||||||
|
|||||||
+9
-9
@@ -46,25 +46,25 @@ class FileError(Error):
|
|||||||
|
|
||||||
class Checks:
|
class Checks:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.list = None
|
self.list = []
|
||||||
|
|
||||||
def add(self, err):
|
def add(self, err):
|
||||||
if not self.list:
|
|
||||||
self.list = []
|
|
||||||
self.list.append(err)
|
self.list.append(err)
|
||||||
|
|
||||||
def join(self, list):
|
def join(self, list):
|
||||||
if list != None:
|
self.list.extend(list)
|
||||||
if not self.list:
|
|
||||||
self.list = []
|
|
||||||
self.list.extend(list)
|
|
||||||
|
|
||||||
def has_tag(self, var, section, name):
|
def has_tag(self, var, section, name):
|
||||||
if not var:
|
if not var:
|
||||||
if not self.list:
|
|
||||||
self.list = []
|
|
||||||
self.list.append(_("%s section should have a '%s' tag") % (section, name))
|
self.list.append(_("%s section should have a '%s' tag") % (section, name))
|
||||||
|
|
||||||
|
def has_error():
|
||||||
|
return len(self.list)>0
|
||||||
|
|
||||||
|
def print_errors(list):
|
||||||
|
for x in list:
|
||||||
|
ctx.ui.error(x)
|
||||||
|
print_errors = staticmethod(print_errors)
|
||||||
|
|
||||||
#########################
|
#########################
|
||||||
# string/list functions #
|
# string/list functions #
|
||||||
|
|||||||
Reference in New Issue
Block a user