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."""
22 from cvs2svn_lib
import config
23 from cvs2svn_lib
.artifact_manager
import artifact_manager
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
34 # A map { id : TypedSymbol }
37 f
= open(artifact_manager
.get_temp_file(config
.SYMBOL_DB
), 'rb')
38 symbols
= cPickle
.load(f
)
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]
51 """Iterate over the Symbol instances within this database."""
53 return self
._symbols
.itervalues()
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)