Document changes made since last edit of CHANGES.
[cvs2svn.git] / cvs2svn_lib / symbol_database.py
blob824f97b1a5b575f64cc3fd85746e7faef781dc8e
1 # (Be in -*- python -*- mode.)
3 # ====================================================================
4 # Copyright (c) 2000-2008 CollabNet. All rights reserved.
6 # This software is licensed as described in the file COPYING, which
7 # you should have received as part of this distribution. The terms
8 # are also available at http://subversion.tigris.org/license-1.html.
9 # If newer versions of this license are posted there, you may use a
10 # newer version instead, at your option.
12 # This software consists of voluntary contributions made by many
13 # individuals. For exact contribution history, see the revision
14 # history and logs, available at http://cvs2svn.tigris.org/.
15 # ====================================================================
17 """This module contains the SymbolDatabase class."""
20 import cPickle
22 from cvs2svn_lib import config
23 from cvs2svn_lib.artifact_manager import artifact_manager
26 class SymbolDatabase:
27 """Read-only access to symbol database.
29 This class allows iteration and lookups id -> symbol, where symbol
30 is a TypedSymbol instance. The whole database is read into memory
31 upon construction."""
33 def __init__(self):
34 # A map { id : TypedSymbol }
35 self._symbols = {}
37 f = open(artifact_manager.get_temp_file(config.SYMBOL_DB), 'rb')
38 symbols = cPickle.load(f)
39 f.close()
40 for symbol in symbols:
41 self._symbols[symbol.id] = symbol
43 def get_symbol(self, id):
44 """Return the symbol instance with id ID.
46 Raise KeyError if the symbol is not known."""
48 return self._symbols[id]
50 def __iter__(self):
51 """Iterate over the Symbol instances within this database."""
53 return self._symbols.itervalues()
55 def close(self):
56 self._symbols = None
59 def create_symbol_database(symbols):
60 """Create and fill a symbol database.
62 Record each symbol that is listed in SYMBOLS, which is an iterable
63 containing Trunk and TypedSymbol objects."""
65 f = open(artifact_manager.get_temp_file(config.SYMBOL_DB), 'wb')
66 cPickle.dump(symbols, f, -1)
67 f.close()