JasonMillward / Autorippr

Rip discs automatically using a blend of Python, MakeMKV and HandBrake
MIT License
241 stars 60 forks source link

Error loading notification class Pushover #126

Open knoer opened 7 years ago

knoer commented 7 years ago

Hi, I only got around to try Autorippr today, and I must say I am impressed.. I installed the lot using the script supplied, and (almost) all is good.

Running of an old Asus eeeBox with an Atom processor running Lubuntu 14.04 Output from Uname: Linux kasper-EB1501 3.19.0-28-generic #30~14.04.1-Ubuntu SMP Tue Sep 1 09:32:55 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux Python version is 2.7.6 Autorippr version 1.7.0

I registered on pushover to make use of these notifications (and/or to avoid numerous emails to my self when ripping), but have some issues getting this to work..

So basically my settings.cfg are now:

# Enable pushover notifications enable: True user_key: ##myuserkey## app_key: ##myregisteredappkey##

But, when ripping a disc, using --debug, I get the following error:

2016-11-03 22:30:43 - Notification - ERROR - Error loading notification class: pushover

Looking at classes/pushover.py, it seems to be logging something somewhere - but I have not been able to locate the logfile.. Am I missing something?

For now, I'm using pushover's EmailGateway, sending notifications to myself via my gmail (as suggested in the initial settings) and it works - but it would be nice to have this working as intended..

JasonMillward commented 7 years ago

The install script is missing sudo pip install pushover which is why it can't find the pushover class

knoer commented 7 years ago

Hey - thanks for the quick reply.

That would make perfect sense - I will try and install the missing package, when I get near my test machine - which, unfortunately, wont be today.. I will report back in a day or two.

Again, thanks for making this available..

knoer commented 7 years ago

So, I got around to test a little more on this during the weekend. Installed pushover through pip, as suggested, but it still throws the same error.

When I installed using sudo pip install pushover there was a mention of incorrect permissions on ~/.cache/pushover/
So I did a very generous chmod on both ~/Autorippr/ and ~/.cache/pushover/ - though it did not make a difference..

I'm being prompted to update to 16.10 - which I'll gladly do - but am holding off for now.. (In the end, when/if I get this sorted, I will do a clean install on a more powerful machine)

Are there anyone else using Pushover for notifications? Any suggestions to how I can pull more information out regarding this error? Does anyone have an idea/code snippet to test pushover on its own, so it can be debugged without having to feed Autorippr with movies? ;-)

I'm happy to provide any and all information I can to assist..

JasonMillward commented 7 years ago

Can you try sudo pip install python-pushover as well please?

knoer commented 7 years ago

Sure.. I just managed to install it remotely.

I started a rip this morning, which is has been compressing for half an hour or so (it takes a while on an Atom, in case anyone wonders ;-) ) I will report back when the current job finishes..

Thanks.

knoer commented 7 years ago

Unfortunately, this was not the solution to my problem. The job that finished this afternoon also "only" sent me a notification via gmail to pushovers email gateway.

I did some rough debugging - inserting log "info" entries at various points in the code. What I got to was that it seems the code enters the try in this function in notification.py (I inserted a debug line adding info messages in the log before each method_class in the following snippet) but it never got to the second line starting with method_class

 def _send(self, status):
        for method in self.config['methods']:
            if bool(self.config['methods'][method]['enable']):
                try:
                    method_class = self.import_from('classes.{}'.format(
                        method), method.capitalize(), self.config['methods'][method])
                    method_class.send_notification(status)
                    del method_class
                except ImportError:
                    self.log.error(
                        "Error loading notification class: {}".format(method))

Just now I got to wonder if it has something to do with me having both smtp & pushover activated in settings.cfg? Just in case, I have just now set smtp to False in settings.cfg, just to be able to rule this out... I am currently running another compression job, but the next disc is in the drive, so I will return with an update, when it's done.

knoer commented 7 years ago

tl;dr installing missing package chump and removing a capitalization in notification.py fixed this issue

One more (long) update on this:

Setting smtp to false in settings.cfg did not make a difference - I do still not get messages directly from pushover.

Yesterday, I created a virtual machine (Lubuntu 16.10) to test this on a clean install - and installed Autorippr with the updated install script (including pip install pushover) but even this install behaves the same way as my first.

Adding the previously mentioned self.log.info entries in notfification.py as so:

    def _send(self, status):
        for method in self.config['methods']:
            if bool(self.config['methods'][method]['enable']):
                self.log.info("loading notification class before try")
                try:
                    self.log.info("loading notification class part1")
                    method_class = self.import_from('classes.{}'.format(
                        method), method.capitalize(), self.config['methods'][method])
                    self.log.info("loading notification class part2")
                    method_class.send_notification(status)
                    del method_class
                except ImportError:
                    self.log.error(
                        "Error loading notification class: {}".format(method))

Gives the following log output:

2016-11-08 10:47:31 - Notification - INFO - loading notification class before try
2016-11-08 10:47:31 - Notification - INFO - loading notification class part1
2016-11-08 10:47:31 - Notification - ERROR - Error loading notification class: pushover

Assuming the error originated from this line: method_class = self.import_from('classes.{}'.format(method), method.capitalize(), self.config['methods'][method]) I started experimenting with pdb, setting a pdb.set_trace() before the above line

kn@kn-virtual-machine:~/Autorippr$ python autorippr.py --rip --debug
2016-11-08 11:49:15 - Rip - DEBUG - Ripping initialised
2016-11-08 11:49:15 - Notification - INFO - trying method pushover
2016-11-08 11:49:15 - Notification - INFO - loading notification class part1
> /home/kn/Autorippr/classes/notification.py(38)_send()
-> method_class = self.import_from('classes.{}'.format(method), method.capitalize(), self.config['methods'][method])
(Pdb) p method
'pushover'
(Pdb) n
ImportError: 'No module named chump'
> /home/kn/Autorippr/classes/notification.py(38)_send()
-> method_class = self.import_from('classes.{}'.format(method), method.capitalize(), self.config['methods'][method])

Now, suddenly, it is complaining about chump?

kn@kn-virtual-machine:~/Autorippr$ python autorippr.py --rip --debug
2016-11-08 11:54:04 - Rip - DEBUG - Ripping initialised
2016-11-08 11:54:04 - Notification - INFO - trying method pushover
2016-11-08 11:54:04 - Notification - INFO - loading notification class part1
Traceback (most recent call last):
  File "autorippr.py", line 434, in <module>
    rip(config)
  File "autorippr.py", line 134, in rip
    notify.rip_fail("title")
  File "/home/kn/Autorippr/classes/notification.py", line 54, in rip_fail
    self._send(status)
  File "/home/kn/Autorippr/classes/notification.py", line 38, in _send
    method_class = self.import_from('classes.{}'.format(method), method.capitalize(), self.config['methods'][method])
  File "/home/kn/Autorippr/classes/notification.py", line 28, in import_from
    class_ = getattr(module, name)
AttributeError: 'module' object has no attribute 'Pushover'

(I did a change to notify.rip_fail() allowing me to test without passing dbvideo as a paramter)

Having thought about the meaning of method.capitalize() in the line that started it all, I (experimentally) removed .capitalize() to avoid capitalization, yielding: method_class = self.import_from('classes.{}'.format(method), method, self.config['methods'][method])

Then, I tried again

kn@kn-virtual-machine:~/Autorippr$ python autorippr.py --rip --debug
2016-11-08 11:56:38 - Rip - DEBUG - Ripping initialised
2016-11-08 11:56:38 - Notification - INFO - trying method pushover
2016-11-08 11:56:38 - Notification - INFO - loading notification class part1
2016-11-08 11:56:38 - Notification - INFO - loading notification class part2
2016-11-08 11:56:39 - Pushover - INFO - Pushover message sent successfully

HEY - bing-bong - a message appeared on my phone!

So, in short, installing chump and removing a capitalization solved this for me on my virtual test machine. I will implement these changes on my working/ripping machine, test, and, in case this keeps working for both pushover and smtp notifications. issue a pull request..

knoer commented 7 years ago

Sorry for the delay - it has been running fine with my modifications since my last post, so I assume it is ready for a commit. Will look into this in one of the next days, and issue a pull request.

I did add another minor edit to the notification system; a message when ripping actually starts (DVD title(s) found and passed on to MakeMKV). I found it nice to get a confirmation that something was found on the disc (matching the title lengths in settings.cfg), and get a confirmation within a couple of minutes after inserting the disc for ripping.

I will embed this in the existing notification system, so this can be turned on/off via settings.cfg with new parameter "start"

 # Notify on these events
 # start: title(s) found on disc - ripping started
 # rip: rip complete
 # compress: compression complete
 # extra: subtitles, renaming etc. complete
    notify_on_state:         start, rip, compress, extra

Still very pleased with this script 👍