Ejemplo n.º 1
0
def check_for_updates(application_configuration):
  """Checks for updates to the SDK.

  A message will be printed on stdout if the SDK is not up-to-date.

  Args:
    application_configuration: The
        application_configuration.ApplicationConfiguration for the application.
        Used to check if the api_versions used by the servers are supported by
        the SDK.

  Raises:
    SystemExit: if the api_version used by a server is not supported by the
        SDK.
  """
  update_server = appengine_rpc.HttpRpcServer(
      _UPDATE_SERVER,
      lambda: ('unused_email', 'unused_password'),
      _get_user_agent(),
      _get_source_name())  # TODO: is the source name arg necessary?
  # Don't try to talk to ClientLogin.
  update_server.authenticated = True

  # TODO: Update check needs to be refactored so the api_version for
  # all runtimes can be checked without generating duplicate nag messages.
  if application_configuration.servers:
    update_check = sdk_update_checker.SDKUpdateChecker(
        update_server, application_configuration.servers)
    update_check.CheckSupportedVersion()  # Can raise SystemExit.
    if update_check.AllowedToCheckForUpdates():
      update_check.CheckForUpdates()
Ejemplo n.º 2
0
def create_rpcserver(email, password):
    """Create an instance of an RPC server to access GAE dashboard pages."""

    # Executing "appcfg.py update ." results in the following
    # arguments to appengine_rpc.HttpRpcServer.__init__():
    #
    # *args    ('appengine.google.com',
    #           <function GetUserCredentials at 0x10ec58320>,
    #           'appcfg_py/1.7.2 Darwin/11.4.0 Python/2.7.1.final.0',
    #           'Google-appcfg-1.7.2')
    #
    # **kwargs {'host_override': None,
    #           'auth_tries': 3,
    #           'save_cookies': True,
    #           'account_type': 'HOSTED_OR_GOOGLE',
    #           'secure': True}
    rpcserver = appengine_rpc.HttpRpcServer(APPENGINE_HOST,
                                            lambda: (email, password),
                                            USER_AGENT,
                                            AUTH_SOURCE,
                                            host_override=None,
                                            auth_tries=1,
                                            save_cookies=False,
                                            account_type='HOSTED_OR_GOOGLE',
                                            secure=True,
                                            rpc_tries=3)
    return rpcserver
Ejemplo n.º 3
0
def MakeRpcServer(option_dict):
    """Create a new HttpRpcServer.

  Creates a new HttpRpcServer to check for updates to the SDK.

  Args:
    option_dict: The dict of command line options.

  Returns:
    A HttpRpcServer.
  """
    server = appengine_rpc.HttpRpcServer(
        option_dict[ARG_ADMIN_CONSOLE_SERVER],
        lambda: ('unused_email', 'unused_password'),
        appcfg.GetUserAgent(),
        appcfg.GetSourceName(),
        host_override=option_dict[ARG_ADMIN_CONSOLE_HOST])
    server.authenticated = True
    return server
Ejemplo n.º 4
0
def uploadXmlsViaCustomRemoteBlobstoreAPI():
    """
  http://stackoverflow.com/questions/101742/how-do-you-access-an-authenticated-google-app-engine-service-from-a-non-web-py
  http://stackoverflow.com/questions/10118585/how-to-make-an-authenticated-request-from-a-script-to-appengine?lq=1
  """
    from google.appengine.tools import appengine_rpc

    app_name = raw_input('app_name:')
    rpcServer = appengine_rpc.HttpRpcServer("%s.appspot.com" % app_name,
                                            auth_func,
                                            None,
                                            app_name,
                                            save_cookies=True,
                                            secure=True)

    romn_dir = getRomnDir()

    for dirpath, dirnames, filenames in os.walk(romn_dir):
        for filename in filenames:
            path = os.path.join(dirpath, filename)
            key = path[len(romn_dir):]
            print('uploading %s ...' % key)
            """Python HTTP POST json-format data (payload is encoded with base64).

      Reference:
          http://stackoverflow.com/questions/4348061/how-to-use-python-urllib2-to-send-json-data-for-login
          http://stackoverflow.com/questions/16329786/how-can-i-get-python-base64-encoding-to-play-nice-with-json
      """
            with open(path, 'rb') as f:
                jdata = json.dumps({
                    'key': key,
                    'payload': base64.b64encode(f.read())
                })

            responseData = rpcServer.Send('/customRemoteBlobstoreAPI', jdata)
            result_array = responseData.split('<br />')
            if result_array[0] == 'OK':
                print('key: %s, blob_key: %s' %
                      (result_array[1], result_array[2]))
            else:
                raise Exception('server return error: %s' % responseData)
Ejemplo n.º 5
0
def run(options):
    """Run the passed in url of the example using GAE's rpc runner.

    Uses appengine_rpc.HttpRpcServer to send a request to the url passed in
    via the options.

    :param options:
    """
    from google.appengine.tools import appengine_rpc
    from google.appengine.tools import appcfg

    source = 'furious'

    # use the same user agent that GAE uses in appcfg
    user_agent = appcfg.GetUserAgent()

    # Since we're only using the dev server for now we can hard code these
    # values. This will need to change and accept these values as variables
    # when this is wired up to hit appspots.
    server = appengine_rpc.HttpRpcServer('localhost:8080',
                                         lambda:
                                         ('*****@*****.**', 'password'),
                                         user_agent,
                                         source,
                                         secure=False)

    # if no url is passed in just use the top level.
    url = "/"
    if options.url:
        url += options.url[0]

    # use the dev server authentication for now.
    server._DevAppServerAuthenticate()

    # send a simple GET request to the url
    server.Send(url, content_type="text/html; charset=utf-8", payload=None)
Ejemplo n.º 6
0
def rpc_server_factory(*args, ** kwargs):
    from google.appengine.tools import appengine_rpc
    kwargs['save_cookies'] = True
    return appengine_rpc.HttpRpcServer(*args, ** kwargs)