Mercurial > public > mercurial-scm > hg
comparison mercurial/commands.py @ 30918:fec3dbaa7f83
debugcommands: extract debuginstall in the debugcommands module
author | Pierre-Yves David <pierre-yves.david@ens-lyon.org> |
---|---|
date | Wed, 01 Feb 2017 17:31:05 +0100 |
parents | 455677a7667f |
children | e1fa5fe9f9d4 |
comparison
equal
deleted
inserted
replaced
30917:b35e05103641 | 30918:fec3dbaa7f83 |
---|---|
11 import errno | 11 import errno |
12 import os | 12 import os |
13 import re | 13 import re |
14 import socket | 14 import socket |
15 import string | 15 import string |
16 import sys | |
17 import tempfile | |
18 import time | 16 import time |
19 | 17 |
20 from .i18n import _ | 18 from .i18n import _ |
21 from .node import ( | 19 from .node import ( |
22 bin, | 20 bin, |
49 merge as mergemod, | 47 merge as mergemod, |
50 minirst, | 48 minirst, |
51 obsolete, | 49 obsolete, |
52 patch, | 50 patch, |
53 phases, | 51 phases, |
54 policy, | |
55 pvec, | 52 pvec, |
56 pycompat, | 53 pycompat, |
57 repair, | 54 repair, |
58 revlog, | 55 revlog, |
59 revset, | 56 revset, |
60 scmutil, | 57 scmutil, |
61 server, | 58 server, |
62 smartset, | 59 smartset, |
63 sshserver, | 60 sshserver, |
64 sslutil, | |
65 streamclone, | 61 streamclone, |
66 templatekw, | 62 templatekw, |
67 templater, | 63 templater, |
68 ui as uimod, | 64 ui as uimod, |
69 util, | 65 util, |
1865 Returns 0 on success, 1 if errors are encountered. | 1861 Returns 0 on success, 1 if errors are encountered. |
1866 """ | 1862 """ |
1867 with repo.wlock(False): | 1863 with repo.wlock(False): |
1868 return cmdutil.copy(ui, repo, pats, opts) | 1864 return cmdutil.copy(ui, repo, pats, opts) |
1869 | 1865 |
1870 @command('debuginstall', [] + formatteropts, '', norepo=True) | |
1871 def debuginstall(ui, **opts): | |
1872 '''test Mercurial installation | |
1873 | |
1874 Returns 0 on success. | |
1875 ''' | |
1876 | |
1877 def writetemp(contents): | |
1878 (fd, name) = tempfile.mkstemp(prefix="hg-debuginstall-") | |
1879 f = os.fdopen(fd, "wb") | |
1880 f.write(contents) | |
1881 f.close() | |
1882 return name | |
1883 | |
1884 problems = 0 | |
1885 | |
1886 fm = ui.formatter('debuginstall', opts) | |
1887 fm.startitem() | |
1888 | |
1889 # encoding | |
1890 fm.write('encoding', _("checking encoding (%s)...\n"), encoding.encoding) | |
1891 err = None | |
1892 try: | |
1893 encoding.fromlocal("test") | |
1894 except error.Abort as inst: | |
1895 err = inst | |
1896 problems += 1 | |
1897 fm.condwrite(err, 'encodingerror', _(" %s\n" | |
1898 " (check that your locale is properly set)\n"), err) | |
1899 | |
1900 # Python | |
1901 fm.write('pythonexe', _("checking Python executable (%s)\n"), | |
1902 pycompat.sysexecutable) | |
1903 fm.write('pythonver', _("checking Python version (%s)\n"), | |
1904 ("%d.%d.%d" % sys.version_info[:3])) | |
1905 fm.write('pythonlib', _("checking Python lib (%s)...\n"), | |
1906 os.path.dirname(pycompat.fsencode(os.__file__))) | |
1907 | |
1908 security = set(sslutil.supportedprotocols) | |
1909 if sslutil.hassni: | |
1910 security.add('sni') | |
1911 | |
1912 fm.write('pythonsecurity', _("checking Python security support (%s)\n"), | |
1913 fm.formatlist(sorted(security), name='protocol', | |
1914 fmt='%s', sep=',')) | |
1915 | |
1916 # These are warnings, not errors. So don't increment problem count. This | |
1917 # may change in the future. | |
1918 if 'tls1.2' not in security: | |
1919 fm.plain(_(' TLS 1.2 not supported by Python install; ' | |
1920 'network connections lack modern security\n')) | |
1921 if 'sni' not in security: | |
1922 fm.plain(_(' SNI not supported by Python install; may have ' | |
1923 'connectivity issues with some servers\n')) | |
1924 | |
1925 # TODO print CA cert info | |
1926 | |
1927 # hg version | |
1928 hgver = util.version() | |
1929 fm.write('hgver', _("checking Mercurial version (%s)\n"), | |
1930 hgver.split('+')[0]) | |
1931 fm.write('hgverextra', _("checking Mercurial custom build (%s)\n"), | |
1932 '+'.join(hgver.split('+')[1:])) | |
1933 | |
1934 # compiled modules | |
1935 fm.write('hgmodulepolicy', _("checking module policy (%s)\n"), | |
1936 policy.policy) | |
1937 fm.write('hgmodules', _("checking installed modules (%s)...\n"), | |
1938 os.path.dirname(__file__)) | |
1939 | |
1940 err = None | |
1941 try: | |
1942 from . import ( | |
1943 base85, | |
1944 bdiff, | |
1945 mpatch, | |
1946 osutil, | |
1947 ) | |
1948 dir(bdiff), dir(mpatch), dir(base85), dir(osutil) # quiet pyflakes | |
1949 except Exception as inst: | |
1950 err = inst | |
1951 problems += 1 | |
1952 fm.condwrite(err, 'extensionserror', " %s\n", err) | |
1953 | |
1954 compengines = util.compengines._engines.values() | |
1955 fm.write('compengines', _('checking registered compression engines (%s)\n'), | |
1956 fm.formatlist(sorted(e.name() for e in compengines), | |
1957 name='compengine', fmt='%s', sep=', ')) | |
1958 fm.write('compenginesavail', _('checking available compression engines ' | |
1959 '(%s)\n'), | |
1960 fm.formatlist(sorted(e.name() for e in compengines | |
1961 if e.available()), | |
1962 name='compengine', fmt='%s', sep=', ')) | |
1963 wirecompengines = util.compengines.supportedwireengines(util.SERVERROLE) | |
1964 fm.write('compenginesserver', _('checking available compression engines ' | |
1965 'for wire protocol (%s)\n'), | |
1966 fm.formatlist([e.name() for e in wirecompengines | |
1967 if e.wireprotosupport()], | |
1968 name='compengine', fmt='%s', sep=', ')) | |
1969 | |
1970 # templates | |
1971 p = templater.templatepaths() | |
1972 fm.write('templatedirs', 'checking templates (%s)...\n', ' '.join(p)) | |
1973 fm.condwrite(not p, '', _(" no template directories found\n")) | |
1974 if p: | |
1975 m = templater.templatepath("map-cmdline.default") | |
1976 if m: | |
1977 # template found, check if it is working | |
1978 err = None | |
1979 try: | |
1980 templater.templater.frommapfile(m) | |
1981 except Exception as inst: | |
1982 err = inst | |
1983 p = None | |
1984 fm.condwrite(err, 'defaulttemplateerror', " %s\n", err) | |
1985 else: | |
1986 p = None | |
1987 fm.condwrite(p, 'defaulttemplate', | |
1988 _("checking default template (%s)\n"), m) | |
1989 fm.condwrite(not m, 'defaulttemplatenotfound', | |
1990 _(" template '%s' not found\n"), "default") | |
1991 if not p: | |
1992 problems += 1 | |
1993 fm.condwrite(not p, '', | |
1994 _(" (templates seem to have been installed incorrectly)\n")) | |
1995 | |
1996 # editor | |
1997 editor = ui.geteditor() | |
1998 editor = util.expandpath(editor) | |
1999 fm.write('editor', _("checking commit editor... (%s)\n"), editor) | |
2000 cmdpath = util.findexe(pycompat.shlexsplit(editor)[0]) | |
2001 fm.condwrite(not cmdpath and editor == 'vi', 'vinotfound', | |
2002 _(" No commit editor set and can't find %s in PATH\n" | |
2003 " (specify a commit editor in your configuration" | |
2004 " file)\n"), not cmdpath and editor == 'vi' and editor) | |
2005 fm.condwrite(not cmdpath and editor != 'vi', 'editornotfound', | |
2006 _(" Can't find editor '%s' in PATH\n" | |
2007 " (specify a commit editor in your configuration" | |
2008 " file)\n"), not cmdpath and editor) | |
2009 if not cmdpath and editor != 'vi': | |
2010 problems += 1 | |
2011 | |
2012 # check username | |
2013 username = None | |
2014 err = None | |
2015 try: | |
2016 username = ui.username() | |
2017 except error.Abort as e: | |
2018 err = e | |
2019 problems += 1 | |
2020 | |
2021 fm.condwrite(username, 'username', _("checking username (%s)\n"), username) | |
2022 fm.condwrite(err, 'usernameerror', _("checking username...\n %s\n" | |
2023 " (specify a username in your configuration file)\n"), err) | |
2024 | |
2025 fm.condwrite(not problems, '', | |
2026 _("no problems detected\n")) | |
2027 if not problems: | |
2028 fm.data(problems=problems) | |
2029 fm.condwrite(problems, 'problems', | |
2030 _("%d problems detected," | |
2031 " please check your install!\n"), problems) | |
2032 fm.end() | |
2033 | |
2034 return problems | |
2035 | |
2036 @command('debugknown', [], _('REPO ID...'), norepo=True) | 1866 @command('debugknown', [], _('REPO ID...'), norepo=True) |
2037 def debugknown(ui, repopath, *ids, **opts): | 1867 def debugknown(ui, repopath, *ids, **opts): |
2038 """test whether node ids are known to a repo | 1868 """test whether node ids are known to a repo |
2039 | 1869 |
2040 Every ID must be a full-length hex node id string. Returns a list of 0s | 1870 Every ID must be a full-length hex node id string. Returns a list of 0s |