'Initializer.  Parses the cmdline and selects the Action to use.
Initializes all of the attributes described in the class docstring.
Prints help or error messages if there is an error parsing the cmdline.
Args:
argv: The list of arguments passed to this program.
parser_class: Options parser to use for this application.
rpc_server_class: RPC server class to use for this application.
out_fh: All normal output is printed to this file handle.
error_fh: Unexpected HTTPErrors are printed to this file handle.
update_check_class: sdk_update_checker.SDKUpdateChecker class (can be
replaced for testing).
throttle_class: A class to use instead of ThrottledHttpRpcServer
(only used in the bulkloader).
opener: Function used for opening files.
file_iterator: Callable that takes (basepath, skip_files, file_separator)
and returns a generator that yields all filenames in the file tree
rooted at that path, skipping files that match the skip_files compiled
regular expression.
time_func: A time.time() compatible function, which can be overridden for
testing.
wrap_server_error_message: If true, the error messages from
urllib2.HTTPError exceptions in Run() are wrapped with
\'--- begin server output ---\' and \'--- end server output ---\',
otherwise the error message is printed as is.
oauth_client_id: The client ID of the project providing Auth. Defaults to
the SDK default project client ID, the constant APPCFG_CLIENT_ID.
oauth_client_secret: The client secret of the project providing Auth.
Defaults to the SDK default project client secret, the constant
APPCFG_CLIENT_NOTSOSECRET.
oauth_scopes: The scope or set of scopes to be accessed by the OAuth2
token retrieved. Defaults to APPCFG_SCOPES. Can be a string or
iterable of strings, representing the scope(s) to request.'

def __init__(self, argv, parser_class=optparse.OptionParser, rpc_server_class=None, out_fh=sys.stdout, error_fh=sys.stderr, update_check_class=sdk_update_checker.SDKUpdateChecker, throttle_class=None, opener=open, file_iterator=FileIterator, time_func=time.time, wrap_server_error_message=True, oauth_client_id=APPCFG_CLIENT_ID, oauth_client_secret=APPCFG_CLIENT_NOTSOSECRET, oauth_scopes=APPCFG_SCOPES):

    self.parser_class = parser_class
    self.argv = argv
    self.rpc_server_class = rpc_server_class
    self.out_fh = out_fh
    self.error_fh = error_fh
    self.update_check_class = update_check_class
    self.throttle_class = throttle_class
    self.time_func = time_func
    self.wrap_server_error_message = wrap_server_error_message
    self.oauth_client_id = oauth_client_id
    self.oauth_client_secret = oauth_client_secret
    self.oauth_scopes = oauth_scopes
    self.read_url_contents = _ReadUrlContents
    self.parser = self._GetOptionParser()
    for action in self.actions.itervalues():
        action.options(self, self.parser)
    (self.options, self.args) = self.parser.parse_args(argv[1:])
    if (len(self.args) < 1):
        self._PrintHelpAndExit()
    if (not self.options.allow_any_runtime):
        if self.options.runtime:
            if (self.options.runtime not in appinfo.GetAllRuntimes()):
                _PrintErrorAndExit(self.error_fh, ('"%s"    is    not    a    supported    runtime\n' % self.options.runtime))
        else:
            appinfo.AppInfoExternal.ATTRIBUTES[appinfo.RUNTIME] = '|'.join(appinfo.GetAllRuntimes())
    if self.options.redundant_oauth2:
        print >>sys.stderr, '\nNote:    the    --oauth2    flag    is    now    the    default    and    can    be    omitted.\n'
    action = self.args.pop(0)
    def RaiseParseError(actionname, action):
        (self.parser, self.options) = self._MakeSpecificParser(action)
        error_desc = action.error_desc
        if (not error_desc):
            error_desc = ("Expected    a    <directory>    argument    after    '%s'." % actionname.split('    ')[0])
        self.parser.error(error_desc)
    if (action == BACKENDS_ACTION):
        if (len(self.args) < 1):
            RaiseParseError(action, self.actions[BACKENDS_ACTION])
        backend_action_first = ((BACKENDS_ACTION + '    ') + self.args[0])
        if (backend_action_first in self.actions):
            self.args.pop(0)
            action = backend_action_first
        elif (len(self.args) > 1):
            backend_directory_first = ((BACKENDS_ACTION + '    ') + self.args[1])
            if (backend_directory_first in self.actions):
                self.args.pop(1)
                action = backend_directory_first
        if ((len(self.args) < 1) or (action == BACKENDS_ACTION)):
            RaiseParseError(action, self.actions[action])
    if (action not in self.actions):
        self.parser.error(("Unknown    action:    '%s'\n%s" % (action, self.parser.get_description())))
    self.action = self.actions[action]
    if ((not self.action.uses_basepath) or self.options.help):
        self.basepath = None
    else:
        if (not self.args):
            RaiseParseError(action, self.action)
        self.basepath = self.args.pop(0)
    (self.parser, self.options) = self._MakeSpecificParser(self.action)
    if self.options.help:
        self._PrintHelpAndExit()
    if (self.options.verbose == 2):
        logging.getLogger().setLevel(logging.INFO)
    elif (self.options.verbose == 3):
        logging.getLogger().setLevel(logging.DEBUG)
    global verbosity
    verbosity = self.options.verbose
    if self.options.oauth2_client_id:
        self.oauth_client_id = self.options.oauth2_client_id
    if self.options.oauth2_client_secret:
        self.oauth_client_secret = self.options.oauth2_client_secret
    self.opener = opener
    self.file_iterator = file_iterator
