aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Harring <ferringb@gmail.com>2012-10-13 17:49:44 -0700
committerBrian Harring <ferringb@google.com>2012-10-16 13:27:24 -0700
commit2919cf0d03b37050c6624d97547653d1fffa033d (patch)
tree76003db257539a345620e1fec369e92a3a69be4b /cvs2svn_lib/symbol_database.py
downloadgit-conversion-tools-2919cf0d03b37050c6624d97547653d1fffa033d.tar.gz
git-conversion-tools-2919cf0d03b37050c6624d97547653d1fffa033d.tar.bz2
git-conversion-tools-2919cf0d03b37050c6624d97547653d1fffa033d.zip
import of content;
note rcsparse has had my old http://cvs2svn.tigris.org/nonav/issues/showattachment.cgi/64/rcparse_redundant_work.patch patch applied.
Diffstat (limited to 'cvs2svn_lib/symbol_database.py')
-rw-r--r--cvs2svn_lib/symbol_database.py68
1 files changed, 68 insertions, 0 deletions
diff --git a/cvs2svn_lib/symbol_database.py b/cvs2svn_lib/symbol_database.py
new file mode 100644
index 0000000..824f97b
--- /dev/null
+++ b/cvs2svn_lib/symbol_database.py
@@ -0,0 +1,68 @@
+# (Be in -*- python -*- mode.)
+#
+# ====================================================================
+# Copyright (c) 2000-2008 CollabNet. All rights reserved.
+#
+# This software is licensed as described in the file COPYING, which
+# you should have received as part of this distribution. The terms
+# are also available at http://subversion.tigris.org/license-1.html.
+# If newer versions of this license are posted there, you may use a
+# newer version instead, at your option.
+#
+# This software consists of voluntary contributions made by many
+# individuals. For exact contribution history, see the revision
+# history and logs, available at http://cvs2svn.tigris.org/.
+# ====================================================================
+
+"""This module contains the SymbolDatabase class."""
+
+
+import cPickle
+
+from cvs2svn_lib import config
+from cvs2svn_lib.artifact_manager import artifact_manager
+
+
+class SymbolDatabase:
+ """Read-only access to symbol database.
+
+ This class allows iteration and lookups id -> symbol, where symbol
+ is a TypedSymbol instance. The whole database is read into memory
+ upon construction."""
+
+ def __init__(self):
+ # A map { id : TypedSymbol }
+ self._symbols = {}
+
+ f = open(artifact_manager.get_temp_file(config.SYMBOL_DB), 'rb')
+ symbols = cPickle.load(f)
+ f.close()
+ for symbol in symbols:
+ self._symbols[symbol.id] = symbol
+
+ def get_symbol(self, id):
+ """Return the symbol instance with id ID.
+
+ Raise KeyError if the symbol is not known."""
+
+ return self._symbols[id]
+
+ def __iter__(self):
+ """Iterate over the Symbol instances within this database."""
+
+ return self._symbols.itervalues()
+
+ def close(self):
+ self._symbols = None
+
+
+def create_symbol_database(symbols):
+ """Create and fill a symbol database.
+
+ Record each symbol that is listed in SYMBOLS, which is an iterable
+ containing Trunk and TypedSymbol objects."""
+
+ f = open(artifact_manager.get_temp_file(config.SYMBOL_DB), 'wb')
+ cPickle.dump(symbols, f, -1)
+ f.close()
+