From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id A56FC138200 for ; Mon, 12 Aug 2013 08:18:54 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id A6E08E0AF0; Mon, 12 Aug 2013 08:18:51 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 35E57E0AE7 for ; Mon, 12 Aug 2013 08:18:51 +0000 (UTC) Received: from hornbill.gentoo.org (hornbill.gentoo.org [94.100.119.163]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 0797D33EC40 for ; Mon, 12 Aug 2013 08:18:50 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by hornbill.gentoo.org (Postfix) with ESMTP id 867DAE545D for ; Mon, 12 Aug 2013 08:18:48 +0000 (UTC) From: "André Erdmann" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "André Erdmann" Message-ID: <1376295339.4d16ea3712b1694bed4f6bbbca84ef90095631cf.dywi@gentoo> Subject: [gentoo-commits] proj/R_overlay:master commit in: roverlay/ X-VCS-Repository: proj/R_overlay X-VCS-Files: roverlay/defaultscript.py roverlay/runtime.py X-VCS-Directories: roverlay/ X-VCS-Committer: dywi X-VCS-Committer-Name: André Erdmann X-VCS-Revision: 4d16ea3712b1694bed4f6bbbca84ef90095631cf X-VCS-Branch: master Date: Mon, 12 Aug 2013 08:18:48 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: f8453797-fa4e-4b48-860f-e42566c8d8e2 X-Archives-Hash: f676cf81163a16c2282a03387fef93e3 commit: 4d16ea3712b1694bed4f6bbbca84ef90095631cf Author: André Erdmann mailerd de> AuthorDate: Mon Aug 12 08:15:39 2013 +0000 Commit: André Erdmann mailerd de> CommitDate: Mon Aug 12 08:15:39 2013 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=4d16ea37 roverlay: do not fail if rrdtool is missing If rrdtool is missing: disable persistent stats collection and continue. Additionally, database setup/writing has been moved to RuntimeEnvironment. --- roverlay/defaultscript.py | 12 +++-------- roverlay/runtime.py | 54 +++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 53 insertions(+), 13 deletions(-) diff --git a/roverlay/defaultscript.py b/roverlay/defaultscript.py index 9d00e94..0aa32d8 100644 --- a/roverlay/defaultscript.py +++ b/roverlay/defaultscript.py @@ -60,6 +60,7 @@ def main ( installed, *args, **kw ): else: roverlay.hook.setup() + main_env.setup_database() retcode = os.EX_OK @@ -70,15 +71,8 @@ def main ( installed, *args, **kw ): else: die ( "unknown command: {!r}".format ( main_env.command ) ) - if main_env.stats_db_file and main_env.want_db_commit: - main_env.stats.write_database() - roverlay.hook.run ( 'db_written' ) - - if main_env.options ['dump_stats']: - print ( "\n{:-^60}".format ( " stats dump " ) ) - print ( main_env.stats ) - print ( "{:-^60}".format ( " end stats dump " ) ) - + main_env.write_database() + main_env.dump_stats() sys.exit ( retcode ) # --- end of main (...) --- diff --git a/roverlay/runtime.py b/roverlay/runtime.py index f44dbad..81a7726 100644 --- a/roverlay/runtime.py +++ b/roverlay/runtime.py @@ -4,9 +4,12 @@ # Distributed under the terms of the GNU General Public License; # either version 2 of the License, or (at your option) any later version. +import logging +import errno import os import sys + import roverlay.argparser import roverlay.core import roverlay.hook @@ -24,6 +27,7 @@ class RuntimeEnvironment ( object ): ): super ( RuntimeEnvironment, self ).__init__() + self.logger = logging.getLogger() self.HLINE = 79 * '-' self.stats = roverlay.stats.collector.static self.config = None @@ -109,10 +113,7 @@ class RuntimeEnvironment ( object ): raise - self.stats_db_file = self.config.get ( 'RRD_DB.file', None ) - if self.stats_db_file: - self.stats.setup_database ( self.config ) - + self.stats_db_file = self.config.get ( 'RRD_DB.file', None ) self.command = command self.options = options self.additional_config = additional_config @@ -125,6 +126,51 @@ class RuntimeEnvironment ( object ): self.stats.time.end ( "setup" ) # --- end of setup (...) --- + def setup_database ( self ): + if self.stats_db_file: + try: + self.stats.setup_database ( self.config ) + + except OSError as oserr: + if oserr.errno == errno.ENOENT: + self.stats_db_file = None + self.logger.error ( + 'rrdtool not available. ' + 'Persistent stats collection has been disabled.' + ) + return False + else: + raise + + else: + return True + else: + return False + # --- end of setup_database (...) --- + + def write_database ( self, hook_event=True ): + if self.stats_db_file and self.want_db_commit: + self.stats.write_database() + if hook_event: + roverlay.hook.run ( "db_written" ) + return True + else: + return False + # --- end of write_database (...) --- + + def dump_stats ( self, stream=None, force=False ): + if force or self.options ['dump_stats']: + cout = sys.stdout.write if stream is None else stream.write + + cout ( "\n{:-^60}\n".format ( " stats dump " ) ) + cout ( str ( self.stats ) ) + cout ( "\n{:-^60}\n".format ( " end stats dump " ) ) + + return True + else: + return False + # --- end of dump_stats (...) --- + def set_action_done ( self, action ): self.actions_done.add ( action ) # --- end of set_action_done (...) ---