Exemple #1
0
def clear_datastore(appid=('a', ''), host=('h', ''), path=('p', ''),
                    kinds=('k', ''), clear_memcache=('c', False), secure=True):
  """Clear all the data on GAE environment using remote_api.
  """
  if not appid:
    appid = get_appid()
  if not host:
    host = "%s.appspot.com" % appid
  if not path:
    path = DEFAULT_REMOTE_API_PATH
  if not kinds:
    models = None
  else:
    models_dict = get_all_models_as_dict()
    models = []
    for kind in kinds.split(','):
      models.append(db.class_for_kind(kind))
      
  remote_api_stub.ConfigureRemoteApi(None, path, auth_func,
                                     host, secure=secure, save_cookies=True)
  remote_api_stub.MaybeInvokeAuthentication()
  delete_all_entities(models)
  if clear_memcache:
    from google.appengine.api import memcache
    memcache.flush_all()
    sys.stderr.write("Flushed memcache.\n")
def add_request(properties, context, user, groupname=None):
  blip = context.GetBlipById(properties['blipId'])
  group = Group.get_by_key_name(Group.get_key_name(groupname))
  text = "You(%s) requested adding you to the group: %s.\n" % (user, groupname)
  if group:
    if user in group.members:
      text += "You are already a member of the group: %s." % groupname
    elif user in group.applications:
      text += ("You have already applied to join the group: %s. "
               "Please wait for a moment." % groupname)
    elif user in group.banned_addresses:
      text += "You are banned from the group: %s." % groupname
    else:
      from google.appengine.api import mail
      from google.appengine.ext import db
      body = "%s has requested joining the group: %s.\n" % (user, groupname)
      body += "You can moderate this request on following URL:\n"
      body += "http://%s.appspot.com/edit_group?key_name=%s" \
          % (get_appid(), group.key().name().replace(":", "%3A"))
      mail.send_mail(sender=settings.ADMINS[0][1],
                     to=group.owner.email,
                     subject="Join request from %s has come" % user,
                     body=body)
      def txn():
        g = Group.get(group.key())
        g.applications.append(user)
        g.put()
      db.run_in_transaction(txn)
      text += "Request to join this group has been sent!"
  else:
    text += "However, there is no such group! Sorry."
  blip.CreateChild().GetDocument().SetText(text)
Exemple #3
0
def create_user(user_name=('u', ''), password=('P', ''), is_admin=('A', False),
                appid=('a', ''), host=('h', ''), path=('p', ''), secure=True):
  """ Create new user using remote_api.
  """
  from kay.auth import (
    create_new_user, DuplicateKeyError,
  )
  if not user_name:
    print_status('user_name required')
    sys.exit(1)
  if not password:
    password = getpass.getpass('Please input a password for new user:'******'A new user: %s successfully created.' % user_name)
    sys.exit(0)
  except DuplicateKeyError, e:
    print_status(e)
    sys.exit(1)
Exemple #4
0
def clear_datastore(appid=('a', ''),
                    host=('h', ''),
                    path=('p', ''),
                    kinds=('k', ''),
                    clear_memcache=('c', False),
                    secure=True):
    """Clear all the data on GAE environment using remote_api.
  """
    if not appid:
        appid = get_appid()
    if not host:
        host = "%s.appspot.com" % appid
    if not path:
        path = '/remote_api'
    if not kinds:
        models = None
    else:
        models_dict = get_all_models_as_dict()
        models = []
        for kind in kinds.split(','):
            models.append(db.class_for_kind(kind))

    remote_api_stub.ConfigureRemoteApi(appid,
                                       path,
                                       auth_func,
                                       host,
                                       secure=secure,
                                       save_cookies=True)
    remote_api_stub.MaybeInvokeAuthentication()
    delete_all_entities(models)
    if clear_memcache:
        from google.appengine.api import memcache
        memcache.flush_all()
        sys.stderr.write("Flushed memcache.\n")
Exemple #5
0
    def inner(appid=('a', ''),
              host=('h', ''),
              path=('p', ''),
              secure=True,
              clean=('c', False)):
        if not appid:
            appid = get_appid()
        if not host:
            host = "%s.appspot.com" % appid
        if not path:
            path = '/remote_api'

        if 'localhost' in host:
            auth_func = dummy_auth
        else:
            auth_func = auth

        remote_api_stub.ConfigureRemoteApi(appid,
                                           path,
                                           auth_func,
                                           host,
                                           secure=secure,
                                           save_cookies=True)
        remote_api_stub.MaybeInvokeAuthentication()

        if clean and callable(clean_func):
            clean_func()
        if callable(main_func):
            main_func()
Exemple #6
0
def create_user(user_name=('u', ''), password=('P', ''), is_admin=('A', False),
                appid=('a', ''), host=('h', ''), path=('p', ''), secure=True):
  """ Create new user using remote_api.
  """
  from kay.auth import (
    create_new_user, DuplicateKeyError,
  )
  if not user_name:
    print_status('user_name required')
    sys.exit(1)
  if not password:
    password = getpass.getpass('Please input a password for new user:'******'/remote_api'
  
  remote_api_stub.ConfigureRemoteApi(None, path, auth_func,
                                     host, secure=secure, save_cookies=True)
  remote_api_stub.MaybeInvokeAuthentication()
  try:
    create_new_user(user_name, password, is_admin=is_admin)
    print_status('A new user: %s successfully created.' % user_name)
    sys.exit(0)
  except DuplicateKeyError, e:
    print_status(e)
    sys.exit(1)
Exemple #7
0
 def create_login_url(self, url):
   import os
   hostname = get_appid() + '.appspot.com'
   url = url_for("auth/login",
                 next=url_quote_plus(url),
                 original_host_url=url_quote_plus(local.request.host_url),
                 owned_domain_hack=True)
   if 'SERVER_SOFTWARE' in os.environ and \
         os.environ['SERVER_SOFTWARE'].startswith('Dev'):
     return url
   else:
     return "https://%s%s" % (hostname, url)
Exemple #8
0
def setup_env():
    try:
        os.environ['APPLICATION_ID'] = get_appid()
    except Exception:
        fake_appid = os.path.basename(
            os.path.dirname(
                os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
        os.environ['APPLICATION_ID'] = fake_appid
    os.environ['USER_EMAIL'] = ''
    os.environ['SERVER_NAME'] = 'localhost'
    os.environ['SERVER_PORT'] = '80'
    logging.getLogger().setLevel(logging.ERROR)
Exemple #9
0
 def create_login_url(self, url):
     import os
     hostname = get_appid() + '.appspot.com'
     url = url_for("auth/login",
                   next=url_quote_plus(url),
                   original_host_url=url_quote_plus(local.request.host_url),
                   owned_domain_hack=True)
     if 'SERVER_SOFTWARE' in os.environ and \
           os.environ['SERVER_SOFTWARE'].startswith('Dev'):
         return url
     else:
         return "https://%s%s" % (hostname, url)
Exemple #10
0
def rshell(appid=('a', ''), host=('h', ''), path=('p', ''),
           useful_imports=True, secure=True, use_ipython=True):
  """Start a new interactive python session with RemoteDatastore stub."""
  banner = ("Interactive Kay Shell with RemoteDatastore. \n"
            "-----------------WARNING--------------------\n"
            "\n"
            "Please be careful in this console session.\n"
            "\n"
            "-----------------WARNING--------------------\n")
  if useful_imports:
    namespace = create_useful_locals_for_rshell()
  else:
    namespace = {}
  if not appid:
    appid = get_appid()
  if not host:
    host = "%s.appspot.com" % appid
  if not path:
    path = DEFAULT_REMOTE_API_PATH

  remote_api_stub.ConfigureRemoteApi(None, path, auth_func,
                                     host, secure=secure, save_cookies=True)
  remote_api_stub.MaybeInvokeAuthentication()
  if use_ipython:
    try:
      import IPython
    except ImportError:
      pass
    else:
      try:
        sh = IPython.Shell.IPShellEmbed(
          argv=['-pi1', '%s[\#]: ' % appid, '-po', '%s[\#]: ' % appid],
          banner=banner)
        sh(global_ns={}, local_ns=namespace)
      except AttributeError:
        from IPython.config.loader import Config
        from IPython.frontend.terminal.embed import InteractiveShellEmbed
        cfg = Config()
	prompt_config = cfg.PromptManager
	prompt_config.in_template = '%s[\#]: ' % appid
        prompt_config.in2_template = '   .\\D.: '
        prompt_config.out_template = '%s[\#]: ' % appid
        sh = InteractiveShellEmbed(config=cfg, banner1=banner, user_global_ns={})
        sh(local_ns=namespace)
      return
  sys.ps1 = '%s> ' % appid
  if readline is not None:
    readline.parse_and_bind('tab: complete')
    atexit.register(lambda: readline.write_history_file(HISTORY_PATH))
    if os.path.exists(HISTORY_PATH):
      readline.read_history_file(HISTORY_PATH)
  from code import interact
  interact(banner, local=namespace)
Exemple #11
0
def rshell(appid=('a', ''),
           host=('h', ''),
           path=('p', ''),
           useful_imports=True,
           secure=True,
           use_ipython=True):
    """Start a new interactive python session with RemoteDatastore stub."""
    banner = ("Interactive Kay Shell with RemoteDatastore. \n"
              "-----------------WARNING--------------------\n"
              "\n"
              "Please be careful in this console session.\n"
              "\n"
              "-----------------WARNING--------------------\n")
    if useful_imports:
        namespace = create_useful_locals_for_rshell()
    else:
        namespace = {}
    if not appid:
        appid = get_appid()
    if not host:
        host = "%s.appspot.com" % appid
    if not path:
        path = '/remote_api'

    remote_api_stub.ConfigureRemoteApi(appid,
                                       path,
                                       auth_func,
                                       host,
                                       secure=secure,
                                       save_cookies=True)
    remote_api_stub.MaybeInvokeAuthentication()
    if use_ipython:
        try:
            import IPython
        except ImportError:
            pass
        else:
            sh = IPython.Shell.IPShellEmbed(
                argv=['-pi1',
                      '%s[\#]: ' % appid, '-po',
                      '%s[\#]: ' % appid],
                banner=banner)
            sh(global_ns={}, local_ns=namespace)
            return
    sys.ps1 = '%s> ' % appid
    if readline is not None:
        readline.parse_and_bind('tab: complete')
        atexit.register(lambda: readline.write_history_file(HISTORY_PATH))
        if os.path.exists(HISTORY_PATH):
            readline.read_history_file(HISTORY_PATH)
    from code import interact
    interact(banner, local=namespace)
Exemple #12
0
def setup_env():
  try:
    os.environ['APPLICATION_ID'] = get_appid()
  except Exception:
    fake_appid = os.path.basename(
      os.path.dirname(
        os.path.dirname(
          os.path.dirname(os.path.abspath(__file__)))))
    os.environ['APPLICATION_ID'] = fake_appid
  os.environ['USER_EMAIL'] = ''
  os.environ['SERVER_NAME'] = 'localhost'
  os.environ['SERVER_PORT'] = '80'
  logging.getLogger().setLevel(logging.ERROR)
Exemple #13
0
def shell(datastore_path='',
          history_path='',
          useful_imports=True,
          use_ipython=True,
          use_sqlite=False):
    """ Start a new interactive python session."""
    banner = 'Interactive Kay Shell'
    if useful_imports:
        namespace = create_useful_locals()
    else:
        namespace = {}
    appid = get_appid()
    os.environ['APPLICATION_ID'] = appid
    p = get_datastore_paths()
    if not datastore_path:
        datastore_path = p[0]
    if not history_path:
        history_path = p[1]
    apiproxy_stub_map.apiproxy = apiproxy_stub_map.APIProxyStubMap()
    if use_sqlite:
        from google.appengine.datastore import datastore_sqlite_stub
        stub = datastore_sqlite_stub.DatastoreSqliteStub(
            appid, datastore_path, history_path)
    else:
        stub = datastore_file_stub.DatastoreFileStub(appid, datastore_path,
                                                     history_path)
    apiproxy_stub_map.apiproxy.RegisterStub('datastore_v3', stub)
    if use_ipython:
        try:
            import IPython
        except ImportError:
            pass
        else:
            sh = IPython.Shell.IPShellEmbed(argv='', banner=banner)
            sh(global_ns={}, local_ns=namespace)
            return
    sys.ps1 = '%s> ' % appid
    if readline is not None:
        readline.parse_and_bind('tab: complete')
        atexit.register(lambda: readline.write_history_file(HISTORY_PATH))
        if os.path.exists(HISTORY_PATH):
            readline.read_history_file(HISTORY_PATH)
    from code import interact
    interact(banner, local=namespace)
Exemple #14
0
def setup_env():
    try:
        os.environ['APPLICATION_ID'] = get_appid()
    except Exception:
        fake_appid = os.path.basename(
            os.path.dirname(
                os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
        os.environ['APPLICATION_ID'] = fake_appid
    try:
        os.environ['CURRENT_VERSION_ID'] = get_versionid()
    except Exception:
        # Note: Must have a major and minor version seperated by a '.'
        fake_versionid = "1.1"
        os.environ['CURRENT_VERSION_ID'] = fake_versionid

    os.environ['USER_EMAIL'] = ''
    os.environ['SERVER_NAME'] = 'localhost'
    os.environ['SERVER_PORT'] = '80'
    logging.getLogger().setLevel(logging.ERROR)
Exemple #15
0
def rshell(appid=('a', ''), host=('h', ''), path=('p', ''),
           useful_imports=True, secure=True, use_ipython=True):
  """Start a new interactive python session with RemoteDatastore stub."""
  banner = ("Interactive Kay Shell with RemoteDatastore. \n"
            "-----------------WARNING--------------------\n"
            "\n"
            "Please be careful in this console session.\n"
            "\n"
            "-----------------WARNING--------------------\n")
  if useful_imports:
    namespace = create_useful_locals_for_rshell()
  else:
    namespace = {}
  if not appid:
    appid = get_appid()
  if not host:
    host = "%s.appspot.com" % appid
  if not path:
    path = '/remote_api'

  remote_api_stub.ConfigureRemoteApi(None, path, auth_func,
                                     host, secure=secure, save_cookies=True)
  remote_api_stub.MaybeInvokeAuthentication()
  if use_ipython:
    try:
      import IPython
    except ImportError:
      pass
    else:
      sh = IPython.Shell.IPShellEmbed(
        argv=['-pi1', '%s[\#]: ' % appid, '-po', '%s[\#]: ' % appid],
        banner=banner)
      sh(global_ns={}, local_ns=namespace)
      return
  sys.ps1 = '%s> ' % appid
  if readline is not None:
    readline.parse_and_bind('tab: complete')
    atexit.register(lambda: readline.write_history_file(HISTORY_PATH))
    if os.path.exists(HISTORY_PATH):
      readline.read_history_file(HISTORY_PATH)
  from code import interact
  interact(banner, local=namespace)
Exemple #16
0
def setup_env():
  try:
    os.environ['APPLICATION_ID'] = get_appid()
  except Exception:
    fake_appid = os.path.basename(
      os.path.dirname(
        os.path.dirname(
          os.path.dirname(os.path.abspath(__file__)))))
    os.environ['APPLICATION_ID'] = fake_appid
  try:
    os.environ['CURRENT_VERSION_ID'] = get_versionid()
  except Exception:
    # Note: Must have a major and minor version seperated by a '.'
    fake_versionid = "1.1"
    os.environ['CURRENT_VERSION_ID'] = fake_versionid

  os.environ['USER_EMAIL'] = ''
  os.environ['SERVER_NAME'] = 'localhost'
  os.environ['SERVER_PORT'] = '80'
  logging.getLogger().setLevel(logging.ERROR)
Exemple #17
0
def shell(datastore_path='', history_path='', useful_imports=True,
          use_ipython=True, use_sqlite=False):
  """ Start a new interactive python session."""
  banner = 'Interactive Kay Shell'
  if useful_imports:
    namespace = create_useful_locals()
  else:
    namespace = {}
  appid = get_appid()
  os.environ['APPLICATION_ID'] = appid
  p = get_datastore_paths()
  if not datastore_path:
    datastore_path = p[0]
  if not history_path:
    history_path = p[1]
  apiproxy_stub_map.apiproxy = apiproxy_stub_map.APIProxyStubMap()
  if use_sqlite:
    from google.appengine.datastore import datastore_sqlite_stub
    stub = datastore_sqlite_stub.DatastoreSqliteStub(appid, datastore_path,
                                                     history_path)
  else:
    stub = datastore_file_stub.DatastoreFileStub(appid, datastore_path,
                                                 history_path)
  apiproxy_stub_map.apiproxy.RegisterStub('datastore_v3', stub)
  if use_ipython:
    try:
      import IPython
    except ImportError:
      pass
    else:
      sh = IPython.Shell.IPShellEmbed(argv='', banner=banner)
      sh(global_ns={}, local_ns=namespace)
      return
  sys.ps1 = '%s> ' % appid
  if readline is not None:
    readline.parse_and_bind('tab: complete')
    atexit.register(lambda: readline.write_history_file(HISTORY_PATH))
    if os.path.exists(HISTORY_PATH):
      readline.read_history_file(HISTORY_PATH)
  from code import interact
  interact(banner, local=namespace)
Exemple #18
0
  def inner(appid=('a', ''), host=('h', ''), path=('p', ''),
            secure=True, clean=('c', False)):
    if not appid:
      appid = get_appid()
    if not host:
      host = "%s.appspot.com" % appid
    if not path:
      path = '/remote_api'

    if 'localhost' in host:
      auth_func = dummy_auth
    else:
      auth_func = auth

    remote_api_stub.ConfigureRemoteApi(appid, path, auth_func,
                                       host, secure=secure, save_cookies=True)
    remote_api_stub.MaybeInvokeAuthentication()

    if clean and callable(clean_func):
      clean_func()
    if callable(main_func):
      main_func()
Exemple #19
0
def add_request(properties, context, user, groupname=None):
    blip = context.GetBlipById(properties['blipId'])
    group = Group.get_by_key_name(Group.get_key_name(groupname))
    text = "You(%s) requested adding you to the group: %s.\n" % (user,
                                                                 groupname)
    if group:
        if user in group.members:
            text += "You are already a member of the group: %s." % groupname
        elif user in group.applications:
            text += ("You have already applied to join the group: %s. "
                     "Please wait for a moment." % groupname)
        elif user in group.banned_addresses:
            text += "You are banned from the group: %s." % groupname
        else:
            from google.appengine.api import mail
            from google.appengine.ext import db
            body = "%s has requested joining the group: %s.\n" % (user,
                                                                  groupname)
            body += "You can moderate this request on following URL:\n"
            body += "http://%s.appspot.com/edit_group?key_name=%s" \
                % (get_appid(), group.key().name().replace(":", "%3A"))
            mail.send_mail(sender=settings.ADMINS[0][1],
                           to=group.owner.email,
                           subject="Join request from %s has come" % user,
                           body=body)

            def txn():
                g = Group.get(group.key())
                g.applications.append(user)
                g.put()

            db.run_in_transaction(txn)
            text += "Request to join this group has been sent!"
    else:
        text += "However, there is no such group! Sorry."
    blip.CreateChild().GetDocument().SetText(text)
Exemple #20
0
def dump_or_restore_all(help, data_set_name, app_id, url, directory, batch_size, op):
  if help:
    print_status('help for %s' % op)
    sys.exit(0)
  if not data_set_name:
    data_set_name = datetime.datetime.now().strftime("%Y%m%d.%H%M%S")
  if not app_id:
    app_id = get_appid()
  if not url:
    url = "https://%s.appspot.com/remote_api" % app_id
  if not directory:
    directory = '_backup'
  target_dir = os.path.join(kay.PROJECT_DIR, directory, data_set_name)

  if not os.path.isdir(target_dir):
    if op == DUMP:
      makedirs(target_dir)
      print_status('Directory "%s" created.' % target_dir)
    else:
      print_status('Directory "%s" is missing, exiting...' % target_dir)
      sys.exit(1)
      
  current_time = datetime.datetime.now().strftime("%Y%m%d.%H%M%S")
  models = get_all_models_as_dict(only_polymodel_base=True)
  results = {}
  if op == RESTORE:
    base_args = ["bulkloader", "--restore"]
  else:
    base_args = ["bulkloader", "--dump"] 
  base_args.append("--application=%s" % app_id)
  if "localhost" in url:
    bulkloader.RequestManager.AuthFunction = dummy_auth_func
  else:
    bulkloader.RequestManager.AuthFunction = real_auth_func
  for key, model in models.iteritems():
    kind = model.kind()
    db_filename = os.path.join(target_dir, "bulkloader-%s-%s.progress" %
                               (kind, current_time))
    log_file = os.path.join(target_dir, "bulkloader-%s-%s.log" %
                            (kind, current_time))
    result_db_filename = os.path.join(target_dir, "bulkloader-%s-%s.result" %
                                      (kind, current_time))
    args = copy.copy(base_args)
    args.append("--filename=%s" % os.path.join(target_dir, "%s.dat" % kind))
    args.append("--kind=%s" % kind)
    args.append("--db_filename=%s" % db_filename)
    args.append("--log_file=%s" % log_file)
    if batch_size:
        args.append("--batch_size=%s" % int(batch_size))
    if op == DUMP:
      args.append("--result_db_filename=%s" % result_db_filename)
    args.append("--url=%s" % url)
    try:
      from werkzeug.utils import import_string
      backup_mod = import_string(directory)
      if op == RESTORE:
        args.extend(backup_mod.restore_options[kind])
      else:
        args.extend(backup_mod.dump_options[kind])
    except:
      pass
    try:
      results[key] = bulkloader.main(args)
    except bulkloader.FileNotFoundError, e:
      print_status("File not found, skipped: %s" % e)
      results[key] = -1
      continue
    logging.getLogger('google.appengine.tools.bulkloader').handlers = []
Exemple #21
0
import logging
import re

from waveapi import events
from waveapi import model
from waveapi import robot

import kay
kay.setup()

from kay.misc import get_appid
from kay.conf import settings

from groupy.models import Group

hostname = "%s.appspot.com" % get_appid()


class Command(object):
    def __init__(self, name, pattern, func):
        self.name = name
        self.pattern = pattern
        self.func = func

    def __call__(self, properties, context, user, **kwargs):
        return self.func(properties, context, user, **kwargs)


def desc(properties, context, user, groupname=None):
    blip = context.GetBlipById(properties['blipId'])
    group = Group.get_by_key_name(Group.get_key_name(groupname))
Exemple #22
0
def dump_or_restore_all(help, data_set_name, app_id, url, directory, op):
    if help:
        print_status('help for %s' % op)
        sys.exit(0)
    if not data_set_name:
        data_set_name = datetime.datetime.now().strftime("%Y%m%d.%H%M%S")
    if not app_id:
        app_id = get_appid()
    if not url:
        url = "https://%s.appspot.com/remote_api" % app_id
    if not directory:
        directory = '_backup'
    target_dir = os.path.join(kay.PROJECT_DIR, directory, data_set_name)

    if not os.path.isdir(target_dir):
        if op == DUMP:
            makedirs(target_dir)
            print_status('Directory "%s" created.' % target_dir)
        else:
            print_status('Directory "%s" is missing, exiting...' % target_dir)
            sys.exit(1)

    current_time = datetime.datetime.now().strftime("%Y%m%d.%H%M%S")
    models = get_all_models_as_dict(only_polymodel_base=True)
    results = {}
    if op == RESTORE:
        base_args = ["bulkloader", "--restore"]
    else:
        base_args = ["bulkloader", "--dump"]
    if "localhost" in url:
        base_args.append("--app_id=%s" % app_id)
        bulkloader.RequestManager.AuthFunction = dummy_auth_func
    else:
        bulkloader.RequestManager.AuthFunction = real_auth_func
    for key, model in models.iteritems():
        kind = model.kind()
        db_filename = os.path.join(
            target_dir, "bulkloader-%s-%s.progress" % (kind, current_time))
        log_file = os.path.join(target_dir,
                                "bulkloader-%s-%s.log" % (kind, current_time))
        result_db_filename = os.path.join(
            target_dir, "bulkloader-%s-%s.result" % (kind, current_time))
        args = copy.copy(base_args)
        args.append("--filename=%s" %
                    os.path.join(target_dir, "%s.dat" % kind))
        args.append("--kind=%s" % kind)
        args.append("--db_filename=%s" % db_filename)
        args.append("--log_file=%s" % log_file)
        if op == DUMP:
            args.append("--result_db_filename=%s" % result_db_filename)
        args.append("--url=%s" % url)
        try:
            from werkzeug.utils import import_string
            backup_mod = import_string(directory)
            if op == RESTORE:
                args.extend(backup_mod.restore_options[kind])
            else:
                args.extend(backup_mod.dump_options[kind])
        except:
            pass
        try:
            results[key] = bulkloader.main(args)
        except bulkloader.FileNotFoundError, e:
            print_status("File not found, skipped: %s" % e)
            results[key] = -1
            continue
        logging.getLogger('google.appengine.tools.bulkloader').handlers = []
Exemple #23
0
import logging
import re

from waveapi import events
from waveapi import model
from waveapi import robot

import kay
kay.setup()

from kay.misc import get_appid
from kay.conf import settings

from groupy.models import Group

hostname = "%s.appspot.com" % get_appid()

class Command(object):
  def __init__(self, name, pattern, func):
    self.name = name
    self.pattern = pattern
    self.func = func
  def __call__(self, properties, context, user, **kwargs):
    return self.func(properties, context, user, **kwargs)

def desc(properties, context, user, groupname=None):
  blip = context.GetBlipById(properties['blipId'])
  group = Group.get_by_key_name(Group.get_key_name(groupname))
  text = ("You(%s) requested the description of the group: %s.\n"
          % (user, groupname))
  if group:
Exemple #24
0
:Copyright: (c) 2009 Takashi Matsuo <*****@*****.**>,
                     TAGOMORI Satoshi <*****@*****.**>
                     All rights reserved.
:license: BSD, see LICENSE for more details.
"""

import os, sys
import functools
import unittest

import kay
kay.setup()
from kay.misc import get_appid

APP_ID = get_appid()
REMOTE_API_ENTRY_POINT = '/remote_api'

from google.appengine.ext.db import KindError

def is_in_production():
    if os.environ.get("SERVER_NAME", None) == "localhost":
      return False
    if os.environ.get("SERVER_SOFTWARE", "").startswith('Dev'):
      return False
    return True

if not is_in_production():
    import getpass

    from google.appengine.tools import appengine_rpc
Exemple #25
0
:Copyright: (c) 2009 Takashi Matsuo <*****@*****.**>,
                     TAGOMORI Satoshi <*****@*****.**>
                     All rights reserved.
:license: BSD, see LICENSE for more details.
"""

import os, sys
import functools
import unittest

import kay
kay.setup()
from kay.misc import get_appid

APP_ID = get_appid()
REMOTE_API_ENTRY_POINT = '/remote_api'

from google.appengine.ext.db import KindError


def is_in_production():
    if os.environ.get("SERVER_NAME", None) == "localhost":
        return False
    if os.environ.get("SERVER_SOFTWARE", "").startswith('Dev'):
        return False
    return True


if not is_in_production():
    import getpass
Exemple #26
0
def rshell(appid=('a', ''),
           host=('h', ''),
           path=('p', ''),
           useful_imports=True,
           secure=True,
           use_ipython=True):
    """Start a new interactive python session with RemoteDatastore stub."""
    banner = ("Interactive Kay Shell with RemoteDatastore. \n"
              "-----------------WARNING--------------------\n"
              "\n"
              "Please be careful in this console session.\n"
              "\n"
              "-----------------WARNING--------------------\n")
    if useful_imports:
        namespace = create_useful_locals_for_rshell()
    else:
        namespace = {}
    if not appid:
        appid = get_appid()
    if not host:
        host = "%s.appspot.com" % appid
    if not path:
        path = DEFAULT_REMOTE_API_PATH

    remote_api_stub.ConfigureRemoteApi(None,
                                       path,
                                       auth_func,
                                       host,
                                       secure=secure,
                                       save_cookies=True)
    remote_api_stub.MaybeInvokeAuthentication()
    if use_ipython:
        try:
            import IPython
        except ImportError:
            pass
        else:
            try:
                sh = IPython.Shell.IPShellEmbed(argv=[
                    '-pi1',
                    '%s[\#]: ' % appid, '-po',
                    '%s[\#]: ' % appid
                ],
                                                banner=banner)
                sh(global_ns={}, local_ns=namespace)
            except AttributeError:
                from IPython.config.loader import Config
                from IPython.frontend.terminal.embed import InteractiveShellEmbed
                cfg = Config()
                prompt_config = cfg.PromptManager
                prompt_config.in_template = '%s[\#]: ' % appid
                prompt_config.in2_template = '   .\\D.: '
                prompt_config.out_template = '%s[\#]: ' % appid
                sh = InteractiveShellEmbed(config=cfg,
                                           banner1=banner,
                                           user_global_ns={})
                sh(local_ns=namespace)
            return
    sys.ps1 = '%s> ' % appid
    if readline is not None:
        readline.parse_and_bind('tab: complete')
        atexit.register(lambda: readline.write_history_file(HISTORY_PATH))
        if os.path.exists(HISTORY_PATH):
            readline.read_history_file(HISTORY_PATH)
    from code import interact
    interact(banner, local=namespace)