From e89aa0e9b903447a5295e1aa015e5daa181e290d Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Thu, 8 Dec 2011 16:35:31 +0400 Subject: [PATCH] fixed a bug with incremental packing an index, now subsequent packs are combined and not overwritten... added basic testing of IndexWithCache... Signed-off-by: Alex A. Naanou --- index.py | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/index.py b/index.py index f4c35456..d0c2eb8c 100755 --- a/index.py +++ b/index.py @@ -1,7 +1,7 @@ #======================================================================= __version__ = '''0.0.01''' -__sub_version__ = '''20111208162058''' +__sub_version__ = '''20111208163546''' __copyright__ = '''(c) Alex A. Naanou 2011''' @@ -291,7 +291,7 @@ def pack_file_index(path, ext='.json', pack_ext='.pack', keep_files=False, keep_ NOTE: if keep_files is True, keep_dirs option will be ignored. ''' - z = zipfile.ZipFile(os.path.join(path, 'index' + pack_ext), 'w', compression=zipfile.ZIP_DEFLATED) + z = zipfile.ZipFile(os.path.join(path, 'index' + pack_ext), 'a', compression=zipfile.ZIP_DEFLATED) for p, _, files in os.walk(path): for f in files: if f.endswith(ext): @@ -421,13 +421,14 @@ class IndexWithCache(Index): def cache_flush(self): ''' ''' - save_file_index(self._cahe, self._path) + save_file_index(self._cache, self._path) def cache_drop(self): ''' ''' del self._cache + #----------------------------------------------------------------------- if __name__ == '__main__': lst = list(list_files(config['ARCHIVE_ROOT'])) @@ -452,8 +453,8 @@ if __name__ == '__main__': root_index = save_file_index(index, os.path.join('test', 'index'), flat_index=False) - ##!!! this is not used in anything yet... - json.dump(root_index, file(os.path.join('test', 'index', 'file_index.json'), 'w')) +## ##!!! this is not used in anything yet... +## json.dump(root_index, file(os.path.join('test', 'index', 'file_index.json'), 'w')) pack_file_index(os.path.join('test', 'index'), keep_files=False) @@ -468,7 +469,17 @@ if __name__ == '__main__': print len(i) - print i[k] +## print i[k] + + ic = IndexWithCache(os.path.join('test', 'index')) + + print ic[k] + + ic['000000000000000000000000000000000'] = {} + + ic.cache_flush() + + pack_file_index(ic._path, keep_files=False) os.remove(os.path.join('test', 'index', 'index.pack'))