Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/ka_debug.py
diff options
context:
space:
mode:
Diffstat (limited to 'ka_debug.py')
-rw-r--r--ka_debug.py75
1 files changed, 75 insertions, 0 deletions
diff --git a/ka_debug.py b/ka_debug.py
new file mode 100644
index 0000000..a29acb5
--- /dev/null
+++ b/ka_debug.py
@@ -0,0 +1,75 @@
+# coding: UTF8
+# Copyright 2009 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
+
+# default path for testing on local machine
+DEBUG_PATH = '/home/strom/minimal/activities/Kandid.activity'
+DBC_BLACK_LIST = ['activity', 'ka_debug', 'kandidtube', 'setup',
+ 'test_suite', 'test_enumerator']
+_logger = None
+_start_time = time.time()
+_last_clock = 0.0
+
+def _avtivate_logger():
+ global _logger
+ if not _logger:
+ _logger = logging.getLogger('Kandid')
+ _logger.setLevel(logging.DEBUG)
+
+def info(msg):
+ global _last_clock
+ clock_now = time.clock()
+ print 'debug', int((time.time()-_start_time)*1000), int((clock_now-_last_clock)*1000), ':', msg
+ _last_clock = clock_now
+ _avtivate_logger()
+ _logger.debug(msg)
+
+def err(msg):
+ global _last_clock
+ clock_now = time.clock()
+ 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:
+ try:
+ import contract, doctest
+ def enable_contact(module_name):
+ if module_name not in DBC_BLACK_LIST:
+ a_modul = __import__(module_name)
+ contract.checkmod(module_name)
+ doctest.testmod(a_modul)
+ # print 'enable_contact', a_modul
+
+ bundle_path = DEBUG_PATH
+ if 'SUGAR_BUNDLE_PATH' in os.environ:
+ from sugar.activity import activity
+ bundle_path = activity.get_bundle_path()
+ for element in os.listdir(bundle_path):
+ if element.endswith('.py') \
+ and os.path.isfile(os.path.join(bundle_path, element)):
+ name_parts = element.split('.')
+ if len(name_parts) == 2:
+ enable_contact(name_parts[0])
+ except ImportError:
+ print "unsupported design by contract"