Merge lp:~gz/bzrtools/dot_encoding_211104 into lp:bzrtools

Proposed by Martin Packman
Status: Needs review
Proposed branch: lp:~gz/bzrtools/dot_encoding_211104
Merge into: lp:bzrtools
Diff against target: 60 lines (+14/-10)
1 file modified
dotgraph.py (+14/-10)
To merge this branch: bzr merge lp:~gz/bzrtools/dot_encoding_211104
Reviewer Review Type Date Requested Status
Richard Wilbur (community) Approve
Aaron Bentley Pending
Review via email: mp+84405@code.launchpad.net

Description of the change

Get the dot encoding correct at the graph definition level rather than leaving it till writing to the subprocess pipe. This is needed because invoke_dot_html feeds an output file of dot with layout annotations back in as input to save calculating the layout twice, and would otherwise have to decode it in order to encode it again.

While there, made the writer function accept a filename string as input as an alternative to an iterable of strings, which saves some file lifetime problems in invoke_dot_html as well.

The problem is nice and easy to see using just the bzrtools branch thanks to BenoƮt Pierre appearing.

To post a comment you must log in.
Revision history for this message
Richard Wilbur (richard-wilbur) wrote :

Looks like this is very likely just as relevant as when Martin first proposed merging this branch according to a recent comment on the associated bug.[0]

Good work, Martin!
+1

[0] https://bugs.launchpad.net/bzrtools/+bug/211104/comments/3

review: Approve

Unmerged revisions

783. By Martin Packman

Allow passing a filename to invoke_dot which helps get file lifetimes correct

782. By Martin Packman

Ensure dot is encoded correctly at definition time rather than just before writing to subprocess

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'dotgraph.py'
--- dotgraph.py 2008-04-11 00:03:51 +0000
+++ dotgraph.py 2011-12-04 18:30:39 +0000
@@ -69,11 +69,11 @@
69 attributes.append('style="%s"' % ",".join(style))69 attributes.append('style="%s"' % ",".join(style))
70 label = self.label70 label = self.label
71 if label is not None:71 if label is not None:
72 attributes.append('label="%s"' % label)72 attributes.append('label="%s"' % label.encode('utf-8'))
73 attributes.append('shape="box"')73 attributes.append('shape="box"')
74 tooltip = None74 tooltip = None
75 if self.message is not None:75 if self.message is not None:
76 tooltip = self.message76 tooltip = self.message.encode('utf-8')
77 attributes.append(self.get_attribute('tooltip', tooltip))77 attributes.append(self.get_attribute('tooltip', tooltip))
78 if self.href is not None:78 if self.href is not None:
79 attributes.append('href="%s"' % self.href)79 attributes.append('href="%s"' % self.href)
@@ -210,16 +210,22 @@
210 '-Efontsize=%d' % fontsize]210 '-Efontsize=%d' % fontsize]
211 if out_file is not None:211 if out_file is not None:
212 cmdline.extend(('-o', out_file))212 cmdline.extend(('-o', out_file))
213 if isinstance(input, basestring):
214 cmdline.append(input)
215 stdin = None
216 else:
217 stdin = PIPE
213 try:218 try:
214 dot_proc = Popen(cmdline, stdin=PIPE)219 dot_proc = Popen(cmdline, stdin=stdin)
215 except OSError, e:220 except OSError, e:
216 if e.errno == errno.ENOENT:221 if e.errno == errno.ENOENT:
217 raise NoDot()222 raise NoDot()
218 else:223 else:
219 raise224 raise
220 for line in input:225 if stdin == PIPE:
221 dot_proc.stdin.write(line.encode('utf-8'))226 for line in input:
222 dot_proc.stdin.close()227 dot_proc.stdin.write(line)
228 dot_proc.stdin.close()
223 return dot_proc.wait()229 return dot_proc.wait()
224230
225def invoke_dot_html(input, out_file):231def invoke_dot_html(input, out_file):
@@ -232,13 +238,11 @@
232 temp_dot = os.path.join(tempdir, 'temp.dot')238 temp_dot = os.path.join(tempdir, 'temp.dot')
233 status = invoke_dot(input, temp_dot, file_type='dot')239 status = invoke_dot(input, temp_dot, file_type='dot')
234240
235 dot = open(temp_dot)
236 temp_file = os.path.join(tempdir, 'temp.cmapx')241 temp_file = os.path.join(tempdir, 'temp.cmapx')
237 status = invoke_dot(dot, temp_file, 'cmapx')242 status = invoke_dot(temp_dot, temp_file, 'cmapx')
238243
239 png_file = '.'.join(out_file.split('.')[:-1] + ['png'])244 png_file = '.'.join(out_file.split('.')[:-1] + ['png'])
240 dot.seek(0)245 status = invoke_dot(temp_dot, png_file, 'png')
241 status = invoke_dot(dot, png_file, 'png')
242246
243 png_relative = png_file.split('/')[-1]247 png_relative = png_file.split('/')[-1]
244 html = open(out_file, 'wb')248 html = open(out_file, 'wb')

Subscribers

People subscribed via source and target branches