# coding: UTF-8 # Copyright 2009, 2010 Thomas Jourdan # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA import logging import os import time import math #Add support for design by contract to all classes except blacklist. # default path for testing on local machine DEBUG_ACTIVITY_PATH = '/home/strom/minimal/activities/Kandid.activity' DEBUG_PROFILE_PATH = '/home/strom/.sugar/1/' DBC_BLACK_LIST = ['activity', 'ka_debug', 'kandidtube', 'setup', ] _logger = None _start_time = time.time() _last_clock = 0.0 _try_once, locale_testrun = False, False if os.path.exists(DEBUG_ACTIVITY_PATH): locale_testrun = True _try_once = True is_DbC_activated = False def _avtivate_logger(): """Activate logger.""" global _logger if not _logger: _logger = logging.getLogger('Kandid') _logger.setLevel(logging.DEBUG) def info(msg): """Log an info message.""" global _last_clock, locale_testrun clock_now = time.clock() if locale_testrun: print 'debug', int((time.time()-_start_time)*1000), \ int((clock_now-_last_clock)*1000), ':', msg _last_clock = clock_now _avtivate_logger() _logger.debug(msg) # _logger.debug(caller()) def _matrix(mtrx, context): """Log an info message.""" xx, yx, xy, yy, x0, y0 = mtrx det = xx * yy + yx * xy if math.fabs(det) < (0.004 ** 2): global _last_clock, locale_testrun clock_now = time.clock() if locale_testrun: print 'matrix', int((time.time()-_start_time)*1000), \ int((clock_now-_last_clock)*1000), ':', context, mtrx, ', det=', det _last_clock = clock_now _avtivate_logger() _logger.debug(mtrx) # raise ValueError('det=' + str(det) + ', ' + str(mtrx)) def matrix(mtrx): """Log an info message.""" _matrix(mtrx, '') def matrix_s(mtrx): """Log matrix after save.""" _matrix(mtrx, 'save') def matrix_r(mtrx): """Log matrix before restore.""" _matrix(mtrx, 'restore') def err(msg): """Log an error message.""" global _last_clock, locale_testrun clock_now = time.clock() if locale_testrun: print 'error', int((time.time()-_start_time)*1000), \ int((clock_now-_last_clock)*1000), ':', msg _last_clock = clock_now _avtivate_logger() _logger.error(msg) _ref_list = [] def dot_start(): global _ref_list _ref_list = [] def dot_id(obj): result = '"' + str(type(obj)) + ' ' + str(id(obj)) + '"' return result.replace("'>", '').replace("