1
0
mirror of https://github.com/samba-team/samba.git synced 2025-12-17 04:23:50 +03:00

KCC: write dot files in a deterministic, user specified place

We were using randomised tempfile names in /tmp, initially to avoid
overwriting previous runs so as to track progress. Now we hardly ever
care about the old versions, and a user-specified name will be handy
for testing.

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>
This commit is contained in:
Douglas Bagnall
2015-04-30 10:39:54 +12:00
committed by Andrew Bartlett
parent 169fcd7add
commit eba852cc98
4 changed files with 55 additions and 49 deletions

View File

@@ -18,6 +18,7 @@
# 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 os
import itertools
from samba.kcc.debug import null_debug, PURPLE, MAGENTA, DARK_YELLOW, RED
@@ -26,14 +27,15 @@ from samba.kcc.debug import DARK_GREEN, C_NORMAL, GREY
def write_dot_file(basename, edge_list, vertices=None, label=None,
destdir=None, reformat_labels=True, directed=False,
dot_file_dir=None, reformat_labels=True, directed=False,
debug=None, edge_colors=None, edge_labels=None,
vertex_colors=None):
from tempfile import NamedTemporaryFile
if label:
basename += '_' + label.translate(None, ', ') # fix DN, guid labels
f = NamedTemporaryFile(suffix='.dot', prefix=basename + '_', delete=False,
dir=destdir)
# sanitise DN and guid labels
basename += '_' + label.translate(None, ', ')
f = open(os.path.join(dot_file_dir, "%s.dot" % basename), 'w')
if debug is not None:
debug(f.name)
graphname = ''.join(x for x in basename if x.isalnum())
@@ -341,19 +343,22 @@ def verify_graph(title, edges, vertices=None, directed=False, properties=(),
debug(C_NORMAL)
def verify_and_dot(basename, edges, vertices=None, label=None, destdir=None,
reformat_labels=True, directed=False, properties=(),
fatal=True, debug=None, verify=True, dot_files=False,
edge_colors=None, edge_labels=None, vertex_colors=None):
def verify_and_dot(basename, edges, vertices=None, label=None,
reformat_labels=True, directed=False,
properties=(), fatal=True, debug=None,
verify=True, dot_file_dir=None,
edge_colors=None, edge_labels=None,
vertex_colors=None):
title = '%s %s' % (basename, label or '')
if verify:
verify_graph(title, edges, vertices, properties=properties,
fatal=fatal, debug=debug)
if dot_files:
if dot_file_dir is not None:
write_dot_file(basename, edges, vertices=vertices, label=label,
destdir=destdir, reformat_labels=reformat_labels,
directed=directed, debug=debug, edge_colors=edge_colors,
dot_file_dir=dot_file_dir,
reformat_labels=reformat_labels, directed=directed,
debug=debug, edge_colors=edge_colors,
edge_labels=edge_labels, vertex_colors=vertex_colors)