From: Thomas Perl Date: Tue, 29 Jun 2010 23:53:22 +0000 (+0200) Subject: Detect non-zero command exit codes X-Git-Tag: 1.11~1 X-Git-Url: https://repo.or.cz/w/urlwatch.git/commitdiff_plain/bc3a8168e80ca32b3c83badcd5e819772934a7e3 Detect non-zero command exit codes If a shell commands exists with a non-zero status, urlwatch considers this as an error and will optionally report the error to the user (not overwriting the last output data). --- diff --git a/lib/urlwatch/handler.py b/lib/urlwatch/handler.py index d02f6ee..1748a12 100755 --- a/lib/urlwatch/handler.py +++ b/lib/urlwatch/handler.py @@ -65,12 +65,25 @@ class JobBase(object): def retrieve(self, timestamp=None, filter=None, headers=None): raise Exception('Not implemented') +class ShellError(Exception): + """Exception for shell commands with non-zero exit code""" + + def __init__(self, result): + Exception.__init__(self) + self.result = result + + def __str__(self): + return '%s: Exit status %d' % (self.__class__.__name__, self.result) + class ShellJob(JobBase): def retrieve(self, timestamp=None, filter=None, headers=None): process = subprocess.Popen(self.location, \ stdout=subprocess.PIPE, \ shell=True) stdout_data, stderr_data = process.communicate() + result = process.wait() + if result != 0: + raise ShellError(result) return filter(self.location, stdout_data) class UrlJob(JobBase): diff --git a/urlwatch b/urlwatch index 021012a..5eb1bb3 100755 --- a/urlwatch +++ b/urlwatch @@ -260,6 +260,10 @@ if __name__ == '__main__': log.error('got HTTPError while loading url: %s' % error) if display_errors: details += foutput('error', job, error, summary) + except handler.ShellError, error: + log.error('Shell returned %d' % error.result) + if display_errors: + details += foutput('error', job, error, summary) except urllib2.URLError, error: log.error('got URLError while loading url: %s' % error) if display_errors: