How to use the bw2io.errors.InvalidPackage function in bw2io

To help you get started, we’ve selected a few bw2io examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github LCA-ActivityBrowser / activity-browser / activity_browser / app / ui / wizards / db_import_wizard.py View on Github external
def run_local_import(self):
        try:
            import_signals.db_progress.emit(0, 0)
            result = ABPackage.import_file(self.archive_path)
            if not import_signals.cancel_sentinel:
                db = next(iter(result))
                if db.name != self.db_name:
                    db.rename(self.db_name)
                import_signals.db_progress.emit(1, 1)
                import_signals.finished.emit()
            else:
                self.delete_canceled_db()
        except InvalidPackage as e:
            self.delete_canceled_db()
            import_signals.import_failure.emit(
                ("Missing databases", str(e))
            )
        except ImportCanceledError:
            self.delete_canceled_db()
        except InvalidExchange:
            self.delete_canceled_db()
            import_signals.import_failure.emit(
                ("Missing exchanges", "The import has failed, likely due missing exchanges.")
            )
        except UnknownObject as e:
            self.delete_canceled_db()
            import_signals.import_failure.emit(
                ("Unknown object", str(e))
            )
github LCA-ActivityBrowser / activity-browser / activity_browser / app / ui / wizards / db_import_wizard.py View on Github external
def evaluate_metadata(cls, metadata: dict):
        """ Take the given metadata dictionary and test it against realities
        of the current brightway project.
        """
        if "depends" in metadata:
            missing = set(metadata["depends"]).difference(bw.databases)
            if missing:
                raise InvalidPackage("Package data links to database names that do not exist: {}".format(missing))