Ejemplo n.º 1
0
 def get_metadata(self, store_id, an_hash):
     """
     Get the FileDescription for the given hash.
     """
     try:
         with open(os.path.join(self.store_path, hash_to_dir(an_hash)), 'rb') as metadata:
             a_file_descr = DeserializeThriftMsg(FileDescription(), metadata.read())
             return a_file_descr
     except IOError as ioe:
         raise MetaDataStoreFileException('Failed to open FileDescription with hash %s' % an_hash, ioe)
Ejemplo n.º 2
0
 def write_metadata(self, store_id, an_hash, a_file_descr):
     """
     Write the FileDescription to this store.
     """
     data = SerializeThriftMsg(a_file_descr)
     path = os.path.join(self.store_path, hash_to_dir(an_hash))
     if not os.path.exists(os.path.dirname(path)):
         os.makedirs(os.path.dirname(path))
     with open(path, 'wb') as metadata:
         metadata.write(data)
     return a_file_descr
Ejemplo n.º 3
0
 def is_in_store(self, store_id, an_hash):
     """
     Check if the given file hash is in the store.
     """
     return is_existing_file(os.path.join(self.store_path, hash_to_dir(an_hash)))
Ejemplo n.º 4
0
 def test_hash_to_dir(self):
     dir = bld.hash_to_dir('002badb952000339cdcf1b61a3205b221766bf49')
     assert dir == '00/2badb952000339cdcf1b61a3205b221766bf49'