1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
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"
|