diff options
author | Thomas Jourdan <b.vehikel@googlemail.com> | 2009-12-06 12:40:41 (GMT) |
---|---|---|
committer | Thomas Jourdan <b.vehikel@googlemail.com> | 2009-12-06 12:40:41 (GMT) |
commit | 7ce7155dead3893e572006588fc342fb3af7ec60 (patch) | |
tree | 2bb234d6d159aa797767bf1ceccea53117dc773a /ka_debug.py | |
parent | bcde11455168a07de8a3b17f2a4d77ce8931e75d (diff) |
Layers are now arranged as a tree data structure.
Diffstat (limited to 'ka_debug.py')
-rw-r--r-- | ka_debug.py | 59 |
1 files changed, 54 insertions, 5 deletions
diff --git a/ka_debug.py b/ka_debug.py index a29acb5..4f2f71b 100644 --- a/ka_debug.py +++ b/ka_debug.py @@ -16,9 +16,12 @@ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA import logging +import sys +import traceback import os import time +"""Add support for design by contract to all classes except blacklist.""" # default path for testing on local machine DEBUG_PATH = '/home/strom/minimal/activities/Kandid.activity' DBC_BLACK_LIST = ['activity', 'ka_debug', 'kandidtube', 'setup', @@ -28,33 +31,79 @@ _start_time = time.time() _last_clock = 0.0 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 clock_now = time.clock() - print 'debug', int((time.time()-_start_time)*1000), int((clock_now-_last_clock)*1000), ':', msg + 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 err(msg): + """Log an error message.""" global _last_clock clock_now = time.clock() - print 'error', int((time.time()-_start_time)*1000), int((clock_now-_last_clock)*1000), ':', msg + print 'error', int((time.time()-_start_time)*1000), \ + int((clock_now-_last_clock)*1000), ':', msg _last_clock = clock_now _avtivate_logger() _logger.error(msg) -# Add support for design by contract. -if True: -#if False: +_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("<class '", '').replace("<type '", '') + +def dot_ref(anchor, ref): + result = '\n' + anchor + dot_id(ref) + for referenced in _ref_list: + if id(ref) == referenced: + result += ' [color=red ]' + break + _ref_list.append(id(ref)) + result += ' ;' + try: + result += '\n' + ref.dot() + finally: + return result + +#def caller(): +# try: +# raise TypeError("") +# except TypeError: +# traceback.print_stack() +# return '[%s] [%s]' % \ +# (sys.exc_info()[1], sys.exc_info()[2]) +# return '' + +def contains_by_id(this_list, this_element): + """Returns True if element in list. Comparison is done using id(). + Only for use in design by contact statements.""" + for elem in this_list: + if id(elem) == id(this_element): + return True + return False + +try_once = True +if try_once: try: + try_once = False import contract, doctest def enable_contact(module_name): + """Enables design by contact for a module.""" if module_name not in DBC_BLACK_LIST: a_modul = __import__(module_name) contract.checkmod(module_name) |