patchbomb: Validate email config before we start prompting for info.
authorBryan O'Sullivan <bos@serpentine.com>
Sun, 27 May 2007 14:40:14 -0700
changeset 4489 a11e13d50645
parent 4488 62019c4427e3
child 4490 c927c568a5ad
patchbomb: Validate email config before we start prompting for info.
hgext/patchbomb.py
mercurial/mail.py
--- a/hgext/patchbomb.py	Sun May 27 14:26:54 2007 -0700
+++ b/hgext/patchbomb.py	Sun May 27 14:40:14 2007 -0700
@@ -223,6 +223,9 @@
                 pass
             os.rmdir(tmpdir)
 
+    if not opts['test']:
+        mail.validateconfig(ui)
+
     # option handling
     commands.setremoteconfig(ui, opts)
     if opts.get('outgoint') and opts.get('bundle'):
--- a/mercurial/mail.py	Sun May 27 14:26:54 2007 -0700
+++ b/mercurial/mail.py	Sun May 27 14:40:14 2007 -0700
@@ -68,3 +68,15 @@
 
 def sendmail(ui, sender, recipients, msg):
     return connect(ui).sendmail(sender, recipients, msg)
+
+def validateconfig(ui):
+    '''determine if we have enough config data to try sending email.'''
+    method = ui.config('email', 'method', 'smtp')
+    if method == 'smtp':
+        if not ui.config('smtp', 'host'):
+            raise util.Abort(_('smtp specified as email transport, '
+                               'but no smtp host configured'))
+    else:
+        if not util.find_exe(method):
+            raise util.Abort(_('%r specified as email transport, '
+                               'but not in PATH') % method)