Пример #1
0
def main(url, kwargs):
    global db, conn
    if not url:
        url = ['mongodb://localhost/']
    conn = MongoClient(host=url, **kwargs)
    try:
        dbname = urllib.parse.urlsplit(url[0]).path.lstrip('/') or 'test'
    except IndexError:
        dbname = 'test'
    db = conn[dbname]

    rc = os.path.expanduser('~/.mongorc.py')
    if os.path.isfile(rc):
        exec(compile(open(rc, 'rb').read(), '.mongorc.py', 'exec'))

    global v
    v = globals().copy()
    v.update(locals())
    v['_'] = None
    del v['repl'], v['kwargs'], v['main']
    del v['displayfunc'], v['subprocess'], v['env']
    del v['__name__'], v['__cached__'], v['__doc__'], v['__file__'], v[
        '__package__']
    del v['rc'], v['argparse']
    sys.displayhook = displayfunc

    repl(
        v,
        os.path.expanduser('~/.mongo_history'),
        banner='Python MongoDB console',
    )
Пример #2
0
def main(kwargs):
    global db, conn
    conn = MongoClient(host=host, port=port, **kwargs)
    db = conn[db]

    rc = os.path.expanduser('~/.mongorc.py')
    if os.path.isfile(rc):
        exec(compile(open(rc, 'rb').read(), '.mongorc.py', 'exec'))

    global v
    v = globals().copy()
    v.update(locals())
    v['_'] = None
    del v['repl'], v['kwargs'], v['main'], v['host'], v['port']
    del v['displayfunc'], v['subprocess'], v['env']
    del v['__name__'], v['__cached__'], v['__doc__'], v['__file__'], v[
        '__package__']
    del v['rc'], v['argparse']
    sys.displayhook = displayfunc

    repl(
        v,
        os.path.expanduser('~/.mongo_history'),
        banner='Python MongoDB console',
    )
Пример #3
0
def main(url, kwargs):
  global db, conn
  if not url:
    url = ['mongodb://localhost/']
  conn = MongoClient(host=url, **kwargs)
  try:
    dbname = urllib.parse.urlsplit(url[0]).path.lstrip('/') or 'test'
  except IndexError:
    dbname = 'test'
  db = conn[dbname]

  global v
  v = globals().copy()
  v.update(locals())
  v['_'] = None
  del v['repl'], v['kwargs'], v['main']
  del v['displayfunc'], v['subprocess'], v['env']
  del v['__name__'], v['__cached__'], v['__doc__'], v['__file__'], v['__package__']
  del v['argparse']
  sys.displayhook = displayfunc

  rc = os.path.expanduser('~/.mongorc.py')
  if os.path.isfile(rc):
    exec(compile(open(rc, 'rb').read(), '.mongorc.py', 'exec'), v)

  repl(
    v, os.path.expanduser('~/.mongo_history'),
    banner = 'Python MongoDB console',
  )
Пример #4
0
def do_debug(self, arg):
  if sys.stdin.isatty():
    import builtins
    from cli import repl
    from pyxmpp2.jid import JID
    old_ = builtins._
    g = locals()
    del g['repl'], g['builtins'], g['old_'], g['arg']
    repl(g, 'cmd.txt')
    builtins._ = old_
  else:
    self.reply(_('Error: stdin is not terminal.'))
  return True
Пример #5
0
def do_debug(self, arg):
    if sys.stdin.isatty():
        import builtins
        from cli import repl
        from pyxmpp2.jid import JID
        old_ = builtins._
        g = locals()
        del g['repl'], g['builtins'], g['old_'], g['arg']
        repl(g, 'cmd.txt')
        builtins._ = old_
    else:
        self.reply(_('Error: stdin is not terminal.'))
    return True
Пример #6
0
def debug(self, msg):
  '''debug things; unregister in production!'''
  if msg == 'cli':
    import builtins
    from cli import repl
    from pyxmpp2.jid import JID
    old_ = builtins._
    g = locals()
    del g['repl'], g['builtins'], g['old_'], g['msg']
    repl(g, 'cmd.txt')
    builtins._ = old_
    return True
  elif msg == 'cache_clear':
    self.user_get_nick.cache_clear()
    self.reply('ok.')
    return True
Пример #7
0
def main(kwargs):
    global db, conn
    conn = Connection(host=host, port=port, **kwargs)
    db = conn[db]

    rc = os.path.expanduser("~/.mongorc.py")
    if os.path.isfile(rc):
        exec(compile(open(rc, "rb").read(), ".mongorc.py", "exec"))

    global v
    v = globals().copy()
    v.update(locals())
    v["_"] = None
    del v["repl"], v["kwargs"], v["main"], v["host"], v["port"]
    del v["displayfunc"], v["subprocess"], v["env"]
    del v["__name__"], v["__cached__"], v["__doc__"], v["__file__"], v["__package__"]
    del v["rc"], v["argparse"]
    sys.displayhook = displayfunc

    repl(v, os.path.expanduser("~/.mongo_history"), banner="Python MongoDB console")
Пример #8
0
def main(kwargs):
  global db, conn
  conn = Connection(host=host, port=port, **kwargs)
  db = conn[db]

  rc = os.path.expanduser('~/.mongorc.py')
  if os.path.isfile(rc):
    exec(compile(open(rc, 'rb').read(), '.mongorc.py', 'exec'))

  global v
  v = globals().copy()
  v.update(locals())
  v['_'] = None
  del v['repl'], v['kwargs'], v['main'], v['host'], v['port']
  del v['displayfunc'], v['subprocess'], v['env']
  del v['__name__'], v['__cached__'], v['__doc__'], v['__file__'], v['__package__']
  del v['rc'], v['argparse']
  sys.displayhook = displayfunc

  repl(
    v, os.path.expanduser('~/.mongo_history'),
    banner = 'Python MongoDB console',
  )
Пример #9
0
def main():
    print time.time(), "Starting..."
    ic = indexd.client.Client(("", 4002))
    ic.setmode("RDWR")
    ic.createdb("app_store", config)
    ic.setdb("app_store")

    lastt = time.time()
    print lastt, "%d docuemts...Ready to go!" % N
    try:
        for i, data in enumerate(read_from_file(file)):
            # avoid those bad data will kill the connection
            if data["description"] != r"\N":
                del data["id"]
                ret = ic.insert(data)
                assert ret["status"] == "ok", ret["message"]
            if i and i % 2000 == 0:
                ic.commit()
                print "%7.2f: %8d/%d done." % (time.time() - lastt, i, N)
                lastt = time.time()
    except AssertionError:
        from cli import repl

        repl(locals())
Пример #10
0
def main():
    import os
    from getpass import getpass
    import argparse
    from nicelogger import enable_pretty_logging
    from cli import repl
    """Parse the command-line arguments and run the bot."""
    parser = argparse.ArgumentParser(description='XMPP dev bot',
                                     parents=[XMPPSettings.get_arg_parser()])
    parser.add_argument('jid', metavar='JID', help='The bot JID')
    parser.add_argument('--debug',
                        action='store_const',
                        dest='log_level',
                        const=logging.DEBUG,
                        default=logging.INFO,
                        help='Print debug messages')
    parser.add_argument('--quiet',
                        const=logging.ERROR,
                        action='store_const',
                        dest='log_level',
                        help='Print only error messages')
    parser.add_argument('--trace',
                        action='store_true',
                        help='Print XML data sent and received')

    args = parser.parse_args()
    settings = XMPPSettings({"software_name": "pyxmpp2 Bot"})
    settings.load_arguments(args)
    if args.jid.endswith('@gmail.com'):
        settings['starttls'] = True
        settings['tls_verify_peer'] = False

    if settings.get("password") is None:
        password = getpass("{0!r} password: "******"password"] = password

    if args.trace:
        logging.info('enabling trace')
        for logger in ("pyxmpp2.IN", "pyxmpp2.OUT"):
            logger = logging.getLogger(logger)
            logger.setLevel(logging.DEBUG)
    enable_pretty_logging(level=args.log_level)

    bot = AutoAcceptBot(JID(args.jid), settings)

    class Q:
        def __call__(self):
            sys.exit()

        __repr__ = __call__

    q = Q()
    self = bot

    try:
        bot.connect()
        while True:
            try:
                bot.run()
            except KeyboardInterrupt:
                v = vars()
                v.update(globals())
                repl(v, os.path.expanduser('~/.xmppbot_history'))
    except SystemExit:
        bot.disconnect()
    except:
        bot.disconnect()
        import traceback
        traceback.print_exc()
Пример #11
0
def main():
  import os
  from getpass import getpass
  import argparse
  from nicelogger import enable_pretty_logging
  from cli import repl

  """Parse the command-line arguments and run the bot."""
  parser = argparse.ArgumentParser(description = 'XMPP dev bot',
                  parents = [XMPPSettings.get_arg_parser()])
  parser.add_argument('jid', metavar = 'JID',
                    help = 'The bot JID')
  parser.add_argument('--debug',
            action = 'store_const', dest = 'log_level',
            const = logging.DEBUG, default = logging.INFO,
            help = 'Print debug messages')
  parser.add_argument('--quiet', const = logging.ERROR,
            action = 'store_const', dest = 'log_level',
            help = 'Print only error messages')
  parser.add_argument('--trace', action = 'store_true',
            help = 'Print XML data sent and received')

  args = parser.parse_args()
  settings = XMPPSettings({
    "software_name": "pyxmpp2 Bot"
  })
  settings.load_arguments(args)
  if args.jid.endswith('@gmail.com'):
    settings['starttls'] = True
    settings['tls_verify_peer'] = False

  if settings.get("password") is None:
    password = getpass("{0!r} password: "******"password"] = password

  if args.trace:
    logging.info('enabling trace')
    for logger in ("pyxmpp2.IN", "pyxmpp2.OUT"):
      logger = logging.getLogger(logger)
      logger.setLevel(logging.DEBUG)
  enable_pretty_logging(level=args.log_level)

  bot = AutoAcceptBot(JID(args.jid), settings)

  class Q:
    def __call__(self):
      sys.exit()
    __repr__ = __call__

  q = Q()
  self = bot

  try:
    bot.connect()
    while True:
      try:
        bot.run()
      except KeyboardInterrupt:
        v = vars()
        v.update(globals())
        repl(v, os.path.expanduser('~/.xmppbot_history'))
  except SystemExit:
    bot.disconnect()
  except:
    bot.disconnect()
    import traceback
    traceback.print_exc()