def server_fixtures(self, version, files): server_objs = BlobDB(self.server_objects_path) index_path = path.join(self.server_versions_path, str(version)) with open(index_path, "wb") as index_f: for file_path, file_data in files.iteritems(): index_f.write('"%s" %10d "%s"\n' % (sha1hex(file_data), len(file_data), file_path)) with server_objs.write_file(sha1hex(file_data)) as data_f: data_f.write(file_data)
def init_server(self, version_trees): os.mkdir(self.tmp_path + "/versions") os.mkdir(self.tmp_path + "/objects") objects = BlobDB(self.tmp_path + "/objects") for v, file_tree in version_trees.iteritems(): with open(self.tmp_path + "/versions/%d" % v, "wb") as ver_f: for i, data in file_tree.iteritems(): ver_f.write('"%s" %10d "%s"\n' % (i.checksum, i.size, i.path)) with objects.write_file(i.checksum) as data_f: data_f.write(data)
def test_backup(self): test_backup = BlobDB(self.tmpdir) backup_the_files(test_backup) self.assertEqual(set(os.listdir(self.tmpdir)), set([sha['f1'][:2], sha['f2'][:2], sha['f3'][:2]])) self.assertEqual(os.listdir(path.join(self.tmpdir, sha['f1'][:2])), [sha['f1'][2:]]) with open(path.join(self.tmpdir, sha['f1'][:2], sha['f1'][2:]), 'rb') as f: self.assertEqual(f.read(), 'file one') self.assertEqual(os.listdir(path.join(self.tmpdir, sha['f2'][:2])), [sha['f2'][2:]]) with open(path.join(self.tmpdir, sha['f2'][:2], sha['f2'][2:]), 'rb') as f: self.assertEqual(f.read(), 'file two') self.assertEqual(os.listdir(path.join(self.tmpdir, sha['f3'][:2])), [sha['f3'][2:]]) with open(path.join(self.tmpdir, sha['f3'][:2], sha['f3'][2:]), 'rb') as f: self.assertEqual(f.read(), 'file three')