Commit 21b2eeb0 authored by Sofia Papagiannaki's avatar Sofia Papagiannaki
Browse files

Refs #447

parent c0aa2174
...@@ -133,18 +133,19 @@ class BackEnd: ...@@ -133,18 +133,19 @@ class BackEnd:
limit = 10000 limit = 10000
return objects[start:start + limit] return objects[start:start + limit]
def get_object_meta(self, account, container, name, keys='*'): def get_object_meta(self, account, container, name, keys=None):
dir = os.path.join(self.basepath, account, container) dir = os.path.join(self.basepath, account, container)
if not os.path.exists(dir): if not os.path.exists(dir):
raise NameError('Container does not exist') raise NameError('Container does not exist')
else: link = self.__get_object_linkinfo(os.path.join(account, container, name))
os.chdir(dir) c = self.con.execute('select name, value from metadata where object_id = ''?''', (link,))
location = self.__get_object_linkinfo('/'.join([account, container, name])) l = c.fetchall()
location = '.'.join([location, 'meta']) if keys:
f = open(location, 'r') l = [elem for elem in l if elem[0] in keys]
data = json.load(f) meta = {}
f.close() for e in l:
return data meta[e[0]] = e[1]
return meta
def get_object_data(self, account, container, name, offset=0, length=-1): def get_object_data(self, account, container, name, offset=0, length=-1):
dir = os.path.join(self.basepath, account, container) dir = os.path.join(self.basepath, account, container)
...@@ -214,17 +215,11 @@ class BackEnd: ...@@ -214,17 +215,11 @@ class BackEnd:
self.__delete_data(location, account, container) self.__delete_data(location, account, container)
return return
def __store_metadata(self, location, account, container, meta): def __store_metadata(self, ref, account, container, meta):
dir = os.path.join(self.basepath, account, container) for k in meta.keys():
if not os.path.exists(dir): self.con.execute('insert or replace into metadata(object_id, name, value) values (?, ?, ?)', (ref, k, meta[k],))
raise NameError('Container does not exist') self.con.commit()
else: return
os.chdir(dir)
location = '.'.join([location, 'meta'])
f = open(location, 'w')
data = json.dumps(meta)
f.write(data)
f.close()
def __store_data(self, location, account, container, data): def __store_data(self, location, account, container, data):
dir = os.path.join(self.basepath, account, container) dir = os.path.join(self.basepath, account, container)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment