Mercurial > MadButterfly
comparison pyink/data_monitor.py @ 1253:07e0cb1e051d
Add class consistency_checker for domview_ui.
- consistency_checker is to check consistency of the DOM-tree
associated with a domview_ui.
- It is so closed to domview_ui, so it may access private
variables.
- But, it uses public interface of domview_ui if possible.
- consistency_checker is not integrated to domview_ui for separating
functions of consistency checking from the domview_ui. It collects
relative logic into a place and setups a boundary from others.
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Tue, 11 Jan 2011 11:43:32 +0800 |
parents | |
children | 0cb5979549be |
comparison
equal
deleted
inserted
replaced
1252:71222a6b4c06 | 1253:07e0cb1e051d |
---|---|
1 import os | |
2 | |
3 ## \brief Monitor accessing on the dta model. | |
4 # | |
5 # This class is a meta-class that monitor data accessing for its instance | |
6 # classes. | |
7 # | |
8 # All methods, of instance classes, who's name is prefixed with 'do' are | |
9 # monitored. When a monitored method was called, monitor will try to lock | |
10 # _domview of the object. The method is only called if successfully acquiring | |
11 # the lock, or return immediately. The lock is released after the calling | |
12 # returned. | |
13 # | |
14 class data_monitor(type): | |
15 def __new__(mclazz, name, bases, clazz_dict): | |
16 debug_level = 0 | |
17 if os.environ.has_key('DATA_MONITOR_DBG'): | |
18 debug_level = int(os.environ['DATA_MONITOR_DBG']) | |
19 pass | |
20 | |
21 def gen_sentinel(func_name, func): | |
22 def sentinel(self, *args, **kws): | |
23 if debug_level >= 1: | |
24 print 'calling %s.%s' % (name, func_name) | |
25 pass | |
26 if debug_level >= 2: | |
27 print ' args: %s' % (repr(args)) | |
28 print ' kws: %s' % (repr(kws)) | |
29 pass | |
30 | |
31 if not self._domview.lock(): # can not lock | |
32 if debug_level >= 1: | |
33 print ' fault to lock' | |
34 pass | |
35 return | |
36 | |
37 try: | |
38 func(self, *args, **kws) | |
39 finally: | |
40 self._domview.unlock() | |
41 pass | |
42 pass | |
43 return sentinel | |
44 | |
45 for attr_name in clazz_dict: | |
46 if (not attr_name.startswith('do')) or \ | |
47 (not callable(clazz_dict[attr_name])): | |
48 continue | |
49 clazz_dict[attr_name] = \ | |
50 gen_sentinel(attr_name, clazz_dict[attr_name]) | |
51 pass | |
52 | |
53 clazz = type.__new__(mclazz, name, bases, clazz_dict) | |
54 | |
55 return clazz | |
56 pass | |
57 |