]> git.ipfire.org Git - pakfire.git/commitdiff
PBS: Add more verbosity to build logs.
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 4 Mar 2012 14:29:06 +0000 (15:29 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 4 Mar 2012 14:29:06 +0000 (15:29 +0100)
When builds have crashed earlier they were not always
traces about the reason in the log. This commit tries
to fix that.

python/pakfire/actions.py
python/pakfire/base.py
python/pakfire/builder.py
python/pakfire/errors.py
python/pakfire/packages/solv.py
python/pakfire/repository/remote.py
python/pakfire/transaction.py

index 37d446f392d82373b58a6b05d2e3b36e17e0ae20..e508f135a56ba96c37780b8c22f9890b1218d865 100644 (file)
@@ -63,11 +63,11 @@ class Action(object):
                return self.type in ("install", "reinstall", "upgrade", "downgrade", "change",) \
                        and not isinstance(self.pkg, packages.BinaryPackage)
 
-       def download(self, text):
+       def download(self, text, logger=None):
                if not self.needs_download:
                        return
 
-               self.pkg = self.pkg.download(text)
+               self.pkg = self.pkg.download(text, logger=logger)
 
        def run(self):
                raise NotImplementedError
index 2a7d2263c598f399bc43ce09b7fa7c0e635bdff7..5da012e78f119ae1d43f8a2a70d42ee9c768e38d 100644 (file)
@@ -254,7 +254,7 @@ class Pakfire(object):
                        t.dump(logger=logger)
 
                # Run the transaction.
-               t.run()
+               t.run(logger=logger)
 
        def localinstall(self, files, yes=None, allow_uninstall=False):
                repo_name = repo_desc = "localinstall"
@@ -296,12 +296,12 @@ class Pakfire(object):
                                if not t.cli_yesno():
                                        return
                        elif yes:
-                               t.dump()
+                               t.dump(logger=logger)
                        else:
                                return
 
                        # If okay, run the transcation.
-                       t.run()
+                       t.run(logger=logger)
 
                finally:
                        # Remove the temporary copy of the repository we have created earlier.
@@ -461,7 +461,7 @@ class Pakfire(object):
                        return
 
                # Run the transaction.
-               t.run()
+               t.run(logger=logger)
 
        def downgrade(self, pkgs, allow_vendorchange=False, allow_archchange=False):
                assert pkgs
index 94da4cf9ec802ca72f1924d937d05de6da92c37b..2f42d01cfdd0899e68921e0bc63182a0eb1a41b5 100644 (file)
@@ -677,6 +677,8 @@ class BuildEnviron(object):
                        self.do(" ".join(build_command), logger=self.log)
 
                except Error:
+                       self.log.error(_("Build failed."), exc_info=True)
+
                        raise BuildError, _("The build command failed. See logfile for details.")
 
                # Perform install test.
index 2daa7283d21c20eeeee3bd84c2b137eab504bc10..fa9df78c84a55fe641c02d99a855e65c2432e0c2 100644 (file)
@@ -58,7 +58,8 @@ class DependencyError(Error):
        message = _("One or more dependencies could not been resolved.")
 
 class DownloadError(Error):
-       pass
+       message = _("An error occured when pakfire tried to download files.")
+
 
 class FileError(Error):
        pass
index c120ce69fd138f6acdcac8ba5e8cf96d8b40e98f..9bbbc2a3d3b4463b75157cb75b3a9eb55cb96532 100644 (file)
@@ -227,9 +227,9 @@ class SolvPackage(base.Package):
                if path and self.repo.cache.verify(path, self.hash1):
                        return file.BinaryPackage(self.pakfire, self.repo, path)
 
-       def download(self, text=""):
+       def download(self, text="", logger=None):
                if not self.repo.local:
-                       self.repo.download(self, text=text)
+                       self.repo.download(self, text=text, logger=logger)
 
                return self.get_from_cache()
 
index e707c59d1c7fe3b4c5032f3e762b5c3e9284e058..370be592142cabfdb30aa1513102d46aa2df623d 100644 (file)
@@ -70,10 +70,13 @@ class RepositorySolv(base.RepositoryFactory):
 
                return priority
 
-       def download(self, pkg, text=""):
+       def download(self, pkg, text="", logger=None):
                """
                        Downloads 'filename' from repository and returns the local filename.
                """
+               if logger is None:
+                       logger = log
+
                filename, hash1 = pkg.filename, pkg.hash1
 
                # Marker, if we need to download the package.
@@ -83,7 +86,7 @@ class RepositorySolv(base.RepositoryFactory):
 
                # Check if file already exists in cache.
                if self.cache.exists(cache_filename):
-                       log.debug("File exists in cache: %s" % filename)
+                       logger.debug("File exists in cache: %s" % filename)
 
                        # If the file does already exist, we check if the hash1 matches.
                        if hash1 and self.cache.verify(cache_filename, hash1):
@@ -104,7 +107,7 @@ class RepositorySolv(base.RepositoryFactory):
                filename = str(filename)
 
                while download:
-                       log.debug("Going to download %s" % filename)
+                       logger.debug("Going to download %s" % filename)
 
                        # If we are in offline mode, we cannot download any files.
                        if self.pakfire.offline and not self.baseurl.startswith("file://"):
@@ -125,11 +128,11 @@ class RepositorySolv(base.RepositoryFactory):
                        o.close()
 
                        if self.cache.verify(cache_filename, hash1):
-                               log.debug("Successfully downloaded %s (%s)." % (filename, hash1))
+                               logger.debug("Successfully downloaded %s (%s)." % (filename, hash1))
                                break
 
-                       log.warning(_("The checksum of the downloaded file did not match."))
-                       log.warning(_("Trying an other mirror."))
+                       logger.warning(_("The checksum of the downloaded file did not match."))
+                       logger.warning(_("Trying an other mirror."))
 
                        # Go to the next mirror.
                        grabber.increment_mirror()
index f18f9453c324cdbe0da1e3e4d715f62acd6bc6c9..5f5076d1d1c4afd0d31298be963addf2542d6305 100644 (file)
@@ -80,20 +80,23 @@ class TransactionCheck(object):
 
                return True
 
-       def print_errors(self):
+       def print_errors(self, logger=None):
+               if logger is None:
+                       logger = logging.getLogger("pakfire")
+
                for name, files in sorted(self.error_files.items()):
                        assert len(files) >= 2
 
                        pkgs = [f.pkg.friendly_name for f in files]
 
                        if len(files) == 2:
-                               log.critical(
+                               logger.critical(
                                        _("file %s from %s conflicts with file from package %s") % \
                                                (name, pkgs[0], pkgs[1])
                                )
 
                        elif len(files) >= 3:
-                               log.critical(
+                               logger.critical(
                                        _("file %s from %s conflicts with files from %s") % \
                                                (name, pkgs[0], i18n.list(pkgs[1:]))
                                )
@@ -102,8 +105,7 @@ class TransactionCheck(object):
                        if mp.space_left >= 0:
                                continue
 
-                       print util.format_size(mp.free), util.format_size(mp.disk_usage)
-                       log.critical(_("There is not enough space left on %(name)s. Need at least %(size)s to perform transaction.") \
+                       logger.critical(_("There is not enough space left on %(name)s. Need at least %(size)s to perform transaction.") \
                                % { "name" : mp.path, "size" : util.format_size(mp.space_needed) })
 
        def load_filelist(self):
@@ -264,7 +266,10 @@ class Transaction(object):
        def downloads(self):
                return sorted([a for a in self.actions if a.needs_download])
 
-       def download(self):
+       def download(self, logger=None):
+               if logger is None:
+                       logger = logging.getLogger("pakfire")
+
                # Get all download actions as a list.
                downloads = [d for d in self.downloads]
                downloads.sort()
@@ -288,19 +293,19 @@ class Transaction(object):
                        raise DownloadError, _("Not enough space to download %s of packages.") \
                                % util.format_size(download_size)
 
-               log.info(_("Downloading packages:"))
+               logger.info(_("Downloading packages:"))
                time_start = time.time()
 
                i = 0
                for action in downloads:
                        i += 1
-                       action.download(text="(%d/%d): " % (i, len(downloads)))
+                       action.download(text="(%d/%d): " % (i, len(downloads)), logger=logger)
 
                # Write an empty line to the console when there have been any downloads.
                width, height = util.terminal_size()
 
                # Print a nice line.
-               log.info("-" * width)
+               logger.info("-" * width)
 
                # Format and calculate download information.
                time_stop = time.time()
@@ -313,8 +318,8 @@ class Transaction(object):
                line = "%s | %5sB     %s     " % \
                        (download_speed, download_size, download_time)
                line = " " * (width - len(line)) + line
-               log.info(line)
-               log.info("")
+               logger.info(line)
+               logger.info("")
 
        def dump_pkg(self, pkg):
                ret = []
@@ -341,7 +346,7 @@ class Transaction(object):
 
        def dump(self, logger=None):
                if logger is None:
-                       logger = log
+                       logger = logging.getLogger("pakfire")
 
                width = 80
                line = "=" * width
@@ -394,8 +399,11 @@ class Transaction(object):
 
                return util.ask_user(_("Is this okay?"))
 
-       def check(self):
-               log.info(_("Running Transaction Test"))
+       def check(self, logger=None):
+               if logger is None:
+                       logger = logging.getLogger("pakfire")
+
+               logger.info(_("Running Transaction Test"))
 
                # Initialize the check object.
                check = TransactionCheck(self.pakfire, self)
@@ -407,33 +415,38 @@ class Transaction(object):
                                raise
 
                if check.successful:
-                       log.info(_("Transaction Test Succeeded"))
+                       logger.info(_("Transaction Test Succeeded"))
                        return
 
                # In case of an unsuccessful transaction test, we print the error
                # and raise TransactionCheckError.
-               check.print_errors()
+               check.print_errors(logger=logger)
 
                raise TransactionCheckError, _("Transaction test was not successful")
 
-       def run(self):
+       def run(self, logger=None):
                assert not self.__need_sort, "Did you forget to sort the transaction?"
 
+               if logger is None:
+                       logger = logging.getLogger("pakfire")
+
                # Download all packages.
+               # (don't add logger here because I do not want to see downloads
+               # in the build logs on the build service)
                self.download()
 
                # Run the transaction test
-               self.check()
+               self.check(logger=logger)
 
-               log.info(_("Running transaction"))
+               logger.info(_("Running transaction"))
                # Run all actions in order and catch all kinds of ActionError.
                for action in self.actions:
                        try:
                                action.run()
                        except ActionError, e:
-                               log.error("Action finished with an error: %s - %s" % (action, e))
+                               logger.error("Action finished with an error: %s - %s" % (action, e))
 
-               log.info("")
+               logger.info("")
 
                # Commit repository metadata.
                self.local.commit()