<s> import sublime <EOL> import os <EOL> from . pathutils import mkdir_p <EOL> import sass <EOL> import stat <EOL> from subprocess import PIPE , Popen <EOL> if not os . access ( sass . path , os . X_OK ) : <EOL> mode = os . stat ( sass . path ) . st_mode <EOL> os . chmod ( sass . path , mode | stat . S_IEXEC ) <EOL> if os . name == '<STR_LIT>' : <EOL> _platform_opts = { '<STR_LIT>' : <NUM_LIT> } <EOL> else : <EOL> _platform_opts = { } <EOL> def to_flags ( options ) : <EOL> '''<STR_LIT>''' <EOL> flags = [ ] <EOL> for key , value in options . items ( ) : <EOL> if value is True : <EOL> flags . append ( '<STR_LIT>' . format ( key ) ) <EOL> elif type ( value ) is list : <EOL> for v in value : <EOL> flags . append ( '<STR_LIT>' . format ( key , v ) ) <EOL> elif value is not False : <EOL> flags . append ( '<STR_LIT>' . format ( key , value ) ) <EOL> return flags <EOL> def _compile ( files , config , outfile_for ) : <EOL> flags = to_flags ( config [ '<STR_LIT>' ] ) <EOL> compiled = [ ] <EOL> for f in files : <EOL> in_file = os . path . join ( config [ '<STR_LIT:root>' ] , f ) <EOL> out_file = outfile_for ( f ) <EOL> mkdir_p ( os . path . dirname ( out_file ) ) <EOL> command = [ sass . path ] + flags + [ in_file , out_file ] <EOL> p = Popen ( command , stdout = PIPE , stderr = PIPE , ** _platform_opts ) <EOL> out , err = p . communicate ( ) <EOL> if err : <EOL> print ( u"<STR_LIT>" . format ( err ) ) <EOL> print ( u"<STR_LIT>" . format ( "<STR_LIT:U+0020>" . join ( command ) ) ) <EOL> sublime . error_message ( u"<STR_LIT>" . format ( f ) ) <EOL> return <EOL> compiled . append ( f ) <EOL> return compiled <EOL> def nested ( files , config , rel = "<STR_LIT>" ) : <EOL> outroot = os . path . join ( config [ '<STR_LIT:root>' ] , config [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> def outfile_for ( infile ) : <EOL> if rel and infile . startswith ( os . path . normpath ( rel ) ) : <EOL> infile = infile [ len ( rel ) + <NUM_LIT:1> : ] <EOL> outname = os . path . splitext ( infile ) [ <NUM_LIT:0> ] + '<STR_LIT>' <EOL> return os . path . join ( outroot , outname ) <EOL> return _compile ( files , config , outfile_for ) <EOL> def flat ( files , config ) : <EOL> outroot = os . path . join ( config [ '<STR_LIT:root>' ] , config [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> def outfile_for ( infile ) : <EOL> outname = os . path . basename ( os . path . splitext ( infile ) [ <NUM_LIT:0> ] + '<STR_LIT>' ) <EOL> return os . path . join ( outroot , outname ) <EOL> return _compile ( files , config , outfile_for ) </s>
