GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — SublimeGraphvizPreview/helpers.py at master · munro/SublimeGraphvizPreview Expand file tree/ Copy pathhelpers.pyMore file actions 57 lines (45 loc) · 1.66 KB / Copy pathhelpers.pyFile metadata and controls57 lines (45 loc) · 1.66 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 from subprocess import call import os import platform import re import tempfile ENVIRON = os.environ if platform.system() != 'Windows': ENVIRON['PATH'] += ':/usr/local/bin' DIGRAPH_START = re.compile('.*(digraph([ \t\n\r]+[a-zA-Z\200-\377_][a-zA-Z\200-\3770-9_]*[ \t\n\r]*{|[ \t\n\r]*{).*)', re.DOTALL | re.IGNORECASE) def surroundingGraphviz(data, cursor): ''' Find graphviz code in source surrounding the cursor. ''' data_before = data[0:cursor] data_after = data[cursor:] # find code before selector code_before_match = DIGRAPH_START.match(data_before) if not code_before_match: return None code_before = code_before_match.group(1) unopened_braces = len(code_before.split('{')) - len(code_before.split('}')) # cursor must be in the middle of the graphviz code if unopened_braces <= 0: return None # find code after selector code_after_match = re.compile('(' + ('.*\\}' * unopened_braces) + ').*', re.DOTALL).match(data_after) if not code_after_match: return None code_after = code_after_match.group(1) # done! code = code_before + code_after return code def graphvizPDF(code): ''' Convert graphviz code to a PDF. ''' # temporary graphviz file grapviz = tempfile.NamedTemporaryFile(prefix='sublime_text_graphviz_', dir=None, suffix='.viz', delete=False, mode='wb') grapviz.write(code.encode('utf-8')) grapviz.close() # compile pdf pdf_filename = tempfile.mktemp(prefix='sublime_text_graphviz_', dir=None, suffix='.pdf') call(['dot', '-Tpdf', '-o' + pdf_filename, grapviz.name], env=ENVIRON) os.unlink(grapviz.name) return pdf_filename |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |