KCC: split and shift samba.graph_utils -> samba.kcc.{graph_utils,debug}
authorDouglas Bagnall <douglas.bagnall@catalyst.net.nz>
Wed, 3 Jun 2015 23:16:15 +0000 (11:16 +1200)
committerAndrew Bartlett <abartlet@samba.org>
Fri, 12 Jun 2015 04:57:13 +0000 (06:57 +0200)
The debug module contains debug functions and colours.

Graph_utils keeps the DOT file generation and graph verification code.

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Garming Sam <garming@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
python/samba/kcc/__init__.py
python/samba/kcc/debug.py [new file with mode: 0644]
python/samba/kcc/graph_utils.py [moved from python/samba/graph_utils.py with 96% similarity]
source4/scripting/bin/samba_kcc

index 67c4d4cd2b9f9021ebc52fba2738a134eb33ad50..1a90879fe71ae9c68c4172689ae64446c92ee792 100644 (file)
@@ -54,9 +54,13 @@ from samba.auth import system_session
 from samba.samdb import SamDB
 from samba.dcerpc import drsuapi
 from samba.kcc_utils import *
-from samba.graph_utils import *
+from samba.kcc.graph_utils import verify_and_dot
 from samba import ldif_utils
 
+from samba.kcc.debug import DEBUG, DEBUG_FN, logger
+from samba.kcc import debug
+
+
 
 class KCC(object):
     """The Knowledge Consistency Checker class.
diff --git a/python/samba/kcc/debug.py b/python/samba/kcc/debug.py
new file mode 100644 (file)
index 0000000..15b12ce
--- /dev/null
@@ -0,0 +1,67 @@
+# Debug utilities for samba_kcc
+#
+# Copyright (C) Andrew Bartlett 2015
+#
+# Although Andrew Bartlett owns the copyright, the actual work was
+# performed by Douglas Bagnall and Garming Sam.
+#
+# 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, see <http://www.gnu.org/licenses/>.
+
+import sys
+import logging
+from functools import partial
+import traceback
+
+logger = logging.getLogger("samba_kcc")
+logger.addHandler(logging.StreamHandler(sys.stdout))
+DEBUG = logger.debug
+
+
+#colours for prettier logs
+C_NORMAL = "\033[00m"
+DARK_RED = "\033[00;31m"
+RED = "\033[01;31m"
+DARK_GREEN = "\033[00;32m"
+GREEN = "\033[01;32m"
+YELLOW = "\033[01;33m"
+DARK_YELLOW = "\033[00;33m"
+DARK_BLUE = "\033[00;34m"
+BLUE = "\033[01;34m"
+PURPLE = "\033[00;35m"
+MAGENTA = "\033[01;35m"
+DARK_CYAN = "\033[00;36m"
+CYAN = "\033[01;36m"
+GREY = "\033[00;37m"
+WHITE = "\033[01;37m"
+REV_RED = "\033[01;41m"
+
+
+def _color_debug(*args, **kwargs):
+    DEBUG('%s%s%s' % (kwargs['color'], args[0], C_NORMAL), *args[1:])
+
+_globals = globals()
+for _color in ('DARK_RED', 'RED', 'DARK_GREEN', 'GREEN', 'YELLOW',
+               'DARK_YELLOW', 'DARK_BLUE', 'BLUE', 'PURPLE', 'MAGENTA',
+               'DARK_CYAN', 'CYAN', 'GREY', 'WHITE', 'REV_RED'):
+    _globals['DEBUG_' + _color] = partial(_color_debug, color=_globals[_color])
+
+
+def DEBUG_FN(msg=''):
+    filename, lineno, function, text = traceback.extract_stack(None, 2)[0]
+    DEBUG("%s%s:%s%s %s%s()%s '%s'" % (CYAN, filename, BLUE, lineno,
+                                       CYAN, function, C_NORMAL, msg))
+
+
+def null_debug(*args, **kwargs):
+    pass
similarity index 96%
rename from python/samba/graph_utils.py
rename to python/samba/kcc/graph_utils.py
index a01e068a17a98307ebe58531f59c65e296058c22..5fea5f0152e7188fe4754ddd46e73cc1c166e74b 100644 (file)
 
 import itertools
 
-#colours for prettier logs
-C_NORMAL = "\033[00m"
-DARK_RED = "\033[00;31m"
-RED = "\033[01;31m"
-DARK_GREEN = "\033[00;32m"
-GREEN = "\033[01;32m"
-YELLOW = "\033[01;33m"
-DARK_YELLOW = "\033[00;33m"
-DARK_BLUE = "\033[00;34m"
-BLUE = "\033[01;34m"
-PURPLE = "\033[00;35m"
-MAGENTA = "\033[01;35m"
-DARK_CYAN = "\033[00;36m"
-CYAN = "\033[01;36m"
-GREY = "\033[00;37m"
-WHITE = "\033[01;37m"
-REV_RED = "\033[01;41m"
+from samba.kcc.debug import null_debug, PURPLE, MAGENTA, DARK_YELLOW, RED
+from samba.kcc.debug import DARK_GREEN, C_NORMAL, GREY
+
 
 
 def write_dot_file(basename, edge_list, vertices=None, label=None,
@@ -312,12 +298,8 @@ def verify_graph_directed_double_ring_or_small(edges, vertices, edge_vertices):
 
 
 def verify_graph(title, edges, vertices=None, directed=False, properties=(),
-                 fatal=True, debug=None):
+                 fatal=True, debug=null_debug):
     errors = []
-    if debug is None:
-        def debug(*args):
-            pass
-
     debug("%sStarting verify_graph for %s%s%s" % (PURPLE, MAGENTA, title,
                                                   C_NORMAL))
 
index 1c1e6d94ebcaa38fbc9ea0c9235864699d5ed918..a7a1953c89346100ecd65f5d7f401ccb9bd460fd 100755 (executable)
@@ -56,7 +56,7 @@ from samba.auth import system_session
 from samba.samdb import SamDB
 from samba.dcerpc import drsuapi
 from samba.kcc_utils import *
-from samba.graph_utils import *
+from samba.kcc.debug import *
 from samba import ldif_utils
 
 
@@ -3115,6 +3115,8 @@ def find_component(vertex):
     return root
 
 
+from samba.kcc.graph_utils import verify_and_dot, list_verify_tests
+from samba.kcc.graph_utils import GraphError
 def add_out_edge(graph, output_edges, e):
     v1 = e.v1
     v2 = e.v2
@@ -3131,6 +3133,7 @@ def add_out_edge(graph, output_edges, e):
 
     v1.edges.append(ee)
     v2.edges.append(ee)
+from samba.kcc.debug import logger, DEBUG, DEBUG_FN
 
 
 def test_all_reps_from(lp, creds, rng_seed=None):