class GraphBuilder(object):
    _PARTITION_NAMES = {
        PT_SYSTEM: 'system',
        PT_VENDOR: 'vendor',
    }

    _LIB_DIRS = {
        ELF.ELFCLASS32: 'lib',
        ELF.ELFCLASS64: 'lib64',
    }

    def __init__(self):
        self.graph = ELFLinker()

    def add_lib(self,
                partition,
                klass,
                name,
                dt_needed=[],
                exported_symbols=set(),
                imported_symbols=set(),
                extra_dir=None):
        """Create and add a shared library to ELFLinker."""

        lib_dir = os.path.join('/', self._PARTITION_NAMES[partition],
                               self._LIB_DIRS[klass])
        if extra_dir:
            lib_dir = os.path.join(lib_dir, extra_dir)

        path = os.path.join(lib_dir, name + '.so')

        elf = ELF(klass,
                  ELF.ELFDATA2LSB,
                  dt_needed=dt_needed,
                  exported_symbols=exported_symbols,
                  imported_symbols=imported_symbols)

        node = self.graph.add(partition, path, elf)
        setattr(self, name + '_' + elf.elf_class_name, node)
        return node

    def add_multilib(self,
                     partition,
                     name,
                     dt_needed=[],
                     exported_symbols=set(),
                     imported_symbols=set(),
                     extra_dir=None):
        """Add 32-bit / 64-bit shared libraries to ELFLinker."""
        return (self.add_lib(partition, ELF.ELFCLASS32, name, dt_needed,
                             exported_symbols, imported_symbols, extra_dir),
                self.add_lib(partition, ELF.ELFCLASS64, name, dt_needed,
                             exported_symbols, imported_symbols, extra_dir))

    def resolve(self):
        self.graph.resolve_deps()
class GraphBuilder(object):
    _PARTITION_NAMES = {
        PT_SYSTEM: 'system',
        PT_VENDOR: 'vendor',
    }

    _LIB_DIRS = {
        ELF.ELFCLASS32: 'lib',
        ELF.ELFCLASS64: 'lib64',
    }

    def __init__(self):
        self.graph = ELFLinker()

    def add_lib(self, partition, klass, name, dt_needed, exported_symbols,
                imported_symbols):
        """Create and add a shared library to ELFLinker."""

        elf = ELF(klass,
                  ELF.ELFDATA2LSB,
                  dt_needed=dt_needed,
                  exported_symbols=exported_symbols,
                  imported_symbols=imported_symbols)
        setattr(self, 'elf' + elf.elf_class_name + '_' + name, elf)

        path = os.path.join('/', self._PARTITION_NAMES[partition],
                            self._LIB_DIRS[klass], name + '.so')
        self.graph.add(partition, path, elf)

    def add_multilib(self, partition, name, dt_needed, exported_symbols,
                     imported_symbols):
        """Add 32-bit / 64-bit shared libraries to ELFLinker."""

        for klass in (ELF.ELFCLASS32, ELF.ELFCLASS64):
            self.add_lib(partition, klass, name, dt_needed, exported_symbols,
                         imported_symbols)

    def resolve(self):
        self.graph.resolve_deps()