Example #1
0
def main(argv):
    try:
        optv, argv = getopt.getopt(argv[1:], "h", ["help"])
    except getopt.GetoptError as e:
        print(e, file=sys.stderr)
        usage(sys.stderr)
        sys.exit(2)

    for opt, _ in optv:
        if opt in ("-h", "--help"):
            usage(sys.stdout)
            sys.exit(0)

    if len(argv) != 1:
        usage(sys.stderr)
        sys.exit(2)

    storurl = argv[0]

    stor = storageFromURL(storurl)
    defer(stor.close)

    def _(txn):
        print(ashex(txn.tid))

    zodbrestore(stor, asbinstream(sys.stdin), _)
Example #2
0
    def _():
        zdump = open("%s/1%s.zdump.raw.ok" % (tdata, zkind), 'rb')
        defer(zdump.close)

        stor = storageFromURL('%s/2.fs' % tmpd)
        defer(stor.close)

        zodbrestore(stor, zdump)
Example #3
0
def main2(argv):
    verbose = False

    try:
        optv, argv = getopt.getopt(argv[1:], "hv", ["help", "verbose"])
    except getopt.GetoptError as e:
        print(e, file=sys.stderr)
        usage(sys.stderr)
        sys.exit(2)

    for opt, _ in optv:
        if opt in ("-h", "--help"):
            usage(sys.stdout)
            sys.exit(0)
        if opt in ("-v", "--verbose"):
            verbose = True

    try:
        storurl1, storurl2 = argv[0:2]
    except ValueError:
        usage(sys.stderr)
        sys.exit(2)

    # parse tidmin..tidmax
    tidmin = tidmax = None
    if len(argv) > 2:
        try:
            tidmin, tidmax = parse_tidrange(argv[2])
        except TidRangeInvalid as e:
            print("E: invalid tidrange: %s" % e, file=sys.stderr)
            sys.exit(2)

    stor1 = storageFromURL(storurl1, read_only=True)
    defer(stor1.close)
    stor2 = storageFromURL(storurl2, read_only=True)
    defer(stor2.close)

    zcmp = storcmp(stor1, stor2, tidmin, tidmax, verbose)
    sys.exit(1 if zcmp else 0)
Example #4
0
def analyze(path, use_dbm, delta_fs, tidmin, tidmax):
    if delta_fs:
        fs = DeltaFileStorage(path, read_only=1)
    else:
        fs = storageFromURL(path, read_only=1)
    defer(fs.close)
    fsi = fs.iterator(tidmin, tidmax)
    report = Report(use_dbm, delta_fs)
    for txn in fsi:
        analyze_trans(report, txn)
    if use_dbm:
        shutil.rmtree(report.temp_dir)
    return report
Example #5
0
def main(argv):
    hashonly = False
    pretty = 'raw'
    prettyok = {'raw', 'zpickledis'}

    try:
        optv, argv = getopt.getopt(argv[1:], "h",
                                   ["help", "hashonly", "pretty="])
    except getopt.GetoptError as e:
        print(e, file=sys.stderr)
        usage(sys.stderr)
        sys.exit(2)

    for opt, arg in optv:
        if opt in ("-h", "--help"):
            usage(sys.stdout)
            sys.exit(0)
        if opt in ("--hashonly"):
            hashonly = True
        if opt in ("--pretty"):
            pretty = arg
            if pretty not in prettyok:
                print("E: unsupported pretty format: %s" % pretty,
                      file=sys.stderr)
                sys.exit(2)

    try:
        storurl = argv[0]
    except IndexError:
        usage(sys.stderr)
        sys.exit(2)

    # parse tidmin..tidmax
    tidmin = tidmax = None
    if len(argv) > 1:
        try:
            tidmin, tidmax = parse_tidrange(argv[1])
        except TidRangeInvalid as e:
            print("E: invalid tidrange: %s" % e, file=sys.stderr)
            sys.exit(2)

    stor = storageFromURL(storurl, read_only=True)
    defer(stor.close)

    zodbdump(stor, tidmin, tidmax, hashonly, pretty)
Example #6
0
def test_zodbcommit(zext):
    tmpd = mkdtemp('', 'zodbcommit.')
    defer(lambda: rmtree(tmpd))

    stor = storageFromURL('%s/2.fs' % tmpd)
    defer(stor.close)

    head = stor.lastTransaction()

    # commit some transactions via zodbcommit and verify if storage dump gives
    # what is expected.
    t1 = Transaction(z64, ' ', b'user name', b'description ...', zext(dumps({'a': 'b'}, _protocol)), [
        ObjectData(p64(1), b'data1', 'sha1', sha1(b'data1')),
        ObjectData(p64(2), b'data2', 'sha1', sha1(b'data2'))])

    t1.tid = zodbcommit(stor, head, t1)

    t2 = Transaction(z64, ' ', b'user2', b'desc2', b'', [
        ObjectDelete(p64(2))])

    t2.tid = zodbcommit(stor, t1.tid, t2)


    buf = BytesIO()
    zodbdump(stor, p64(u64(head)+1), None, out=buf)
    dumped = buf.getvalue()

    assert dumped == b''.join([_.zdump() for _ in (t1, t2)])

    # ObjectCopy. XXX zodbcommit handled ObjectCopy by actually copying data,
    # not referencing previous transaction via backpointer.
    t3 = Transaction(z64, ' ', b'user3', b'desc3', b'', [
        ObjectCopy(p64(1), t1.tid)])

    t3.tid = zodbcommit(stor, t2.tid, t3)

    data1_1, _, _ = stor.loadBefore(p64(1), p64(u64(t1.tid)+1))
    data1_3, _, _ = stor.loadBefore(p64(1), p64(u64(t3.tid)+1))
    assert data1_1 == data1_3
    assert data1_1 == b'data1'  # just in case
Example #7
0
def main(argv):
    try:
        optv, argv = getopt.getopt(argv[1:], "h", ["help"])
    except getopt.GetoptError as e:
        print(e, file=sys.stderr)
        usage(sys.stderr)
        sys.exit(2)

    for opt, _ in optv:
        if opt in ("-h", "--help"):
            usage(sys.stdout)
            sys.exit(0)

    if len(argv) != 2:
        usage(sys.stderr)
        sys.exit(2)

    storurl = argv[0]
    at = fromhex(argv[1])

    stor = storageFromURL(storurl)
    defer(stor.close)

    # artificial transaction header with tid=0 to request regular commit
    zin = b'txn 0000000000000000 " "\n'

    zin += sys.stdin.read()
    zin = BytesIO(zin)
    zr = zodbdump.DumpReader(zin)
    zr.lineno -= 1  # we prepended txn header
    txn = zr.readtxn()
    tail = zin.read()
    if tail:
        print('E: +%d: garbage after transaction' % zr.lineno, file=sys.stderr)
        sys.exit(1)

    tid = zodbcommit(stor, at, txn)
    print(ashex(tid))
Example #8
0
def main(argv):
    try:
        optv, argv = getopt.getopt(argv[1:], "h", ["help"])
    except getopt.GetoptError as e:
        print(e, file=sys.stderr)
        usage(sys.stderr)
        sys.exit(2)

    for opt, _ in optv:
        if opt in ("-h", "--help"):
            usage(sys.stdout)
            sys.exit(0)

    try:
        storurl = argv[0]
    except IndexError:
        usage(sys.stderr)
        sys.exit(2)

    stor = storageFromURL(storurl, read_only=True)
    defer(stor.close)

    zodbinfo(stor, argv[1:])