예제 #1
0
파일: uploader.py 프로젝트: zinbers/XX-Net
def upload(appid, email, password):
    global defined_input
    global defined_password
    global code_path
    defined_input = email
    defined_password = password

    my_stdout.write(
        "============  Begin upload  ============\r\nappid:%s \r\n\r\n" %
        (appid))

    dirname = os.path.join(code_path, "gae")
    assert isinstance(dirname, basestring) and isinstance(appid, basestring)
    app_yaml_file = os.path.join(dirname, 'app.yaml')
    template_filename = os.path.join(dirname, 'app.template.yaml')
    assert os.path.isfile(
        template_filename), u'%s not exists!' % template_filename

    with open(template_filename, 'rb') as fp:
        yaml = fp.read()
    with open(app_yaml_file, 'wb') as fp:
        fp.write(re.sub(r'application:\s*\S+', 'application: ' + appid, yaml))

    try:
        for i in range(100):
            try:
                result = appcfg.AppCfgApp(['appcfg', 'rollback', dirname],
                                          password_input_fn=getpass_getpass,
                                          raw_input_fn=my_input,
                                          error_fh=my_stdout).Run()
                if result != 0:
                    continue
                result = appcfg.AppCfgApp(['appcfg', 'update', dirname],
                                          password_input_fn=getpass_getpass,
                                          raw_input_fn=my_input,
                                          error_fh=my_stdout).Run()
                if result != 0:
                    continue
                return True
            except appengine_rpc.ClientLoginError as e:
                my_stdout.write("upload  fail: %s\n\n" % e)
                raise e
            except Exception as e:
                my_stdout.write("upload  fail: %s\n\n" % e)
                if i < 99:
                    my_stdout.write("Retry %d time...\n\n" % (i + 1))
                    time.sleep(i)
                else:
                    my_stdout.write("Retry max time, failed.\n\n")

        return False

    finally:
        try:
            os.remove(app_yaml_file)
        except OSError:
            pass
예제 #2
0
def upload(appid, email, password):
    global defined_input
    global defined_password
    global code_path
    defined_input = email
    defined_password = password

    my_stdout.write(
        "============  Begin upload  ============\r\nappid:%s \r\n\r\n" %
        (appid))

    try:
        os.remove(appengine_rpc.HttpRpcServer.DEFAULT_COOKIE_FILE_PATH)
    except OSError:
        pass

    dirname = os.path.join(code_path, "gae")
    assert isinstance(dirname, basestring) and isinstance(appid, basestring)
    filename = os.path.join(dirname, 'app.yaml')
    template_filename = os.path.join(dirname, 'app.template.yaml')
    assert os.path.isfile(
        template_filename), u'%s not exists!' % template_filename

    with open(template_filename, 'rb') as fp:
        yaml = fp.read()
    with open(filename, 'wb') as fp:
        fp.write(re.sub(r'application:\s*\S+', 'application: ' + appid, yaml))

    for i in range(10):
        try:
            result = appcfg.AppCfgApp(['appcfg', 'rollback', dirname],
                                      password_input_fn=getpass_getpass,
                                      raw_input_fn=my_input,
                                      error_fh=my_stdout).Run()
            if result == 1:
                continue
            result = appcfg.AppCfgApp(['appcfg', 'update', dirname],
                                      password_input_fn=getpass_getpass,
                                      raw_input_fn=my_input,
                                      error_fh=my_stdout).Run()
            if result == 1:
                continue
            break
        except Exception as e:
            my_stdout.write("upload  fail: %s\n\n" % e)
            if i < 9:
                my_stdout.write("Retry again.\n\n")
                time.sleep(1)

    try:
        os.remove(filename)
        os.remove(appengine_rpc.HttpRpcServer.DEFAULT_COOKIE_FILE_PATH)
    except OSError:
        pass
예제 #3
0
def upload(appid):
    global code_path

    logging.info("============  Begin upload  ============")
    logging.info("appid:%s", appid)

    dirname = os.path.join(code_path, "gae")
    assert isinstance(dirname, basestring) and isinstance(appid, basestring)
    app_yaml_file = os.path.join(dirname, 'app.yaml')
    template_filename = os.path.join(dirname, 'app.template.yaml')
    assert os.path.isfile(
        template_filename), u'%s not exists!' % template_filename

    with open(template_filename, 'rb') as fp:
        yaml = fp.read()
    with open(app_yaml_file, 'wb') as fp:
        fp.write(re.sub(r'application:\s*\S+', 'application: ' + appid, yaml))

    try:
        for i in range(3):
            try:
                #"--noauth_local_webserver"
                result = appcfg.AppCfgApp([
                    'appcfg', 'rollback', '--oauth2_credential_file',
                    cookie_file, dirname
                ]).Run()
                if result != 0:
                    continue
                result = appcfg.AppCfgApp([
                    'appcfg', 'update', '--oauth2_credential_file',
                    cookie_file, dirname
                ]).Run()
                if result != 0:
                    continue
                return True
            except appengine_rpc.ClientLoginError as e:
                logging.info("upload  fail: %s" % e)
                raise e
            except Exception as e:
                logging.exception("upload fail:%r", e)
                if i < 99:
                    logging.info("Retry %d time..." % (i + 1))
                    time.sleep(i)
                else:
                    logging.info("Retry max time, failed.")

        return False

    finally:
        try:
            os.remove(app_yaml_file)
        except OSError:
            pass
예제 #4
0
  def run(self):
    from google.appengine.tools import appcfg
    from kay.management.preparse import do_preparse_apps
    import sys
    old_stdout = sys.stdout
    old_stderr = sys.stderr
    redir = RedirectText(self.win)
    sys.stdout = redir
    sys.stderr = redir

    import time
    do_preparse_apps()
    args = ['manage.py', 'update', os.getcwdu()]

    try:
      app = appcfg.AppCfgApp(args, raw_input_fn=self.ask_username,
                             password_input_fn=self.ask_pass, error_fh=redir)
      result = app.Run()
      if result:
        print_status('Failed Deploying application.')
      else:
        from kay.conf import settings
        if settings.PROFILE and 'update' in sys.argv:
          print_status('--------------------------\n' \
                         'WARNING: PROFILER ENABLED!\n' \
                         '--------------------------')
    except KeyboardInterrupt:
      print_status('Interrupted.')
    sys.stdout = old_stdout
    sys.stderr = old_stderr
    evt = ThreadEndEvent()
    wx.PostEvent(self.win, evt)
예제 #5
0
def run_appcfg(app_path):
    """Runs appcfg.py program.

    `app` is the path to the app.
    """
    from google.appengine.tools import appcfg

    argv = ["appcfg.py", "update", app_path]
    try:
        appcfg.AppCfgApp(argv).Run()
    except KeyboardInterrupt:
        appcfg.StatusUpdate("Interrupted")
예제 #6
0
def do_appcfg_passthru_argv():
  """
  Execute appcfg.py with specified parameters. For more details,
  please invoke 'python manage.py appcfg --help'.
  """
  from google.appengine.tools import appcfg
  progname = sys.argv[0]
  if len(sys.argv) < 3:
    sys.stderr.write('action required.\n')
    sys.exit(1)
  if 'update' in sys.argv:
    do_preparse_apps()
  
  models = get_all_models_as_dict()
  args = []
  for arg in sys.argv[2:]:
    args.append(arg)
    if arg == "request_logs":
      args.append(os.getcwdu())

  if "--help" in args or "help" in args or "request_logs" in args:
    args = [progname] + args
  else:
    args = [progname] + args + [os.getcwdu()]
  logging.basicConfig(format=('%(asctime)s %(levelname)s %(filename)s:'
                              '%(lineno)s %(message)s '))
  try:
    app = appcfg.AppCfgApp(args, parser_class=HookedOptionParser)
    result = app.Run()
    if result:
      sys.exit(result)
  except KeyboardInterrupt:
    print_status('Interrupted.')
    sys.exit(1)
  from kay.conf import settings
  if settings.PROFILE and 'update' in sys.argv:
    print_status(
      '--------------------------\n'
      'WARNING: PROFILER ENABLED!\n'
      '--------------------------'
    )
예제 #7
0
def get_modules(email, password, app_id):
    """Return a list of all modules that our GAE instance knows of."""
    fix_sys_path()
    from google.appengine.tools import appcfg
    output = cStringIO.StringIO()
    argv = [
        'appcfg.py', '--skip_sdk_update_check', 'list_versions', '-A', app_id
    ]
    app = appcfg.AppCfgApp(argv,
                           password_input_fn=lambda prompt: password,
                           raw_input_fn=lambda prompt: email,
                           out_fh=output,
                           error_fh=output)
    rc = app.Run()
    if rc != 0:
        raise RuntimeError("appcfg.py returned error code %s:\n%s" %
                           (rc, output.getvalue()))

    # The output is some yaml-like format.  We do a cheesy parse of it:
    # the module names are all of the form 'module_name: [...'
    modules = re.findall(r'(\S+): \[', output.getvalue())

    # Special case: we don't want to reutrn the test 'vm' module
    return [m for m in modules if m != 'vm']