##// END OF EJS Templates
sslutil: inform the user about how to fix an incomplete certificate chain...
sslutil: inform the user about how to fix an incomplete certificate chain This is a Windows only thing. Unfortunately, the socket is closed at this point (so the certificate is unavailable to check the chain). That means it's printed out when verification fails as a guess, on the assumption that 1) most of the time verification won't fail, and 2) sites using expired or certs that are too new will be rare. Maybe this is an argument for adding more functionality to debugssl, to test for problems and print certificate info. Or maybe it's an argument for bundling certificates with the Windows builds. That idea was set aside when the enhanced SSL code went in last summer, and it looks like there were issues with using certifi on Windows anyway[1]. This was tested by deleting the certificate out of certmgr.msc > "Third-Party Root Certification Authorities" > "Certificates", seeing `hg pull` fail (with the new message), trying this command, and then successfully performing the pull command. [1] https://www.mercurial-scm.org/pipermail/mercurial-devel/2016-October/089573.html

File last commit:

r32898:c425b678 default
r33494:30f2715b default
Show More
f
159 lines | 5.8 KiB | text/plain | FortranFixedLexer
Mads Kiilerich
tests: add 'f' tool for cross platform file operations in the tests...
r23860 #!/usr/bin/env python
"""
Utility for inspecting files in various ways.
This tool is like the collection of tools found in a unix environment but are
cross platform and stable and suitable for our needs in the test suite.
This can be used instead of tools like:
[
dd
find
head
hexdump
ls
md5sum
readlink
sha1sum
stat
tail
test
readlink.py
md5sum.py
"""
Pulkit Goyal
py3: make tests/f use absolute_import
r29160 from __future__ import absolute_import
import glob
Yuya Nishihara
tests: make 'f' utility import hashlib unconditionally...
r29233 import hashlib
Pulkit Goyal
py3: make tests/f use absolute_import
r29160 import optparse
import os
import re
import sys
Mads Kiilerich
tests: add 'f' tool for cross platform file operations in the tests...
r23860
def visit(opts, filenames, outfile):
"""Process filenames in the way specified in opts, writing output to
outfile."""
for f in sorted(filenames):
isstdin = f == '-'
if not isstdin and not os.path.lexists(f):
outfile.write('%s: file not found\n' % f)
continue
quiet = opts.quiet and not opts.recurse or isstdin
isdir = os.path.isdir(f)
islink = os.path.islink(f)
isfile = os.path.isfile(f) and not islink
dirfiles = None
content = None
facts = []
if isfile:
if opts.type:
facts.append('file')
if opts.hexdump or opts.dump or opts.md5:
Pulkit Goyal
py3: use open() instead of file() constructor...
r32898 content = open(f, 'rb').read()
Mads Kiilerich
tests: add 'f' tool for cross platform file operations in the tests...
r23860 elif islink:
if opts.type:
facts.append('link')
content = os.readlink(f)
elif isstdin:
content = sys.stdin.read()
if opts.size:
facts.append('size=%s' % len(content))
elif isdir:
if opts.recurse or opts.type:
dirfiles = glob.glob(f + '/*')
facts.append('directory with %s files' % len(dirfiles))
elif opts.type:
facts.append('type unknown')
if not isstdin:
stat = os.lstat(f)
Matt Mackall
tests: teach f not to report directory size...
r23911 if opts.size and not isdir:
Mads Kiilerich
tests: add 'f' tool for cross platform file operations in the tests...
r23860 facts.append('size=%s' % stat.st_size)
Matt Mackall
tests: teach f not to report symlink mode bits...
r23912 if opts.mode and not islink:
FUJIWARA Katsunori
f: use modern octal number formatting...
r28046 facts.append('mode=%o' % (stat.st_mode & 0o777))
Mads Kiilerich
tests: add 'f' tool for cross platform file operations in the tests...
r23860 if opts.links:
facts.append('links=%s' % stat.st_nlink)
if opts.newer:
# mtime might be in whole seconds so newer file might be same
if stat.st_mtime >= os.stat(opts.newer).st_mtime:
facts.append('newer than %s' % opts.newer)
else:
facts.append('older than %s' % opts.newer)
if opts.md5 and content is not None:
Yuya Nishihara
tests: make 'f' utility import hashlib unconditionally...
r29233 h = hashlib.md5(content)
facts.append('md5=%s' % h.hexdigest()[:opts.bytes])
Mads Kiilerich
tests: add 'f' tool for cross platform file operations in the tests...
r23860 if opts.sha1 and content is not None:
Yuya Nishihara
tests: make 'f' utility import hashlib unconditionally...
r29233 h = hashlib.sha1(content)
facts.append('sha1=%s' % h.hexdigest()[:opts.bytes])
Mads Kiilerich
tests: add 'f' tool for cross platform file operations in the tests...
r23860 if isstdin:
outfile.write(', '.join(facts) + '\n')
elif facts:
outfile.write('%s: %s\n' % (f, ', '.join(facts)))
elif not quiet:
outfile.write('%s:\n' % f)
if content is not None:
chunk = content
if not islink:
if opts.lines:
if opts.lines >= 0:
chunk = ''.join(chunk.splitlines(True)[:opts.lines])
else:
chunk = ''.join(chunk.splitlines(True)[opts.lines:])
if opts.bytes:
if opts.bytes >= 0:
chunk = chunk[:opts.bytes]
else:
chunk = chunk[opts.bytes:]
if opts.hexdump:
for i in range(0, len(chunk), 16):
FUJIWARA Katsunori
f: add whitespace around operator...
r28044 s = chunk[i:i + 16]
Mads Kiilerich
tests: add 'f' tool for cross platform file operations in the tests...
r23860 outfile.write('%04x: %-47s |%s|\n' %
(i, ' '.join('%02x' % ord(c) for c in s),
re.sub('[^ -~]', '.', s)))
if opts.dump:
if not quiet:
outfile.write('>>>\n')
outfile.write(chunk)
if not quiet:
if chunk.endswith('\n'):
outfile.write('<<<\n')
else:
outfile.write('\n<<< no trailing newline\n')
if opts.recurse and dirfiles:
assert not isstdin
visit(opts, dirfiles, outfile)
if __name__ == "__main__":
parser = optparse.OptionParser("%prog [options] [filenames]")
parser.add_option("-t", "--type", action="store_true",
help="show file type (file or directory)")
parser.add_option("-m", "--mode", action="store_true",
help="show file mode")
parser.add_option("-l", "--links", action="store_true",
help="show number of links")
parser.add_option("-s", "--size", action="store_true",
help="show size of file")
parser.add_option("-n", "--newer", action="store",
help="check if file is newer (or same)")
parser.add_option("-r", "--recurse", action="store_true",
help="recurse into directories")
parser.add_option("-S", "--sha1", action="store_true",
help="show sha1 hash of the content")
parser.add_option("-M", "--md5", action="store_true",
help="show md5 hash of the content")
parser.add_option("-D", "--dump", action="store_true",
help="dump file content")
parser.add_option("-H", "--hexdump", action="store_true",
help="hexdump file content")
parser.add_option("-B", "--bytes", type="int",
help="number of characters to dump")
parser.add_option("-L", "--lines", type="int",
help="number of lines to dump")
parser.add_option("-q", "--quiet", action="store_true",
help="no default output")
(opts, filenames) = parser.parse_args(sys.argv[1:])
if not filenames:
filenames = ['-']
visit(opts, filenames, sys.stdout)