def main():
    parser = OptionParser(usage='%prog [options] dburl', version=VERSION)
    parser.add_option('--input', action='store', dest='input', metavar='FILE',
                      help='the name of the file to read from')
    parser.add_option('--ignore-errors', action='store_true',
                      dest='ignore_errors',
                      help='whether to ignore errors in document creation '
                           'and continue with the remaining documents')
    parser.add_option('--json-module', action='store', dest='json_module',
                      help='the JSON module to use ("simplejson", "cjson", '
                            'or "json" are supported)')
    parser.add_option('-u', '--username', action='store', dest='username',
                      help='the username to use for authentication')
    parser.add_option('-p', '--password', action='store', dest='password',
                      help='the password to use for authentication')
    parser.set_defaults(input='-')
    options, args = parser.parse_args()

    if len(args) != 1:
        return parser.error('incorrect number of arguments')

    if options.input != '-':
        fileobj = open(options.input, 'rb')
    else:
        fileobj = sys.stdin

    if options.json_module:
        json.use(options.json_module)

    load_db(fileobj, args[0], username=options.username,
            password=options.password, ignore_errors=options.ignore_errors)
Exemple #2
0
def main():
    parser = OptionParser(usage='%prog [options] dburl', version=VERSION)
    parser.add_option('--input',
                      action='store',
                      dest='input',
                      metavar='FILE',
                      help='the name of the file to read from')
    parser.add_option('--ignore-errors',
                      action='store_true',
                      dest='ignore_errors',
                      help='whether to ignore errors in document creation '
                      'and continue with the remaining documents')
    parser.add_option('--json-module',
                      action='store',
                      dest='json_module',
                      help='the JSON module to use ("simplejson", "cjson", '
                      'or "json" are supported)')
    parser.add_option('-u',
                      '--username',
                      action='store',
                      dest='username',
                      help='the username to use for authentication')
    parser.add_option('-p',
                      '--password',
                      action='store',
                      dest='password',
                      help='the password to use for authentication')
    parser.set_defaults(input='-')
    options, args = parser.parse_args()

    if len(args) != 1:
        return parser.error('incorrect number of arguments')

    if options.input != '-':
        fileobj = open(options.input, 'rb')
    else:
        fileobj = sys.stdin

    if options.json_module:
        json.use(options.json_module)

    load_db(fileobj,
            args[0],
            username=options.username,
            password=options.password,
            ignore_errors=options.ignore_errors)
def main():
    """Command-line entry point for running the view server."""
    import getopt
    from couchdbcurl import __version__ as VERSION

    try:
        option_list, argument_list = getopt.gnu_getopt(
            sys.argv[1:], 'h',
            ['version', 'help', 'json-module=', 'debug', 'log-file=']
        )

        message = None
        for option, value in option_list:
            if option in ('--version'):
                message = _VERSION % dict(name=os.path.basename(sys.argv[0]),
                                      version=VERSION)
            elif option in ('-h', '--help'):
                message = _HELP % dict(name=os.path.basename(sys.argv[0]))
            elif option in ('--json-module'):
                json.use(module=value)
            elif option in ('--debug'):
                log.setLevel(logging.DEBUG)
            elif option in ('--log-file'):
                if value == '-':
                    handler = logging.StreamHandler(sys.stderr)
                    handler.setFormatter(logging.Formatter(
                        ' -> [%(levelname)s] %(message)s'
                    ))
                else:
                    handler = logging.FileHandler(value)
                    handler.setFormatter(logging.Formatter(
                        '[%(asctime)s] [%(levelname)s] %(message)s'
                    ))
                log.addHandler(handler)
        if message:
            sys.stdout.write(message)
            sys.stdout.flush()
            sys.exit(0)

    except getopt.GetoptError, error:
        message = '%s\n\nTry `%s --help` for more information.\n' % (
            str(error), os.path.basename(sys.argv[0])
        )
        sys.stderr.write(message)
        sys.stderr.flush()
        sys.exit(1)
Exemple #4
0
def main():
    """Command-line entry point for running the view server."""
    import getopt

    try:
        option_list, argument_list = getopt.gnu_getopt(
            sys.argv[1:], 'h',
            ['version', 'help', 'json-module=', 'debug', 'log-file=']
        )

        message = None
        for option, value in option_list:
            if option in ('-h', '--help'):
                message = _HELP % dict(name=os.path.basename(sys.argv[0]))
            elif option in ('--json-module'):
                json.use(module=value)
            elif option in ('--debug'):
                log.setLevel(logging.DEBUG)
            elif option in ('--log-file'):
                if value == '-':
                    handler = logging.StreamHandler(sys.stderr)
                    handler.setFormatter(logging.Formatter(
                        ' -> [%(levelname)s] %(message)s'
                    ))
                else:
                    handler = logging.FileHandler(value)
                    handler.setFormatter(logging.Formatter(
                        '[%(asctime)s] [%(levelname)s] %(message)s'
                    ))
                log.addHandler(handler)
        if message:
            sys.stdout.write(message)
            sys.stdout.flush()
            sys.exit(0)

    except getopt.GetoptError as error:
        message = '%s\n\nTry `%s --help` for more information.\n' % (
            str(error), os.path.basename(sys.argv[0])
        )
        sys.stderr.write(message)
        sys.stderr.flush()
        sys.exit(1)

    sys.exit(run())
def main():
    parser = OptionParser(usage='%prog [options] dburl', version=VERSION)
    parser.add_option('--json-module', action='store', dest='json_module',
                      help='the JSON module to use ("simplejson", "cjson", '
                            'or "json" are supported)')
    parser.add_option('-u', '--username', action='store', dest='username',
                      help='the username to use for authentication')
    parser.add_option('-p', '--password', action='store', dest='password',
                      help='the password to use for authentication')
    parser.set_defaults()
    options, args = parser.parse_args()

    if len(args) != 1:
        return parser.error('incorrect number of arguments')

    if options.json_module:
        json.use(options.json_module)

    dump_db(args[0], username=options.username, password=options.password)
Exemple #6
0
def main():
    """Command-line entry point for running the view server."""
    import getopt

    try:
        option_list, argument_list = getopt.gnu_getopt(
            sys.argv[1:], "h", ["version", "help", "json-module=", "debug", "log-file="]
        )

        message = None
        for option, value in option_list:
            if option in ("-h", "--help"):
                message = _HELP % dict(name=os.path.basename(sys.argv[0]))
            elif option in ("--json-module"):
                json.use(module=value)
            elif option in ("--debug"):
                log.setLevel(logging.DEBUG)
            elif option in ("--log-file"):
                if value == "-":
                    handler = logging.StreamHandler(sys.stderr)
                    handler.setFormatter(logging.Formatter(" -> [%(levelname)s] %(message)s"))
                else:
                    handler = logging.FileHandler(value)
                    handler.setFormatter(logging.Formatter("[%(asctime)s] [%(levelname)s] %(message)s"))
                log.addHandler(handler)
        if message:
            sys.stdout.write(message)
            sys.stdout.flush()
            sys.exit(0)

    except getopt.GetoptError as error:
        message = "%s\n\nTry `%s --help` for more information.\n" % (str(error), os.path.basename(sys.argv[0]))
        sys.stderr.write(message)
        sys.stderr.flush()
        sys.exit(1)

    sys.exit(run())
def main():
    usage = '%prog [options] SOURCE_URL TARGET_URL1 [TARGET_URL2 ...]'

    parser = optparse.OptionParser(usage=usage, version=VERSION)

    parser.add_option('--batch-threshold',
        action='store',
        dest='batch_threshold',
        default=0,
        metavar='NUM',
        help='number of changes that are to be replicated')
    parser.add_option('--wait-threshold',
        action='store',
        dest='wait_threshold',
        default=0.01,
        metavar='SECS',
        help='number of seconds to wait before triggering replication')
    parser.add_option('--ignore-deletes',
        action='store_true',
        dest='ignore_deletes',
        help='whether to ignore "delete" notifications')
    parser.add_option('--debug',
        action='store_true',
        dest='debug',
        help='enable debug logging; requires --log-file to be specified')
    parser.add_option('--log-file',
        action='store',
        dest='log_file',
        metavar='FILE',
        help='name of the file to write log messages to, or "-" to enable '
             'logging to the standard error stream')
    parser.add_option('--json-module',
        action='store',
        dest='json_module',
        metavar='NAME',
        help='the JSON module to use ("simplejson", "cjson", or "json" are '
             'supported)')

    options, args = parser.parse_args()
    if len(args) < 2:
        parser.error("need at least one source and target server")
        sys.exit(1)

    src_url = args[0]
    targets = [
        URLSPLIT_RE.match(url).groupdict()
        for url in args[1:]
    ]

    if options.debug:
        log.setLevel(logging.DEBUG)

    if options.log_file:
        if options.log_file == '-':
            handler = logging.StreamHandler(sys.stderr)
            handler.setFormatter(logging.Formatter(
                ' -> [%(levelname)s] %(message)s'
            ))
        else:
            handler = logging.FileHandler(options.log_file)
            handler.setFormatter(logging.Formatter(
                '[%(asctime)s] [%(levelname)s] %(message)s'
            ))
        log.addHandler(handler)

    if options.json_module:
        json.use(options.json_module)

    log.debug('Syncing changes from %r to %r', src_url, targets)
    try:
        ReplicationHelper(src_url, targets, options)()
    except Exception, e:
        log.exception(e)