<s> import os <EOL> import sys <EOL> import argparse <EOL> from PIL import Image as PImage <EOL> from glue . formats import formats <EOL> from glue . helpers import redirect_stdout <EOL> from glue import exceptions <EOL> from glue import managers <EOL> from glue import __version__ <EOL> def main ( argv = None ) : <EOL> argv = ( argv or sys . argv ) [ <NUM_LIT:1> : ] <EOL> parser = argparse . ArgumentParser ( usage = ( "<STR_LIT>" ) ) <EOL> parser . add_argument ( "<STR_LIT>" , "<STR_LIT>" , <EOL> dest = "<STR_LIT:source>" , <EOL> type = unicode , <EOL> default = os . environ . get ( '<STR_LIT>' , None ) , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_argument ( "<STR_LIT>" , "<STR_LIT>" , <EOL> dest = "<STR_LIT>" , <EOL> type = unicode , <EOL> default = os . environ . get ( '<STR_LIT>' , None ) , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_argument ( "<STR_LIT>" , "<STR_LIT>" , <EOL> dest = "<STR_LIT>" , <EOL> action = '<STR_LIT:store_true>' , <EOL> default = os . environ . get ( '<STR_LIT>' , False ) , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_argument ( "<STR_LIT>" , "<STR_LIT>" , <EOL> dest = "<STR_LIT>" , <EOL> action = '<STR_LIT:store_true>' , <EOL> default = os . environ . get ( '<STR_LIT>' , False ) , <EOL> help = ( "<STR_LIT>" <EOL> "<STR_LIT>" ) ) <EOL> parser . add_argument ( "<STR_LIT>" , <EOL> dest = "<STR_LIT>" , <EOL> action = '<STR_LIT:store_true>' , <EOL> default = os . environ . get ( '<STR_LIT>' , False ) , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_argument ( "<STR_LIT>" , "<STR_LIT>" , <EOL> dest = "<STR_LIT>" , <EOL> action = '<STR_LIT:store_true>' , <EOL> default = os . environ . get ( '<STR_LIT>' , False ) , <EOL> help = ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) ) <EOL> parser . add_argument ( "<STR_LIT>" , "<STR_LIT>" , <EOL> dest = "<STR_LIT>" , <EOL> action = '<STR_LIT:store_true>' , <EOL> default = os . environ . get ( '<STR_LIT>' , False ) , <EOL> help = ( "<STR_LIT>" <EOL> "<STR_LIT>" ) ) <EOL> parser . add_argument ( "<STR_LIT>" , <EOL> dest = "<STR_LIT>" , <EOL> action = "<STR_LIT:store_true>" , <EOL> default = os . environ . get ( '<STR_LIT>' , False ) , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_argument ( "<STR_LIT>" , "<STR_LIT>" , <EOL> action = "<STR_LIT:version>" , <EOL> version = '<STR_LIT>' + __version__ , <EOL> help = "<STR_LIT>" ) <EOL> group = parser . add_argument_group ( "<STR_LIT>" ) <EOL> group . add_argument ( "<STR_LIT>" , "<STR_LIT>" , <EOL> dest = "<STR_LIT>" , <EOL> metavar = '<STR_LIT>' , <EOL> type = unicode , <EOL> default = os . environ . get ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> choices = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ] , <EOL> help = ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) ) <EOL> group . add_argument ( "<STR_LIT>" , <EOL> dest = "<STR_LIT>" , <EOL> metavar = '<STR_LIT>' , <EOL> type = unicode , <EOL> default = os . environ . get ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> choices = [ '<STR_LIT>' , '<STR_LIT:width>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:filename>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , <EOL> help = ( "<STR_LIT>" <EOL> "<STR_LIT>" ) ) <EOL> for format in formats . itervalues ( ) : <EOL> format . populate_argument_parser ( parser ) <EOL> group = parser . add_argument_group ( "<STR_LIT>" ) <EOL> deprecated_arguments = { } <EOL> def add_deprecated_argument ( * args , ** kwargs ) : <EOL> group . add_argument ( * args , ** kwargs ) <EOL> deprecated_arguments [ kwargs [ '<STR_LIT>' ] ] = args [ <NUM_LIT:0> ] <EOL> add_deprecated_argument ( "<STR_LIT>" , dest = "<STR_LIT>" ) <EOL> add_deprecated_argument ( "<STR_LIT>" , dest = "<STR_LIT>" ) <EOL> add_deprecated_argument ( "<STR_LIT>" , dest = "<STR_LIT>" ) <EOL> add_deprecated_argument ( "<STR_LIT>" , action = '<STR_LIT:store_true>' , <EOL> dest = "<STR_LIT>" ) <EOL> add_deprecated_argument ( "<STR_LIT>" , dest = "<STR_LIT>" , action = '<STR_LIT:store_true>' ) <EOL> add_deprecated_argument ( "<STR_LIT>" , dest = "<STR_LIT>" ) <EOL> add_deprecated_argument ( "<STR_LIT>" , action = '<STR_LIT:store_true>' , dest = "<STR_LIT>" ) <EOL> add_deprecated_argument ( "<STR_LIT>" , dest = "<STR_LIT>" , <EOL> action = '<STR_LIT:store_true>' ) <EOL> add_deprecated_argument ( "<STR_LIT>" , dest = "<STR_LIT>" ) <EOL> options , args = parser . parse_known_args ( argv ) <EOL> options . enabled_formats = [ f for f in formats if getattr ( options , '<STR_LIT>' . format ( f ) , False ) ] <EOL> if set ( options . enabled_formats ) in ( set ( [ '<STR_LIT>' ] ) , set ( [ '<STR_LIT>' , '<STR_LIT:html>' ] ) ) and options . generate_css : <EOL> options . enabled_formats . append ( '<STR_LIT>' ) <EOL> setattr ( options , "<STR_LIT>" , True ) <EOL> if not options . generate_image : <EOL> options . enabled_formats . remove ( '<STR_LIT>' ) <EOL> for argument in deprecated_arguments . iterkeys ( ) : <EOL> if getattr ( options , argument , None ) : <EOL> parser . error ( ( "<STR_LIT>" <EOL> "<STR_LIT>" ) . format ( deprecated_arguments [ argument ] ) ) <EOL> extra = <NUM_LIT:0> <EOL> if not options . source and args : <EOL> options . source = args [ <NUM_LIT:0> ] <EOL> extra += <NUM_LIT:1> <EOL> if not options . output and args [ extra : ] : <EOL> options . output = args [ extra ] <EOL> if options . source is None : <EOL> parser . error ( ( "<STR_LIT>" <EOL> "<STR_LIT>" ) ) <EOL> if not os . path . isdir ( options . source ) : <EOL> parser . error ( "<STR_LIT>" . format ( options . source ) ) <EOL> options . source = os . path . abspath ( options . source ) <EOL> if options . output : <EOL> options . output = os . path . abspath ( options . output ) <EOL> if not options . source : <EOL> parser . error ( ( "<STR_LIT>" <EOL> "<STR_LIT>" ) ) <EOL> if options . output : <EOL> for format in options . enabled_formats : <EOL> format_option = '<STR_LIT>' . format ( format ) <EOL> path = getattr ( options , format_option ) <EOL> if isinstance ( path , bool ) and path : <EOL> setattr ( options , format_option , options . output ) <EOL> else : <EOL> if options . generate_image and not options . img_dir : <EOL> parser . error ( ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) ) <EOL> for format in options . enabled_formats : <EOL> format_option = '<STR_LIT>' . format ( format ) <EOL> path = getattr ( options , format_option ) <EOL> if isinstance ( path , bool ) or not path : <EOL> parser . error ( ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" . format ( format ) ) ) <EOL> else : <EOL> setattr ( options , format_option , os . path . abspath ( path ) ) <EOL> if not options . generate_image and isinstance ( options . img_dir , bool ) : <EOL> options . img_dir = options . output <EOL> for format in options . enabled_formats : <EOL> formats [ format ] . apply_parser_contraints ( parser , options ) <EOL> if options . project : <EOL> manager_cls = managers . ProjectManager <EOL> else : <EOL> manager_cls = managers . SimpleManager <EOL> if options . watch : <EOL> manager = managers . WatchManager ( manager_cls , vars ( options ) ) <EOL> else : <EOL> manager = manager_cls ( ** vars ( options ) ) <EOL> try : <EOL> if options . quiet : <EOL> with redirect_stdout ( ) : <EOL> manager . process ( ) <EOL> else : <EOL> manager . process ( ) <EOL> except exceptions . ValidationError , e : <EOL> sys . stderr . write ( e . args [ <NUM_LIT:0> ] ) <EOL> return e . error_code <EOL> except exceptions . SourceImagesNotFoundError , e : <EOL> sys . stderr . write ( "<STR_LIT>" % e . args [ <NUM_LIT:0> ] ) <EOL> return e . error_code <EOL> except exceptions . NoSpritesFoldersFoundError , e : <EOL> sys . stderr . write ( "<STR_LIT>" % e . args [ <NUM_LIT:0> ] ) <EOL> return e . error_code <EOL> except exceptions . PILUnavailableError , e : <EOL> sys . stderr . write ( ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) . format ( e . args [ <NUM_LIT:0> ] ) ) <EOL> return e . error_code <EOL> except Exception : <EOL> import platform <EOL> import traceback <EOL> sys . stderr . write ( "<STR_LIT:\n>" ) <EOL> sys . stderr . write ( "<STR_LIT:=>" * <NUM_LIT> ) <EOL> sys . stderr . write ( "<STR_LIT>" ) <EOL> sys . stderr . write ( "<STR_LIT>" ) <EOL> sys . stderr . write ( "<STR_LIT:->" * <NUM_LIT> ) <EOL> sys . stderr . write ( "<STR_LIT:\n>" ) <EOL> sys . stderr . write ( "<STR_LIT>" . format ( __version__ ) ) <EOL> sys . stderr . write ( "<STR_LIT>" . format ( sys . version ) ) <EOL> sys . stderr . write ( "<STR_LIT>" . format ( PImage . VERSION ) ) <EOL> sys . stderr . write ( "<STR_LIT>" . format ( platform . platform ( ) ) ) <EOL> sys . stderr . write ( "<STR_LIT>" . format ( vars ( options ) ) ) <EOL> sys . stderr . write ( "<STR_LIT>" . format ( sys . argv ) ) <EOL> sys . stderr . write ( traceback . format_exc ( ) ) <EOL> sys . stderr . write ( "<STR_LIT:=>" * <NUM_LIT> ) <EOL> sys . stderr . write ( "<STR_LIT:\n>" ) <EOL> return <NUM_LIT:1> <EOL> return <NUM_LIT:0> <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> sys . exit ( main ( ) ) </s>
