Skip to content

Instantly share code, notes, and snippets.

@cowlinator
Last active May 23, 2019 17:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cowlinator/1bc874dc1afb48fac86b69f4e6f8efc8 to your computer and use it in GitHub Desktop.
Save cowlinator/1bc874dc1afb48fac86b69f4e6f8efc8 to your computer and use it in GitHub Desktop.
Patch paramiko to remove cryptography warnings ( https://github.com/paramiko/paramiko/issues/1369 )
import distutils.version
import os
import subprocess
import sys
import paramiko
import requests
if __name__ == "__main__":
print(paramiko.__version__)
if distutils.version.StrictVersion(paramiko.__version__) > distutils.version.StrictVersion('2.4.2'):
print("Paramiko patch (supposedly) not required. Not patching.")
sys.exit(0)
response = requests.get(
"https://gist.githubusercontent.com/vkobel/52d795920aacd74afb4db15a89c39b8b/raw/3a75d984fb703413307f240c6c1cacd4d6036a8a/patchfile.diff",
stream=True
)
if response.status_code != 200 and response.status_code != 203 and response.status_code != 226:
raise Exception("Cannot get paramiko patch. Status code {sc}".format(sc=response.status_code))
patchfile_path = os.path.expanduser(os.path.join("~", "tmp", "paramiko-patchfile.diff"))
try:
os.makedirs(os.path.dirname(patchfile_path))
except Exception:
pass
with open(patchfile_path, 'wb') as file:
for chunk in response.iter_content(10 * 1024):
file.write(chunk)
os.chdir(paramiko.__path__[0])
subprocess.check_call("patch -p1 <{pp}".format(pp=patchfile_path), shell=True)
@cowlinator
Copy link
Author

cowlinator commented May 23, 2019

This script will patch whichever paramiko package is currently installed. (To patch a virtualenv, first activate the virtualenv).
This script should work on Linux and OS X. (untested)
This script will also work on Windows if you have added C:\Program Files\Git\usr\bin to your system Path environment variable. (tested)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment