-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathREADME.txt
185 lines (151 loc) · 4.91 KB
/
README.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
Usage Example:
Creating a Silo and creating an object inside it
>>> from recordsilo import Silo
>>>
>>> # store_directory will be created if it doesn't already exist
... s = Silo("removeme")
>>>
>>> # Get an object - this will be created if it doesn't already exist
... p = s.get_item("doi://10.2302/1232")
Adding files
>>> # Add some files - the content of the files will be the string values following the names.
... # The 'True' declaration flags that this file is metadata of some sort
>>> p.put_stream("mods.xml", "<modsColl..... />", True)
>>> p.put_stream("TXT.txt", "Textual item\n")
>>>
>>> # Add some binary files
... with open("/home/ben/important.rdf", "rb") as file:
... p.put_stream("important.rdf", file)
...
>>> with open("/home/ben/Desktop/GDO.pdf", "rb") as file:
... p.put_stream("GDO.pdf", file)
Versions
>>> p.versions
['1']
>>> p.files
['mods.xml', 'TXT.txt', 'important.rdf', 'GDO.pdf']
>>> p.currentversion
'1'
Adding a new version
>>> # Tries to autogen the next version. Uses the version cursor (p.currentversion) as a starting point
>>> p.increment_version()
'2'
>>> p.put_stream("ERR.err", "Something we don't want")
>>> p.put_stream("PDF", "Binary filehandle, something that supports .read()")
>>>
>>> p.del_stream("ERR.err")
>>> p.versions
['1', '2']
>>> p.files
['PDF']
>>> p.currentversion
'2'
The version cursor
>>> p.set_version_cursor("1")
True
>>>
>>> p.currentversion
'1'
>>> p.files
['mods.xml', 'TXT.txt', 'important.rdf', 'GDO.pdf']
>>> p.set_version_cursor("2")
True
>>> p.files
['PDF']
>>>
Cloning versions
>>> p.clone_version("1", "temp")
'temp'
>>> p.currentversion
'temp'
>>> p.put_stream("some.doc", "Binary filehandle, something that supports .read()")
>>> def print_mods(p):
... with p.get_stream("mods.xml") as mods:
... print mods.read()
...
>>> print_mods(p)
<AlternateMods/>
>>> p.files
['mods.xml', 'TXT.txt', 'important.rdf', 'GDO.pdf', 'some.doc']
>>> p.set_version_cursor("1")
True
>>> print_mods(p)
<modsColl..... />
>>> p.files
['mods.xml', 'TXT.txt', 'important.rdf', 'GDO.pdf']
Cloning versions - using symlinks for files in clone rather than do a hard copy
>>> p.clone_version_delta('temp', 'temp2')
'temp2'
Renaming versions
>>> p.versions
['1', '2', 'temp']
>>> p.rename_version("temp", "3")
'3'
>>> p.versions
['1', '2', '3']
The JSON manifest:
>>> p
{'files': {'1': ['mods.xml', 'TXT.txt', 'important.rdf', 'GDO.pdf'], '3': ['mods.xml', 'TXT.txt', 'important.rdf', 'GDO.pdf', 'some.doc'], '2': ['PDF']}, 'versions': ['1', '2', '3'], 'item_id': 'doi://10.2302/1232', 'currentversion': '3', 'metadata_files': {'1': ['mods.xml', 'TXT.txt', 'important.rdf', 'GDO.pdf'], '3': ['mods.xml', 'TXT.txt', 'important.rdf', 'GDO.pdf', 'some.doc'], '2': ['PDF']}, 'date': u'2010-02-02T16:51:45.890655', 'version_dates': {'1': '2010-02-02T16:51:45.890655', '3': '2010-02-02T16:51:45.890655', '2': '2010-02-02T16:51:47.634459'}}
Deleting
>>> p.set_version_cursor("2")
True
>>> p.files
['PDF']
>>> p.del_stream("PDF")
>>> p.files
[]
>>> p.del_version("2")
>>> p.set_version_cursor("2")
ERROR:RecordSilo:Version 2 does not exist
False
>>>
Cloning while versioning up
>>> p.increment_version(date=None, clone_previous_version=True)
'4'
>>> p.currentversion
'4'
>>> p.files
['mods.xml', 'TXT.txt', 'important.rdf', 'GDO.pdf', 'some.doc']
Cloning while versioning up, using symlinks for files in clone rather than do a hard copy
>>> p.increment_version_delta(date=None, clone_previous_version=True)
'5'
>>> p.currentversion
'5'
>>> p.files
['mods.xml', 'TXT.txt', 'important.rdf', 'GDO.pdf', 'some.doc']
Dates
>>> p.versions
['1', '3', '4']
>>> p.currentversion
'4'
>>> p.date
'2010-02-02T17:28:20.926703'
>>> p.set_version_cursor("1")
True
>>> p.date
u'2010-02-02T16:51:45.890655'
The JSON metadata
>>> p.metadata
{}
>>> p.metadata['dc:title'] = "Shakespearean sonnet"
>>> p.metadata
{'dc:title': 'Shakespearean sonnet'}
>>> p.sync()
Syncing to and reverting from disc
>>> # Metadata can be any data structure expressible in JSON
>>> p.metadata['listandDictdata'] = {'foo':['bar', 'baa', 'baaaaa'], 'sna':'fu'}
>>> p.metadata
{'listandDictdata': {'foo': ['bar', 'baa', 'baaaaa'], 'sna': 'fu'}, 'dc:title': 'Shakespearean sonnet'}
>>> The JSON manifest
>>> p
{'files': {'1': []}, 'versions': ['1'], 'date': '2010-02-02T17:39:50.282308', 'currentversion': '1', 'metadata_files': {'1': []}, 'item_id': '7', 'version_dates': {'1': '2010-02-02T17:39:50.282308'}, 'metadata': {'listandDictdata': {'foo': ['bar', 'baa', 'baaaaa'], 'sna': 'fu'}, 'dc:title': 'Shakespearean sonnet'}}
>>> # Sync the JSON manifest to disc
>>> p.sync()
>>> p.metadata['rubbish'] = "Whoops"
>>> p.metadata
{'listandDictdata': {'foo': ['bar', 'baa', 'baaaaa'], 'sna': 'fu'}, 'dc:title': 'Shakespearean sonnet', 'rubbish': 'Whoops'}
>>> # Reverting the manifest from the disc version.
>>> p.revert()
>>> p.metadata
{'listandDictdata': {'foo': ['bar', 'baa', 'baaaaa'], 'sna': 'fu'}, 'dc:title': 'Shakespearean sonnet'}
NB all stream writes cause a sync()