コード例 #1
0
ファイル: cxp_to_s3.py プロジェクト: DraconPern/medcommonsPhp
def cxp_to_s3(guid, storageId, host=DEFAULT_HOST, bucket=DEFAULT_BUCKET,
              kfile=DEFAULT_KEYFILE, amazon_user_token=None,
              amazon_product_token=None):
    global status

    if 0:
        params = cxp.params.copy()

        params['host'] = host

        params['documentGuid'] = guid
        params['storageId'] = storageId

        if not status:
            status = mtom.status('CXP get')

        try:
            cxp.get(params, status).cxp(dict(elements = [dict(guid = guid)]))
        except socket.error:
            return CXP_TEMP_ERR
        except:
            from traceback import print_exc
            print_exc(file = stderr)
            return CXP_PERM_ERR
    else:
        params = {'host': host, 'documentGuid': guid, 'storageId': storageId}

    try:
        inp = popen([ ARCHIVE_CMD + ['--directory', '%s/%s' % (REPOSITORY, storageId),
                                     '%s' % guid,
                                     '%s.properties' % guid],
                      COMPRESS_CMD,
                      ENCRYPT_CMD + [kfile] ])

        i = 0

        while True:
            b = read_fully(inp, SEGMENT_SIZE)

            if not b:
                break

            params['i'] = i

            put_data(bucket, OBJECT_FORMAT % params, b,
                     user_token=amazon_user_token,
                     product_token=amazon_product_token)

            i += 1
    except:
        from traceback import print_exc
        print_exc(file = stderr)
        return CXP_PERM_ERR

    #clean(guid)

    return CXP_OK
コード例 #2
0
ファイル: s3backup.py プロジェクト: DraconPern/medcommonsPhp
def main(argv):
    args = argv[1:]

    # Defaults
    key_id = get_s3_info('key_id')
    secret = get_s3_info('key')
    size = DEFAULT_SIZE

    bucket = None
    prefix = None

    while args:
	a = args.pop(0)

        if a == '-C' and args:
            filename = args.pop(0)
            args = file(filename).read().split() + args

        elif a == '-a' and args:
            key_id = args.pop(0)

        elif a == '-s' and args:
            secret = args.pop(0)

        elif a == '-l' and args:
            size = parse_size(args.pop(0))

        elif a == '-mcproperties':
            import s3options
            bucket = s3options.get_bucket()
            key_id = s3options.get_key_id()
            secret = s3options.get_secret()

        elif a.startswith('-'):
            usage()

        elif bucket is None:
            bucket = a

        elif prefix is None:
            prefix = a

        else:
            usage()

    if not prefix or not bucket:
        usage()

    if not key_id:
        print >>stderr, "Must either specify -a {key_id} or put key_id into ~/.s3/key_id"
        exit(1)

    if not secret:
        print >>stderr, "Must either specify -s {secret} or put secret into ~/.s3/key"
        exit(1)

    s3.init0(key_id = key_id, secret = secret)

    segment = 0
    while True:
        block = read_fully(stdin, size)
        if not block:
            break

        object = prefix + '.%03d' % segment

        s3.put_data(bucket, object, block)
        print object, len(block)

        segment += 1
コード例 #3
0
ファイル: s3backup.py プロジェクト: billdonner/medcommonsPhp
def main(argv):
    args = argv[1:]

    # Defaults
    key_id = get_s3_info('key_id')
    secret = get_s3_info('key')
    size = DEFAULT_SIZE

    bucket = None
    prefix = None

    while args:
        a = args.pop(0)

        if a == '-C' and args:
            filename = args.pop(0)
            args = file(filename).read().split() + args

        elif a == '-a' and args:
            key_id = args.pop(0)

        elif a == '-s' and args:
            secret = args.pop(0)

        elif a == '-l' and args:
            size = parse_size(args.pop(0))

        elif a == '-mcproperties':
            import s3options
            bucket = s3options.get_bucket()
            key_id = s3options.get_key_id()
            secret = s3options.get_secret()

        elif a.startswith('-'):
            usage()

        elif bucket is None:
            bucket = a

        elif prefix is None:
            prefix = a

        else:
            usage()

    if not prefix or not bucket:
        usage()

    if not key_id:
        print >> stderr, "Must either specify -a {key_id} or put key_id into ~/.s3/key_id"
        exit(1)

    if not secret:
        print >> stderr, "Must either specify -s {secret} or put secret into ~/.s3/key"
        exit(1)

    s3.init0(key_id=key_id, secret=secret)

    segment = 0
    while True:
        block = read_fully(stdin, size)
        if not block:
            break

        object = prefix + '.%03d' % segment

        s3.put_data(bucket, object, block)
        print object, len(block)

        segment += 1
コード例 #4
0
def cxp_to_s3(guid,
              storageId,
              host=DEFAULT_HOST,
              bucket=DEFAULT_BUCKET,
              kfile=DEFAULT_KEYFILE,
              amazon_user_token=None,
              amazon_product_token=None):
    global status

    if 0:
        params = cxp.params.copy()

        params['host'] = host

        params['documentGuid'] = guid
        params['storageId'] = storageId

        if not status:
            status = mtom.status('CXP get')

        try:
            cxp.get(params, status).cxp(dict(elements=[dict(guid=guid)]))
        except socket.error:
            return CXP_TEMP_ERR
        except:
            from traceback import print_exc
            print_exc(file=stderr)
            return CXP_PERM_ERR
    else:
        params = {'host': host, 'documentGuid': guid, 'storageId': storageId}

    try:
        inp = popen([
            ARCHIVE_CMD + [
                '--directory',
                '%s/%s' % (REPOSITORY, storageId),
                '%s' % guid,
                '%s.properties' % guid
            ], COMPRESS_CMD, ENCRYPT_CMD + [kfile]
        ])

        i = 0

        while True:
            b = read_fully(inp, SEGMENT_SIZE)

            if not b:
                break

            params['i'] = i

            put_data(bucket,
                     OBJECT_FORMAT % params,
                     b,
                     user_token=amazon_user_token,
                     product_token=amazon_product_token)

            i += 1
    except:
        from traceback import print_exc
        print_exc(file=stderr)
        return CXP_PERM_ERR

    #clean(guid)

    return CXP_OK