Skip to content

Commit d1db768

Browse files
committed
updated usage
1 parent 581cd1f commit d1db768

File tree

1 file changed

+26
-12
lines changed

1 file changed

+26
-12
lines changed

README.md

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,10 @@ import bagit
7878
bag = bagit.Bag('/path/to/bag')
7979
```
8080

81-
### Update
81+
### Update Bag Metadata
8282

83-
If you have a bag that you would like to modify, just load the Bag, add or
84-
remove files manually, and/or update bag metadata, then call the save method.
85-
Calling save will regenerate the manifest, and update the respective tag file
86-
and tag manifests.
83+
You can change the metadata persisted to the bag-info.txt by using the `info`
84+
property on a `Bag`.
8785

8886
```python
8987

@@ -92,17 +90,33 @@ import bagit, shutil, os
9290
# load the bag
9391
bag = bagit.Bag('/path/to/bag')
9492

95-
# add a file to the bag
93+
# update bag info metadata
94+
bag.info['Internal-Sender-Description'] = 'Updated on 2014-06-28.'
95+
bag.info['Authors'] = ['John Kunze', 'Andy Boyko']
96+
bag.save()
97+
```
98+
99+
### Update Bag Manifests
100+
101+
By default `save` will not update manifests. This guards against a situation
102+
where a call to `save` to persist bag metadata accidentally regenerates
103+
manifests for an invalid bag. If you have modified the payload of a bag by
104+
adding, modifying or deleting files in the data directory, and wish to
105+
regenerate the manifests set the `manifests` parameter to True when calling
106+
`save`.
107+
108+
```python
109+
110+
import shutil, os
111+
112+
# add a file
96113
shutil.copyfile('newfile', '/path/to/bag/data/newfile')
97114

98-
# remove a file from the bag
115+
# remove a file
99116
os.remove('/path/to/bag/data/file')
100117

101-
# update bag info metadata
102-
bag.info['Internal-Sender-Description'] = 'Updated on 2014-06-28.'
103-
104-
# save the bag
105-
bag.save()
118+
# persist changes
119+
bag.save(manifests=True)
106120
```
107121

108122
The save method takes an optional processes parameter which will

0 commit comments

Comments
 (0)