changeset 28440:855d9b2eea67

debuginstall: convert to formatter commit editor now reports its editor default template is now reported a broken vi editor (vi not in path) is still not considered a problem (!!)
author timeless <timeless@mozdev.org>
date Wed, 09 Mar 2016 18:58:51 +0000
parents b6e71f8af5b8
children 79d8e7926a04
files mercurial/commands.py tests/test-completion.t tests/test-install.t
diffstat 3 files changed, 92 insertions(+), 46 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/commands.py	Wed Mar 02 13:13:05 2016 -0500
+++ b/mercurial/commands.py	Wed Mar 09 18:58:51 2016 +0000
@@ -2700,8 +2700,8 @@
 
     fm.end()
 
-@command('debuginstall', [], '', norepo=True)
-def debuginstall(ui):
+@command('debuginstall', [] + formatteropts, '', norepo=True)
+def debuginstall(ui, **opts):
     '''test Mercurial installation
 
     Returns 0 on success.
@@ -2716,25 +2716,33 @@
 
     problems = 0
 
+    fm = ui.formatter('debuginstall', opts)
+    fm.startitem()
+
     # encoding
-    ui.status(_("checking encoding (%s)...\n") % encoding.encoding)
+    fm.write('encoding', _("checking encoding (%s)...\n"), encoding.encoding)
+    err = None
     try:
         encoding.fromlocal("test")
     except error.Abort as inst:
-        ui.write(" %s\n" % inst)
-        ui.write(_(" (check that your locale is properly set)\n"))
+        err = inst
         problems += 1
+    fm.condwrite(err, 'encodingerror', _(" %s\n"
+                 " (check that your locale is properly set)\n"), err)
 
     # Python
-    ui.status(_("checking Python executable (%s)\n") % sys.executable)
-    ui.status(_("checking Python version (%s)\n")
-              % ("%s.%s.%s" % sys.version_info[:3]))
-    ui.status(_("checking Python lib (%s)...\n")
-              % os.path.dirname(os.__file__))
+    fm.write('pythonexe', _("checking Python executable (%s)\n"),
+             sys.executable)
+    fm.write('pythonver', _("checking Python version (%s)\n"),
+             ("%s.%s.%s" % sys.version_info[:3]))
+    fm.write('pythonlib', _("checking Python lib (%s)...\n"),
+             os.path.dirname(os.__file__))
 
     # compiled modules
-    ui.status(_("checking installed modules (%s)...\n")
-              % os.path.dirname(__file__))
+    fm.write('hgmodules', _("checking installed modules (%s)...\n"),
+             os.path.dirname(__file__))
+
+    err = None
     try:
         from . import (
             base85,
@@ -2744,63 +2752,74 @@
         )
         dir(bdiff), dir(mpatch), dir(base85), dir(osutil) # quiet pyflakes
     except Exception as inst:
-        ui.write(" %s\n" % inst)
-        ui.write(_(" One or more extensions could not be found"))
-        ui.write(_(" (check that you compiled the extensions)\n"))
+        err = inst
         problems += 1
+    fm.condwrite(err, 'extensionserror', " %s\n", err)
 
     # templates
     from . import templater
     p = templater.templatepaths()
-    ui.status(_("checking templates (%s)...\n") % ' '.join(p))
+    fm.write('templatedirs', 'checking templates (%s)...\n', ' '.join(p))
+    fm.condwrite(not p, '', _(" no template directories found\n"))
     if p:
         m = templater.templatepath("map-cmdline.default")
         if m:
             # template found, check if it is working
+            err = None
             try:
                 templater.templater(m)
             except Exception as inst:
-                ui.write(" %s\n" % inst)
+                err = inst
                 p = None
+            fm.condwrite(err, 'defaulttemplateerror', " %s\n", err)
         else:
-            ui.write(_(" template 'default' not found\n"))
             p = None
-    else:
-        ui.write(_(" no template directories found\n"))
+        fm.condwrite(p, 'defaulttemplate',
+                     _("checking default template (%s)\n"), m)
+        fm.condwrite(not m, 'defaulttemplatenotfound',
+                     _(" template '%s' not found\n"), "default")
     if not p:
-        ui.write(_(" (templates seem to have been installed incorrectly)\n"))
         problems += 1
+    fm.condwrite(not p, '',
+                 _(" (templates seem to have been installed incorrectly)\n"))
 
     # editor
-    ui.status(_("checking commit editor...\n"))
     editor = ui.geteditor()
     editor = util.expandpath(editor)
+    fm.write('editor', _("checking commit editor... (%s)\n"), editor)
     cmdpath = util.findexe(shlex.split(editor)[0])
-    if not cmdpath:
-        if editor == 'vi':
-            ui.write(_(" No commit editor set and can't find vi in PATH\n"))
-            ui.write(_(" (specify a commit editor in your configuration"
-                       " file)\n"))
-        else:
-            ui.write(_(" Can't find editor '%s' in PATH\n") % editor)
-            ui.write(_(" (specify a commit editor in your configuration"
-                       " file)\n"))
-            problems += 1
+    fm.condwrite(not cmdpath and editor == 'vi', 'vinotfound',
+                 _(" No commit editor set and can't find %s in PATH\n"
+                   " (specify a commit editor in your configuration"
+                   " file)\n"), not cmdpath and editor == 'vi' and editor)
+    fm.condwrite(not cmdpath and editor != 'vi', 'editornotfound',
+                 _(" Can't find editor '%s' in PATH\n"
+                   " (specify a commit editor in your configuration"
+                   " file)\n"), not cmdpath and editor)
+    if not cmdpath and editor != 'vi':
+        problems += 1
 
     # check username
-    ui.status(_("checking username...\n"))
+    username = None
+    err = None
     try:
-        ui.username()
+        username = ui.username()
     except error.Abort as e:
-        ui.write(" %s\n" % e)
-        ui.write(_(" (specify a username in your configuration file)\n"))
+        err = e
         problems += 1
 
+    fm.condwrite(username, 'username',  _("checking username (%s)\n"), username)
+    fm.condwrite(err, 'usernameerror', _("checking username...\n %s\n"
+        " (specify a username in your configuration file)\n"), err)
+
+    fm.condwrite(not problems, '',
+                 _("no problems detected\n"))
     if not problems:
-        ui.status(_("no problems detected\n"))
-    else:
-        ui.write(_("%s problems detected,"
-                   " please check your install!\n") % problems)
+        fm.data(problems=problems)
+    fm.condwrite(problems, 'problems',
+                 _("%s problems detected,"
+                   " please check your install!\n"), problems)
+    fm.end()
 
     return problems
 
--- a/tests/test-completion.t	Wed Mar 02 13:13:05 2016 -0500
+++ b/tests/test-completion.t	Wed Mar 09 18:58:51 2016 +0000
@@ -254,7 +254,7 @@
   debugignore: 
   debugindex: changelog, manifest, dir, format
   debugindexdot: changelog, manifest, dir
-  debuginstall: 
+  debuginstall: template
   debugknown: 
   debuglabelcomplete: 
   debuglocks: force-lock, force-wlock
--- a/tests/test-install.t	Wed Mar 02 13:13:05 2016 -0500
+++ b/tests/test-install.t	Wed Mar 09 18:58:51 2016 +0000
@@ -6,10 +6,35 @@
   checking Python lib (*lib*)... (glob)
   checking installed modules (*mercurial)... (glob)
   checking templates (*mercurial?templates)... (glob)
-  checking commit editor...
-  checking username...
+  checking default template (*mercurial?templates?map-cmdline.default) (glob)
+  checking commit editor... (*python* -c "import sys; sys.exit(0)") (glob)
+  checking username (test)
   no problems detected
 
+hg debuginstall JSON
+  $ hg debuginstall -Tjson
+  [
+   {
+    "defaulttemplate": "*mercurial?templates?map-cmdline.default", (glob)
+    "defaulttemplateerror": null,
+    "defaulttemplatenotfound": "default",
+    "editor": "*python* -c \"import sys; sys.exit(0)\"", (glob)
+    "editornotfound": false,
+    "encoding": "ascii",
+    "encodingerror": null,
+    "extensionserror": null,
+    "hgmodules": "*mercurial", (glob)
+    "problems": 0,
+    "pythonexe": "*python", (glob)
+    "pythonlib": "*python*", (glob)
+    "pythonver": "*.*.*", (glob)
+    "templatedirs": "*mercurial?templates", (glob)
+    "username": "test",
+    "usernameerror": null,
+    "vinotfound": false
+   }
+  ]
+
 hg debuginstall with no username
   $ HGUSER= hg debuginstall
   checking encoding (ascii)...
@@ -18,7 +43,8 @@
   checking Python lib (*lib*)... (glob)
   checking installed modules (*mercurial)... (glob)
   checking templates (*mercurial?templates)... (glob)
-  checking commit editor...
+  checking default template (*mercurial?templates?map-cmdline.default) (glob)
+  checking commit editor... (*python* -c "import sys; sys.exit(0)") (glob)
   checking username...
    no username supplied
    (specify a username in your configuration file)
@@ -38,8 +64,9 @@
   checking Python lib (*lib*)... (glob)
   checking installed modules (*mercurial)... (glob)
   checking templates (*mercurial?templates)... (glob)
-  checking commit editor...
-  checking username...
+  checking default template (*mercurial?templates?map-cmdline.default) (glob)
+  checking commit editor... (*python* -c "import sys; sys.exit(0)") (glob)
+  checking username (test)
   no problems detected
 
 #if test-repo