def parse(cls, args):
        """
        Parse command line arguments to construct a dictionary of command
        parameters that can be used to create a command

        Args:
            `args`: sequence of arguments

        Returns:
            Dictionary that can be used in create method

        Raises:
            ParseError: when the arguments are not correct
        """

        try:
            (options, args) = cls.optparser.parse_args(args)
            if options.inline is None and options.script_location is None:
                raise ParseError("One of script or it's location"
                                 " must be specified",
                                 cls.optparser.format_help())
        except OptionParsingError as e:
            raise ParseError(e.msg, cls.optparser.format_help())
        except OptionParsingExit as e:
            return None

        if options.script_location is not None:
            if options.inline is not None:
                raise ParseError(
                    "Both script and script_location cannot be specified",
                    cls.optparser.format_help())

            if ((options.script_location.find("s3://") != 0) and
                (options.script_location.find("s3n://") != 0)):

                # script location is local file

                try:
                    s = open(options.script_location).read()
                except IOError as e:
                    raise ParseError("Unable to open script location: %s" %
                                     str(e),
                                     cls.optparser.format_help())
                options.script_location = None
                options.inline = s

            if (args is not None) and (len(args) > 0):
                if options.inline is not None:
                    raise ParseError(
                        "Extra arguments can only be "
                        "supplied with a script_location in S3 right now",
                        cls.optparser.format_help())

                setattr(options, 'parameters',
                        " ".join([pipes.quote(a) for a in args]))

        else:
            if (args is not None) and (len(args) > 0):
                raise ParseError(
                    "Extra arguments can only be supplied with a script_location",
                    cls.optparser.format_help())

        v = vars(options)
        v["command_type"] = "ShellCommand"
        return v
def parse ( cls , args ) : try : ( options , args ) = cls . optparser . parse_args ( args ) if options . inline is None and options . script_location is None : raise ParseError ( "One of script or it's location" " must be specified" , cls . optparser . format_help ( ) ) except OptionParsingError as e : raise ParseError ( e . msg , cls . optparser . format_help ( ) ) except OptionParsingExit as e : return None if options . script_location is not None : if options . inline is not None : raise ParseError ( "Both script and script_location cannot be specified" , cls . optparser . format_help ( ) ) if ( ( options . script_location . find ( "s3://" ) != 0 ) and ( options . script_location . find ( "s3n://" ) != 0 ) ) : try : s = open ( options . script_location ) . read ( ) except IOError as e : raise ParseError ( "Unable to open script location: %s" % str ( e ) , cls . optparser . format_help ( ) ) options . script_location = None options . inline = s if ( args is not None ) and ( len ( args ) > 0 ) : if options . inline is not None : raise ParseError ( "Extra arguments can only be " "supplied with a script_location in S3 right now" , cls . optparser . format_help ( ) ) setattr ( options , 'parameters' , " " . join ( [ pipes . quote ( a ) for a in args ] ) ) else : if ( args is not None ) and ( len ( args ) > 0 ) : raise ParseError ( "Extra arguments can only be supplied with a script_location" , cls . optparser . format_help ( ) ) v = vars ( options ) v [ "command_type" ] = "ShellCommand" return v
Parse command line arguments to construct a dictionary of command
        parameters that can be used to create a command

        Args:
            `args`: sequence of arguments

        Returns:
            Dictionary that can be used in create method

        Raises:
            ParseError: when the arguments are not correct