From a567a335b63b32bac5131bdda92a6f180c97e45e Mon Sep 17 00:00:00 2001 From: Narayan Desai Date: Fri, 30 Oct 2009 14:16:22 +0000 Subject: bcfg2-info: fix traceback when python-profiler is not available (see Ticket #767 for details) git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@5516 ce84e21b-d406-0410-9b95-82705330c041 --- src/sbin/bcfg2-info | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'src/sbin') diff --git a/src/sbin/bcfg2-info b/src/sbin/bcfg2-info index 801fb1fc1..fd29f314f 100755 --- a/src/sbin/bcfg2-info +++ b/src/sbin/bcfg2-info @@ -9,11 +9,16 @@ import getopt import logging import lxml.etree import os -import profile -import pstats import sys import tempfile +try: + import profile + import pstats + have_profile = True +except: + have_profile = False + import Bcfg2.Logger import Bcfg2.Options import Bcfg2.Server.Core @@ -410,6 +415,9 @@ Usage: [quit|exit]""" print(cand[0].name) def do_profile(self, arg): + if not have_profile: + print("Profiling functionality not available") + return tracefname = tempfile.mktemp() p = profile.Profile() p.runcall(self.onecmd, arg) @@ -436,14 +444,15 @@ if __name__ == '__main__': 'encoding': Bcfg2.Options.ENCODING}) setup = Bcfg2.Options.OptionParser(optinfo) setup.parse(sys.argv[1:]) - print(setup) - if setup['profile']: + if setup['profile'] and have_profile: prof = profile.Profile() loop = prof.runcall(infoCore, setup['repo'], setup['plugins'], setup['password'], setup['encoding'], setup['event debug']) displayTrace(prof) else: + if setup['profile']: + print("Profiling functionality not available") loop = infoCore(setup['repo'], setup['plugins'], setup['password'], setup['encoding'], setup['event debug']) -- cgit v1.2.3-1-g7c22