修订版 | fd950b81ea5c2bac9a0287fb4d61bdfec213b904 (tree) |
---|---|
时间 | 2013-11-02 21:08:07 |
作者 | Albert Mietus < albert AT ons-huis DOT net > |
Commiter | Albert Mietus < albert AT ons-huis DOT net > |
More logging.*
@@ -4,6 +4,8 @@ | ||
4 | 4 | |
5 | 5 | from ..ccBase import CCBase |
6 | 6 | |
7 | +import logging | |
8 | + | |
7 | 9 | class ASTBaseBase(CCBase): |
8 | 10 | """Base-Base for all AST-Nodes. Most nodes will inherit from ASTBase, but some do not. |
9 | 11 |
@@ -29,7 +31,7 @@ | ||
29 | 31 | super(ASTBase,self).__init__() |
30 | 32 | |
31 | 33 | if len(DEBUG & set(('all', 'ALL', self.__class__.__name__, 'AST',' AST2', 'init'))): |
32 | - print 'DEBUG %s::super.init(%s;%s)' % (self.__class__.__name__, self._node_no(), ",".join(str(arg) for arg in args)) | |
34 | + logging.debug ('%s::super.init(%s;%s)' % (self.__class__.__name__, self._node_no(), ",".join(str(arg) for arg in args))) | |
33 | 35 | |
34 | 36 | def walk(self, topdown=True, _top=None): |
35 | 37 | """Walk over the complete AST2, in an 'os.walk()' style (Generator) |
@@ -45,12 +47,11 @@ | ||
45 | 47 | |
46 | 48 | |
47 | 49 | if len(DEBUG & set(('all', 'ALL', 'walk'))): |
48 | - print "DEBUG {type:>50}.walk()\t {node}".format(type=type(self),node=self) | |
50 | + logging.debug("{type:>50}.walk()\t {node}".format(type=type(self),node=self)) | |
49 | 51 | descendants = self._descendants() |
50 | 52 | for d in descendants: |
51 | 53 | if not isinstance(d, ASTBase): |
52 | - import sys | |
53 | - print >>sys.stderr, "WARNING walk(): descendant '{d}' (type={type}) of node '{node}' ({no}) is not ASTBase-derived. Skipping it".format(d=d,type=type(d), node=repr(self), no=self._node_no()) | |
54 | + logging.error("WARNING walk(): descendant '{d}' (type={type}) of node '{node}' ({no}) is not ASTBase-derived. Skipping it".format(d=d,type=type(d), node=repr(self), no=self._node_no())) | |
54 | 55 | descendants.remove(d) |
55 | 56 | if topdown: |
56 | 57 | yield self,_top,descendants |
@@ -95,10 +96,8 @@ | ||
95 | 96 | try: |
96 | 97 | child_lines = "\n".join([c.dump(indent_with=indent_with, indent_level=indent_level+1) for c in self.childs]) |
97 | 98 | return ("childs=[\n" + child_lines + "]" ) if len(self.childs)>0 else "" |
98 | - except AttributeError: | |
99 | - import sys | |
100 | - print >>sys.stderr,"LOG: can't dumpChilds of %s" % self | |
101 | - # Probally .childs isn't set yet | |
99 | + except AttributeError: # Probally .childs isn't set yet | |
100 | + logging.error("Can't dumpChilds of %s" % self) | |
102 | 101 | return "" |
103 | 102 | |
104 | 103 | def _descendants(self): |
@@ -8,6 +8,7 @@ | ||
8 | 8 | from .astBase import ASTBase |
9 | 9 | from ..ccBase import CCmixInNamed |
10 | 10 | |
11 | +import logging | |
11 | 12 | |
12 | 13 | class ProtocolKindBase(ASTBase): pass # Event and such ... |
13 | 14 |
@@ -28,11 +29,11 @@ | ||
28 | 29 | def setKind(self, kind): |
29 | 30 | if self.kind == UNKNOWN: |
30 | 31 | self.kind = kind |
31 | - else: print "ERROR: Protocol-kind already set to %s. Ignored" % kinds.name(self.kind) | |
32 | + else: logging.error("Protocol-kind already set to %s. Ignored" % kinds.name(self.kind)) | |
32 | 33 | |
33 | 34 | def append(self, child): |
34 | 35 | if self.kind is child.kind: super(Protocol,self).append(child) |
35 | - else: print "Error, can append %s to %s-Protocol. Ignored!" % (kinds.name(child.kind), kinds.name(self.kind)) | |
36 | + else: logging.error("Can append %s to %s-Protocol. Ignored!" % (kinds.name(child.kind), kinds.name(self.kind))) | |
36 | 37 | |
37 | 38 | |
38 | 39 | class Event(ProtocolKindBase, CCmixInNamed): |
@@ -97,8 +97,6 @@ | ||
97 | 97 | else: # typespec is a sequence: so it becomes a MACRO type |
98 | 98 | super(Type, self).__init__(None, id=ALL_TYPES._MACRO) |
99 | 99 | self.sub_types = tuple([Type(e) for e in typespec]) |
100 | -# import sys | |
101 | -# print >> sys.stderr, 'XXX', self.__dict__ | |
102 | 100 | |
103 | 101 | def __repr__ (self, prefix=True): |
104 | 102 | retval ="" |
@@ -5,6 +5,8 @@ | ||
5 | 5 | from donjon.ccBase import CCBase |
6 | 6 | from donjon.sdg import vsymbols |
7 | 7 | |
8 | +import logging | |
9 | + | |
8 | 10 | def _GVid(node): |
9 | 11 | return node.className().replace('.','_DOT_') + '_' + str(node._node_no()) |
10 | 12 |
@@ -140,7 +142,7 @@ | ||
140 | 142 | MemberBase: ',shape=cds', |
141 | 143 | } |
142 | 144 | except ImportError as e: |
143 | - print "Can't create MARKERS:", e | |
145 | + logging.error("Can't create MARKERS: %s"% e) | |
144 | 146 | MARKERS={} |
145 | 147 | |
146 | 148 | m = '' |
@@ -1,6 +1,5 @@ | ||
1 | 1 | # Copyright (C) ALbert Mietus, SoftwareBeterMaken.nl; 2013. Part of Castle-project |
2 | 2 | |
3 | -import sys | |
4 | 3 | import logging |
5 | 4 | |
6 | 5 | USE_CPICKLE=True # cPickle-2.7 has a assert bug! |
@@ -18,7 +17,7 @@ | ||
18 | 17 | parser = CastleParser(tokens) |
19 | 18 | ast1 = parser.parse(src) |
20 | 19 | except IOError,e: |
21 | - print >> sys.stderr, "IO Error:", e, "for file:", src | |
20 | + logging.error("IO Error: %s for file:%s", e, src) | |
22 | 21 | return |
23 | 22 | |
24 | 23 | # Walk the ast1: to produce the ast2. which also checks the ast1 |
@@ -37,14 +36,14 @@ | ||
37 | 36 | gvfile=file(filename, 'w') |
38 | 37 | gvfile.write("%s" % gen.toDOT(ast1.tree)) |
39 | 38 | except IOError,e: |
40 | - print >> sys.stderr, "IO Error:", e, | |
39 | + logging.error("IO Error: %s", e) | |
41 | 40 | |
42 | 41 | def ast2_dump(ast2, filename): |
43 | 42 | try: |
44 | 43 | dumpfile=file(filename, 'w') |
45 | 44 | dumpfile.write(ast2.dump(indent_with="\t", indent_level=0)) |
46 | 45 | except IOError,e: |
47 | - print >> sys.stderr, "IO Error:", e, | |
46 | + logging.error("IO Error: %s", e) | |
48 | 47 | |
49 | 48 | def ast2_GV(ast2, filename): |
50 | 49 | import donjon.aux.graphviz as graphviz |
@@ -52,7 +51,7 @@ | ||
52 | 51 | gvfile=file(filename, 'w') |
53 | 52 | gvfile.write(graphviz.dumpGV(ast2,header=True)) |
54 | 53 | except IOError,e: |
55 | - print >> sys.stderr, "IO Error:", e, | |
54 | + logging.error("IO Error: %s", e) | |
56 | 55 | |
57 | 56 | |
58 | 57 | def ast2_pickle(ast2, filename): |
@@ -64,7 +63,7 @@ | ||
64 | 63 | pickle.dump(ast2,picklefile, -1) |
65 | 64 | pickle.dump(CCBase._node_counter,picklefile, -1) |
66 | 65 | except IOError,e: |
67 | - print >> sys.stderr, "IO Error:", e, | |
66 | + logging.error("IO Error: %s", e) | |
68 | 67 | |
69 | 68 | |
70 | 69 | def ast2_unpickle(ast2_filename): |
@@ -77,8 +76,7 @@ | ||
77 | 76 | CCBase._node_counter = pickle.load(picklefile) |
78 | 77 | return ast2 |
79 | 78 | except IOError,e: |
80 | - import sys | |
81 | - print >> sys.stderr, "IO Error:", e, | |
79 | + logging.error("IO Error: %s", e) | |
82 | 80 | |
83 | 81 | |
84 | 82 | def AST2debug(debug_options): |
@@ -9,6 +9,8 @@ | ||
9 | 9 | from donjon.ast.implementation import Implement |
10 | 10 | from ..ccBase import CCmixInNamed |
11 | 11 | |
12 | +import logging | |
13 | + | |
12 | 14 | class VirtSymBase(SDGBase, CCmixInNamed): |
13 | 15 | __str__ = CCmixInNamed.getName |
14 | 16 |
@@ -49,6 +51,6 @@ | ||
49 | 51 | elif isinstance(side, Component) and self.component is None: |
50 | 52 | self.component = side |
51 | 53 | else: |
52 | - print "ERROR: Can't add %s to correct side of %s vsymbol (%)" % (side, type(self), self.getName()) | |
54 | + logging.error("Can't add %s to correct side of %s vsymbol (%)" % (side, type(self), self.getName())) | |
53 | 55 | |
54 | 56 |