[PATCH] Check if the mua exists.
Carl Chenet
carl.chenet at ohmytux.com
Thu Apr 23 17:36:25 UTC 2009
---
bin/reportbug | 17 +++++++++++++----
reportbug/utils.py | 22 ++++++++++++++++++++++
2 files changed, 35 insertions(+), 4 deletions(-)
diff --git a/bin/reportbug b/bin/reportbug
index dcae600..563534f 100755
--- a/bin/reportbug
+++ b/bin/reportbug
@@ -244,10 +244,13 @@ def handle_editing(filename, dmessage, options, sendto, attachments, package,
mailer = ui.menu('Choose a mailer for your report', mailers,
'Select mailer: ', default='', empty_ok=True)
if mailer:
- mailer = utils.MUA.get(mailer)
- if mailer:
- options.mua = mailer
- break
+ if not utils.mua_exists(utils.MUA[mailer]):
+ ewrite("Your mail user agent can not be found.\n")
+ else:
+ mailer = utils.MUA.get(mailer)
+ if mailer:
+ options.mua = mailer
+ break
skip_editing = True
elif x in ('n', 'q'):
stopmsg(filename)
@@ -835,6 +838,12 @@ def main():
print "The above files are missing, so can't be attached; exiting"
sys.exit(1)
+
+ if options.mua:
+ if not utils.mua_exists(options.mua):
+ ewrite("Your mail user agent can not be found; exiting.\n")
+ sys.exit(1)
+
if options.interface:
interface = options.interface
diff --git a/reportbug/utils.py b/reportbug/utils.py
index 7341633..31ccbea 100644
--- a/reportbug/utils.py
+++ b/reportbug/utils.py
@@ -759,6 +759,28 @@ MUA = {
}
MUA['nmh'] = MUA['mh']
+MUAVERSION = {
+ MUA['mutt'] : 'mutt -v',
+ MUA[ 'af'] : 'af -v ',
+ MUA['mh'] : '/usr/bin/mh/comp -use -file',
+ MUA['gnus'] : 'emacs --version',
+ }
+
+def mua_exists(mua):
+ output = '/dev/null'
+ if os.path.exists(output):
+ try:
+ returnvalue = subprocess.call(MUAVERSION[mua], stdout=open(output, 'w'), stderr=subprocess.STDOUT, shell=True)
+ except IOError, OSError:
+ returnvalue = subprocess.call(MUAVERSION[mua], shell=True)
+ else:
+ returnvalue = subprocess.call(MUAVERSION[mua], shell=True)
+ # 127 is the shell standard return value to indicate a 'command not found' result
+ if returnvalue == 127:
+ return False
+ else:
+ return True
+
def first_run():
return not os.path.exists(USERFILE)
--
1.5.4.3
--=-LrJZiSlU05J/TIxrYSCD--
More information about the Reportbug-maint
mailing list