/usr/share/pyshared/carquinyol/metadatastore.py is in python-carquinyol-0.84 0.84.1-3build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | import os
from carquinyol import layoutmanager
from carquinyol import metadatareader
MAX_SIZE = 256
class MetadataStore(object):
def store(self, uid, metadata):
dir_path = layoutmanager.get_instance().get_entry_path(uid)
if not os.path.exists(dir_path):
os.makedirs(dir_path)
metadata_path = os.path.join(dir_path, 'metadata')
if not os.path.exists(metadata_path):
os.makedirs(metadata_path)
else:
for key in os.listdir(metadata_path):
os.remove(os.path.join(metadata_path, key))
metadata['uid'] = uid
for key, value in metadata.items():
# Hack to support activities that still pass properties named as for
# example title:text.
if ':' in key:
key = key.split(':', 1)[0]
f = open(os.path.join(metadata_path, key), 'w')
try:
if isinstance(value, unicode):
value = value.encode('utf-8')
elif not isinstance(value, basestring):
value = str(value)
f.write(value)
finally:
f.close()
def retrieve(self, uid, properties=None):
dir_path = layoutmanager.get_instance().get_entry_path(uid)
return metadatareader.retrieve(dir_path, properties)
def delete(self, uid):
dir_path = layoutmanager.get_instance().get_entry_path(uid)
metadata_path = os.path.join(dir_path, 'metadata')
for key in os.listdir(metadata_path):
os.remove(os.path.join(metadata_path, key))
os.rmdir(metadata_path)
def get_property(self, uid, key):
dir_path = layoutmanager.get_instance().get_entry_path(uid)
metadata_path = os.path.join(dir_path, 'metadata')
property_path = os.path.join(metadata_path, key)
if os.path.exists(property_path):
return open(property_path, 'r').read()
else:
return None
def set_property(self, uid, key, value):
dir_path = layoutmanager.get_instance().get_entry_path(uid)
metadata_path = os.path.join(dir_path, 'metadata')
property_path = os.path.join(metadata_path, key)
open(property_path, 'w').write(value)
|