def getPackageManager(logger=None): """Return a tuple with the package manager printable name string, the mini implementation class and the sink base class, for the preferred package manager available in the system. The only parameter accepted by this function is a logger instance, that can be ommited (or None) if the user don't wants logs. """ try: from otopi import minidnf minidnf.MiniDNF() if logger is not None: logger.debug('Using DNF as package manager') return 'DNF', minidnf.MiniDNF, minidnf.MiniDNFSinkBase except (ImportError, RuntimeError): try: from otopi import miniyum # yum does not raises validation exceptions in constructor, # then its not worth instantiating it to test. if logger is not None: logger.debug('Using Yum as package manager') return 'Yum', miniyum.MiniYum, miniyum.MiniYumSinkBase except ImportError: raise RuntimeError( _( 'No supported package manager found in your system' ) )
def _getMiniDNF( self, disabledPlugins=(), ): from otopi import minidnf class _MyMiniDNFSink(minidnf.MiniDNFSinkBase): """minidnf interaction.""" def _touch(self): self._last = time.time() def __init__(self, parent): super(_MyMiniDNFSink, self).__init__() self._parent = parent self._touch() def verbose(self, msg): super(_MyMiniDNFSink, self).verbose(msg) self._parent.logger.debug('DNF %s' % msg) def info(self, msg): super(_MyMiniDNFSink, self).info(msg) self._parent.logger.info('DNF %s' % msg) self._touch() def error(self, msg): super(_MyMiniDNFSink, self).error(msg) self._parent.logger.error('DNF %s' % msg) self._touch() def keepAlive(self, msg): super(_MyMiniDNFSink, self).keepAlive(msg) if time.time() - self._last >= self._parent.environment[ constants.PackEnv.KEEP_ALIVE_INTERVAL ]: self.info(msg) def askForGPGKeyImport(self, userid, hexkeyid): return self._parent.dialog.confirm( constants.Confirms.GPG_KEY, _( 'Confirm use of GPG Key ' 'userid={userid} hexkeyid={hexkeyid}' ).format( userid=userid, hexkeyid=hexkeyid, ) ) def reexec(self): super(_MyMiniDNFSink, self).reexec() self._parent.context.notify(self._parent.context.NOTIFY_REEXEC) return minidnf.MiniDNF( sink=_MyMiniDNFSink(parent=self), disabledPlugins=disabledPlugins, )