• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/sh
2
3/Library/Frameworks/Python.framework/Versions/@PYVER@/bin/python@PYVER@ << "EOF"
4
5# install_certifi.py
6#
7# sample script to install or update a set of default Root Certificates
8# for the ssl module.  Uses the certificates provided by the certifi package:
9#       https://pypi.python.org/pypi/certifi
10
11import os
12import os.path
13import ssl
14import stat
15import subprocess
16import sys
17
18STAT_0o775 = ( stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR
19             | stat.S_IRGRP | stat.S_IWGRP | stat.S_IXGRP
20             | stat.S_IROTH |                stat.S_IXOTH )
21
22def main():
23    openssl_dir, openssl_cafile = os.path.split(
24        ssl.get_default_verify_paths().openssl_cafile)
25
26    print(" -- pip install --upgrade certifi")
27    subprocess.check_call([sys.executable,
28        "-E", "-s", "-m", "pip", "install", "--upgrade", "certifi"])
29
30    import certifi
31
32    # change working directory to the default SSL directory
33    os.chdir(openssl_dir)
34    relpath_to_certifi_cafile = os.path.relpath(certifi.where())
35    print(" -- removing any existing file or link")
36    try:
37        os.remove(openssl_cafile)
38    except OSError:
39        pass
40    print(" -- creating symlink to certifi certificate bundle")
41    os.symlink(relpath_to_certifi_cafile, openssl_cafile)
42    print(" -- setting permissions")
43    os.chmod(openssl_cafile, STAT_0o775)
44    print(" -- update complete")
45
46if __name__ == '__main__':
47    main()
48EOF
49