brightway2 / brightway2 /

from serialization import SerializedDict, PickledDict

class Mapping(PickledDict):
    """A dictionary that maps object ids, like ``("Ecoinvent 2.2", 42)``, to integers. Needed because parameter arrays have integer ``row`` and ``column`` fields.

    File data is saved in ``mapping.pickle``.

    This dictionary does not support setting items directly; instead, use the ``add`` method to add multiple keys."""
    _filename = "mapping.pickle"

    def add(self, keys):
        """Add a set of keys. These keys can already be in the mapping; only new keys will be added.

            *keys* (list): The keys to add.

        index = max(
        for i, key in enumerate(keys):
            if key not in
      [key] = index + i + 1

    def delete(self, keys):
        """Delete a set of keys.

            *keys* (list): The keys to delete.

        for key in keys:

    def __setitem__(self, key, value):
        raise NotImplemented

    def __unicode__(self):
        return u"Mapping from databases and methods to parameter indices."

    def __len__(self):
        return len(

class Databases(SerializedDict):
    """A dictionary for database metadata. This class includes methods to manage database versions. File data is saved in ``databases.json``."""
    _filename = "databases.json"

    def increment_version(self, database):
        """Increment the ``database`` version. Returns the new version."""[database]["version"] += 1

    def version(self, database):
        """Return the ``database`` version"""

    def __unicode__(self):
        return u"Brightway2 databases metadata with %i objects" % len(

class Methods(SerializedDict):
    """A dictionary for method metadata. File data is saved in ``methods.json``."""
    _filename = "methods.json"

    def pack(self, data):
        """Transform the dictionary to a list because JSON can't handle lists as keys"""
        return [(k, v) for k, v in data.iteritems()]

    def unpack(self, data):
        """Transform data back to a dictionary"""
        return dict([(tuple(x[0]), x[1]) for x in data])

    def __unicode__(self):
        return u"Brightway2 methods metadata with %i objects" % len(

mapping = Mapping()
databases = Databases()
methods = Methods()

def reset_meta():
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.