class TagComponent(Component): tribler_should_stop_on_component_error = False community: TagCommunity = None tags_db: TagDatabase = None _ipv8_component: Ipv8Component = None async def run(self): await super().run() self._ipv8_component = await self.require_component(Ipv8Component) key_component = await self.require_component(KeyComponent) db_path = self.session.config.state_dir / STATEDIR_DB_DIR / "tags.db" if self.session.config.gui_test_mode: db_path = ":memory:" self.tags_db = TagDatabase(str(db_path)) self.community = TagCommunity(self._ipv8_component.peer, self._ipv8_component.ipv8.endpoint, self._ipv8_component.ipv8.network, db=self.tags_db, tags_key=key_component.secondary_key) self._ipv8_component.initialise_community_by_default(self.community) async def shutdown(self): await super().shutdown() if self._ipv8_component and self.community: await self._ipv8_component.unload_community(self.community) if self.tags_db: self.tags_db.shutdown()
class TagComponent(Component): tribler_should_stop_on_component_error = False community: TagCommunity = None tags_db: TagDatabase = None rules_processor: TagRulesProcessor = None _ipv8_component: Ipv8Component = None async def run(self): await super().run() self._ipv8_component = await self.require_component(Ipv8Component) key_component = await self.require_component(KeyComponent) mds_component = await self.require_component(metadata_store_component.MetadataStoreComponent) db_path = self.session.config.state_dir / STATEDIR_DB_DIR / "tags.db" if self.session.config.gui_test_mode: db_path = ":memory:" self.tags_db = TagDatabase(str(db_path), create_tables=True) self.community = TagCommunity( self._ipv8_component.peer, self._ipv8_component.ipv8.endpoint, self._ipv8_component.ipv8.network, db=self.tags_db, tags_key=key_component.secondary_key ) self.rules_processor = TagRulesProcessor( notifier=self.session.notifier, db=self.tags_db, mds=mds_component.mds, ) self.rules_processor.start() self._ipv8_component.initialise_community_by_default(self.community) if self.session.config.gui_test_mode: generate_test_channels(mds_component.mds, self.tags_db) async def shutdown(self): await super().shutdown() if self._ipv8_component and self.community: await self._ipv8_component.unload_community(self.community) if self.tags_db: self.tags_db.shutdown()
def upgrade_pony_db_13to14(self): mds_path = self.state_dir / STATEDIR_DB_DIR / 'metadata.db' tagdb_path = self.state_dir / STATEDIR_DB_DIR / 'tags.db' mds = MetadataStore(mds_path, self.channels_dir, self.trustchain_keypair, disable_sync=True, check_tables=False, db_version=13) if mds_path.exists() else None tag_db = TagDatabase( str(tagdb_path), create_tables=False, check_tables=False) if tagdb_path.exists() else None self.do_upgrade_pony_db_13to14(mds, tag_db) if mds: mds.shutdown() if tag_db: tag_db.shutdown()
def tags_db(): db = TagDatabase() yield db db.shutdown()