~ubuntu-branches/ubuntu/natty/pytables/natty-updates

« back to all changes in this revision

Viewing changes to examples/tutorial3-2.py

  • Committer: Bazaar Package Importer
  • Author(s): Alexandre Fayolle
  • Date: 2006-06-28 10:45:03 UTC
  • mfrom: (1.2.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 5.
  • Revision ID: james.westby@ubuntu.com-20060628104503-cc251q5o5j3e2k10
  * Fixed call to pyversions in debian/rules which failed on recent versions 
    of pyversions
  * Fixed clean rule in debian/rules which left the stamp files behind
  * Acknowledge NMU
  * Added Alexandre Fayolle to uploaders

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
"""A more complex example of do/undo capability with PyTables
 
2
 
 
3
Here, names has been assigned to the marks, and jumps are done between
 
4
marks.
 
5
 
 
6
"""
 
7
 
 
8
import tables
 
9
 
 
10
# Create an HDF5 file
 
11
fileh = tables.openFile('tutorial3-2.h5', 'w', title='Undo/Redo demo 2')
 
12
 
 
13
         #'-**-**-**-**-**-**- enable undo/redo log  -**-**-**-**-**-**-**-'
 
14
fileh.enableUndo()
 
15
 
 
16
# Start undoable operations
 
17
fileh.createArray('/', 'otherarray1', [3,4], 'Another array 1')
 
18
fileh.createGroup('/', 'agroup', 'Group 1')
 
19
# Create a 'first' mark
 
20
fileh.mark('first')
 
21
fileh.createArray('/agroup', 'otherarray2', [4,5], 'Another array 2')
 
22
fileh.createGroup('/agroup', 'agroup2', 'Group 2')
 
23
# Create a 'second' mark
 
24
fileh.mark('second')
 
25
fileh.createArray('/agroup/agroup2', 'otherarray3', [5,6], 'Another array 3')
 
26
# Create a 'third' mark
 
27
fileh.mark('third')
 
28
fileh.createArray('/', 'otherarray4', [6,7], 'Another array 4')
 
29
fileh.createArray('/agroup', 'otherarray5', [7,8], 'Another array 5')
 
30
 
 
31
# Now go to mark 'first'
 
32
fileh.goto('first')
 
33
assert '/otherarray1' in fileh.objects
 
34
assert '/agroup' in fileh.objects
 
35
assert '/agroup/agroup2' not in fileh.objects
 
36
assert '/agroup/otherarray2' not in fileh.objects
 
37
assert '/agroup/agroup2/otherarray3' not in fileh.objects
 
38
assert '/otherarray4' not in fileh.objects
 
39
assert '/agroup/otherarray5' not in fileh.objects
 
40
# Go to mark 'third'
 
41
fileh.goto('third')
 
42
assert '/otherarray1' in fileh.objects
 
43
assert '/agroup' in fileh.objects
 
44
assert '/agroup/agroup2' in fileh.objects
 
45
assert '/agroup/otherarray2' in fileh.objects
 
46
assert '/agroup/agroup2/otherarray3' in fileh.objects
 
47
assert '/otherarray4' not in fileh.objects
 
48
assert '/agroup/otherarray5' not in fileh.objects
 
49
# Now go to mark 'second'
 
50
fileh.goto('second')
 
51
assert '/otherarray1' in fileh.objects
 
52
assert '/agroup' in fileh.objects
 
53
assert '/agroup/agroup2' in fileh.objects
 
54
assert '/agroup/otherarray2' in fileh.objects
 
55
assert '/agroup/agroup2/otherarray3' not in fileh.objects
 
56
assert '/otherarray4' not in fileh.objects
 
57
assert '/agroup/otherarray5' not in fileh.objects
 
58
# Go to the end
 
59
fileh.goto(-1)
 
60
assert '/otherarray1' in fileh.objects
 
61
assert '/agroup' in fileh.objects
 
62
assert '/agroup/agroup2' in fileh.objects
 
63
assert '/agroup/otherarray2' in fileh.objects
 
64
assert '/agroup/agroup2/otherarray3' in fileh.objects
 
65
assert '/otherarray4' in fileh.objects
 
66
assert '/agroup/otherarray5' in fileh.objects
 
67
# Check that objects have come back to life in a sane state
 
68
assert fileh.root.otherarray1.read() == [3,4]
 
69
assert fileh.root.agroup.otherarray2.read() == [4,5]
 
70
assert fileh.root.agroup.agroup2.otherarray3.read() == [5,6]
 
71
assert fileh.root.otherarray4.read() == [6,7]
 
72
assert fileh.root.agroup.otherarray5.read() == [7,8]
 
73
 
 
74
 
 
75
         #'-**-**-**-**-**-**- disable undo/redo log  -**-**-**-**-**-**-**-'
 
76
fileh.disableUndo()
 
77
 
 
78
# Close the file
 
79
fileh.close()