ds_store package¶
- class ds_store.DSStore(store)¶
Bases:
objectPython interface to a
.DS_Storefile. Works by manipulating the file on the disk—so this code will work with.DS_Storefiles for.very large directories.
A
DSStoreobject can be used as if it was a mapping, e.g.:d['foobar.dat']['Iloc']
will fetch the “Iloc” record for “foobar.dat”, or raise
KeyErrorif there is no such record. If used in this manner, theDSStoreobject will return (type, value) tuples, unless the type is “blob” and the module knows how to decode it.Currently, we know how to decode “Iloc”, “bwsp”, “lsvp”, “lsvP” and “icvp” blobs. “Iloc” decodes to an (x, y) tuple, while the others are all decoded using
biplistorplistlibdepending on Python version.Assignment also works, e.g.:
d['foobar.dat']['note'] = ('ustr', u'Hello World!')
as does deletion with
del:del d['foobar.dat']['note']
This is usually going to be the most convenient interface, though occasionally (for instance when creating a new
.DS_Storefile) you may wish to drop down to usingDSStoreEntryobjects directly.- close()¶
Flush dirty data and close the underlying file.
- delete(filename, code)¶
Delete an item, identified by
filenameandcodefrom the B-Tree.
- find(filename, code=None)¶
Returns a generator that will iterate over matching entries in the B-Tree.
- flush()¶
Flush any dirty data back to the file.
- insert(entry)¶
Insert
entry(which should be aDSStoreEntry) into the B-Tree.
- classmethod open(file_or_name, mode='r+', initial_entries=None)¶
Open a
.DS_Storefile; pass either a Python file object, or a filename in thefile_or_nameargument and a file access mode in themodeargument.If you are creating a new file using the “w” or “w+” modes, you may also specify a list of entries with which to initialise the file.
- class ds_store.DSStoreEntry(filename, code, typecode, value=None)¶
Bases:
objectHolds the data from an entry in a
.DS_Storefile. Note that this is not meant to represent the entry itself—i.e. if you change the type or value, your changes will not be reflected in the underlying file.If you want to make a change, you should either use the
DSStoreobject’sDSStore.insert()method (which will replace a key if it already exists), or the mapping access mode forDSStore(often simpler anyway).- byte_length()¶
Compute the length of this entry, in bytes.
- classmethod read(block)¶
Read a
.DS_Storeentry from the containing Block.
- write(block, insert=False)¶
Write this entry to the specified Block.