manatools / dnfdragora

dnfdragora is a dnf frontend based on libyui abstraction
GNU General Public License v3.0
133 stars 41 forks source link

dnfdragora fails to query state of dnf-makecache.timer #202

Closed mikhailnov closed 2 years ago

mikhailnov commented 2 years ago

dnfdragora git master with dnfdaemon git master and dnf 4.9.0

dnfdragora throws an error on launching:

dnfdaemon type error occured: TypeError: 'module' object is not callable

mikhailnov commented 2 years ago

I even can't understand how to debug where this error comes from

mikhailnov commented 2 years ago

Rolling back dnfdaemon to previously working version does not help, probably something has changed in python3-dnf ot python3-libdnf

mikhailnov commented 2 years ago

I've removed error handling from /usr/bin/dnfdragora and got a better understandable error:

Traceback (most recent call last):
  File "/usr/bin/dnfdragora", line 84, in <module>
    main_gui.handleevent()
  File "/usr/lib/python3.8/site-packages/dnfdragora/ui.py", line 1557, in handleevent
    rebuild_package_list = self._manageDnfDaemonEvent()
  File "/usr/lib/python3.8/site-packages/dnfdragora/ui.py", line 1914, in _manageDnfDaemonEvent
    if self._check_MD_cache_expired():
  File "/usr/lib/python3.8/site-packages/dnfdragora/ui.py", line 1790, in _check_MD_cache_expired
    ms = manatools.services()
TypeError: 'module' object is not callable
mikhailnov commented 2 years ago

in a pure python shell:

>>> import manatools.services
>>> ms = manatools.services()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'module' object is not callable

python is 3.8

mikhailnov commented 2 years ago

Don't know why this happend, I've workedaround it in dnfdragora:

diff --git a/dnfdragora/ui.py b/dnfdragora/ui.py
index c090f19..3d16471 100644
--- a/dnfdragora/ui.py
+++ b/dnfdragora/ui.py
@@ -12,6 +12,7 @@ Author:  Angelo Naselli <anaselli@linux.it>
 '''

 import os
+import subprocess
 import sys
 import platform
 import datetime
@@ -28,7 +29,6 @@ from gi.repository import GLib
 import dnfdaemon.client

 import manatools.ui.helpdialog as helpdialog
-import manatools.services
 import dnfdragora.basedragora
 import dnfdragora.compsicons as compsicons
 import dnfdragora.groupicons as groupicons
@@ -1787,8 +1787,8 @@ class mainGui(dnfdragora.basedragora.BaseDragora):
     def _check_MD_cache_expired(self):
       ''' Check metadata expired '''
       # check if MD cache management is disabled
-      ms = manatools.services()
-      if ms.GetUnitFileState('dnf-makecache.timer') == 'enabled' :
+      p = subprocess.run(['systemctl', '-q', 'is-active', 'dnf-makecache.timer'])
+      if p.returncode == 0:
           logger.debug("MakeCache enabled")
           return False
       if self.md_update_interval <= 0:

This is probably not worse than using manatools backend, that backend seems to caontain hackery.

timlau commented 2 years ago

Don't look like this is related to dnfdaemon, so you should properly raise the issue against

https://github.com/manatools/dnfdragora

If you want to debug the dnfdaemon back-end

you can start the daemon manually with

sudo /usr/share/dnfdaemon/dnfdaemon-system -d -v --notimeout

or use

make start-system

from a git checkout of the dnfdaemon code

anaselli commented 2 years ago

Have you installed python-manatools?

mikhailnov commented 2 years ago

@anaselli yes, see https://github.com/manatools/dnfdaemon/issues/54#issuecomment-939537613

mikhailnov commented 2 years ago

yes, please move this issue to dnfdragora, admins should be able to do this I think

anaselli commented 2 years ago

@mikhailnov i need to investigate better, but i have some time problems right now. Anyway the idea is to have python mantools to get some backend APIs. So the right place is to fix service module or its usage. Honestly we are trying to find a good way to access systemd unit/service API, but we had to hack upstream python modules in any projects we tried. The module we are using atm is a porting of what i did using perl long time ago. (perl-manatools) If you have any ideas for an upstream module we're open to any solutions :)

mikhailnov commented 2 years ago

https://github.com/manatools/python-manatools/blob/master/manatools/services.py looks like hackery, strange manipulations with finding "@" inside unit name, with parsing /etc/rc.d... I don't know where else it is used, maybe it makes sense, but for quering state of dnf-makecache.timer I would just call systemctl as I did in my hackery or query an equivalent dbus API. Parsing /etc/rc.d is probably an ettempt to inherit what drakxservices did? systemd sysv generator converts all sysvinit scripts into native unit files, such hackery looks useless (but of course I am not sure).

anaselli commented 2 years ago

Well in the very first time was written to manage sysvinit, so maybe something could be changed. But I'm almost sure unit list also missed some cases.

anaselli commented 2 years ago

https://github.com/manatools/python-manatools/blob/master/manatools/services.py looks like hackery, strange manipulations with finding "@" inside unit name

That should be to avoid adding to a future manaservice information of System units to manage user processes (such as @useri_id)

I added manager property to python-manatools so that now applications can access to systemd interface APIs, and fixed dnfdragora accordingly. Thanks for the report.

anaselli commented 2 years ago

Sorry the commit is this one