2007-05-30 23:48:36 +00:00
|
|
|
#!/usr/bin/python2.4
|
|
|
|
#
|
|
|
|
|
|
|
|
"""Example 1 in Python
|
|
|
|
"""
|
|
|
|
|
2007-06-11 21:36:57 +00:00
|
|
|
import stasis
|
2007-05-30 23:48:36 +00:00
|
|
|
import sys
|
|
|
|
import array
|
|
|
|
|
|
|
|
def runit(argv):
|
|
|
|
print "init"
|
2007-06-11 21:36:57 +00:00
|
|
|
stasis.Tinit()
|
2007-05-30 23:48:36 +00:00
|
|
|
|
|
|
|
# First transaction, for writing
|
|
|
|
print "begin & alloc"
|
2007-06-11 21:36:57 +00:00
|
|
|
xid = stasis.Tbegin();
|
|
|
|
record_id = stasis.Talloc(xid, 4);
|
2007-05-30 23:48:36 +00:00
|
|
|
|
|
|
|
print "update"
|
|
|
|
write_data = array.array('l', (42,))
|
|
|
|
data_out = write_data.tostring()
|
|
|
|
assert len(data_out) == 4
|
|
|
|
|
2007-06-11 21:36:57 +00:00
|
|
|
stasis.TupdateStr(xid, record_id, data_out, stasis.OPERATION_SET)
|
|
|
|
stasis.Tcommit(xid)
|
2007-05-30 23:48:36 +00:00
|
|
|
|
|
|
|
# Second transaction, for reading
|
|
|
|
print "read"
|
2007-06-11 21:36:57 +00:00
|
|
|
xid = stasis.Tbegin()
|
2007-05-30 23:48:36 +00:00
|
|
|
|
|
|
|
# Read from Stasis into memory for data_in
|
|
|
|
data_in = '1234'
|
2007-06-11 21:36:57 +00:00
|
|
|
stasis.TreadStr(xid, record_id, data_in)
|
2007-05-30 23:48:36 +00:00
|
|
|
read_data = array.array('l', data_in)
|
|
|
|
assert read_data[0] == 42
|
|
|
|
|
|
|
|
print "done"
|
2007-06-11 21:36:57 +00:00
|
|
|
stasis.Tdealloc(xid, record_id)
|
|
|
|
stasis.Tabort(xid)
|
2007-05-30 23:48:36 +00:00
|
|
|
|
2007-06-11 21:36:57 +00:00
|
|
|
stasis.Tdeinit()
|
2007-05-30 23:48:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
runit(sys.argv)
|