<s> import sublime , sublime_plugin <EOL> from subprocess import call <EOL> import os <EOL> import platform <EOL> try : <EOL> from . helpers import surroundingGraphviz , graphvizPDF , ENVIRON <EOL> except ValueError : <EOL> from helpers import surroundingGraphviz , graphvizPDF , ENVIRON <EOL> class GraphvizPreviewCommand ( sublime_plugin . TextCommand ) : <EOL> def run ( self , edit ) : <EOL> sel = self . view . sel ( ) [ <NUM_LIT:0> ] <EOL> if not sel . empty ( ) : <EOL> code = self . view . substr ( sel ) . strip ( ) <EOL> else : <EOL> code = surroundingGraphviz ( <EOL> self . view . substr ( sublime . Region ( <NUM_LIT:0> , self . view . size ( ) ) ) , <EOL> sel . begin ( ) <EOL> ) <EOL> if not code : <EOL> sublime . error_message ( '<STR_LIT>' ) <EOL> return <EOL> pdf_filename = graphvizPDF ( code ) <EOL> try : <EOL> if platform . system ( ) == '<STR_LIT>' : <EOL> os . startfile ( pdf_filename ) <EOL> else : <EOL> call ( [ '<STR_LIT>' , pdf_filename ] , env = ENVIRON ) <EOL> except Exception as e : <EOL> sublime . error_message ( '<STR_LIT>' + str ( e ) ) <EOL> raise e </s>
