25 lines
685 B
Python
25 lines
685 B
Python
import os
|
|
|
|
class DiscObjectStore:
|
|
"""DiscObjectStore ist ein Mapping Objekt, welches ein Verzeichnis im Dateisystem als Speicher nutzt und somit persistent zwischen Programmstarts arbeitet"""
|
|
def __init__(self,path = "./objects"):
|
|
self._path = path
|
|
self.check()
|
|
|
|
def check(self):
|
|
if not os.path.exists( self._path ):
|
|
os.makedirs( self._path )
|
|
|
|
def __contains__(self, name):
|
|
return os.path.exists( "%s/%s" % (self._path, name))
|
|
|
|
def __getitem__(self, name):
|
|
f = open("%s/%s" % (self._path, name), "rb")
|
|
v = f.read()
|
|
f.close()
|
|
return v
|
|
|
|
def __setitem__(self, name, value):
|
|
f = open("%s/%s" % (self._path, name), "wb")
|
|
v = f.write(value)
|
|
f.close() |