2014-02-14 17:57:43 +00:00
|
|
|
"""
|
|
|
|
Monkey patches (paramiko support)
|
|
|
|
"""
|
2011-05-19 17:18:57 +00:00
|
|
|
import logging
|
|
|
|
|
2011-05-19 17:19:16 +00:00
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
2011-05-19 17:17:51 +00:00
|
|
|
def patch_001_paramiko_deprecation():
|
|
|
|
"""
|
2014-02-14 17:57:43 +00:00
|
|
|
Silence an an unhelpful Deprecation Warning triggered by Paramiko.
|
2011-05-19 17:17:51 +00:00
|
|
|
|
|
|
|
Not strictly a monkeypatch.
|
|
|
|
"""
|
|
|
|
import warnings
|
|
|
|
warnings.filterwarnings(
|
|
|
|
category=DeprecationWarning,
|
|
|
|
message='This application uses RandomPool,',
|
|
|
|
action='ignore',
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2011-05-19 17:18:57 +00:00
|
|
|
def patch_100_paramiko_log():
|
|
|
|
"""
|
|
|
|
Silence some noise paramiko likes to log.
|
|
|
|
|
|
|
|
Not strictly a monkeypatch.
|
|
|
|
"""
|
|
|
|
logging.getLogger('paramiko.transport').setLevel(logging.WARNING)
|
|
|
|
|
|
|
|
|
2011-05-19 17:17:03 +00:00
|
|
|
def patch_100_logger_getChild():
|
2011-05-18 21:46:49 +00:00
|
|
|
"""
|
|
|
|
Imitate Python 2.7 feature Logger.getChild.
|
|
|
|
"""
|
|
|
|
import logging
|
|
|
|
if not hasattr(logging.Logger, 'getChild'):
|
|
|
|
def getChild(self, name):
|
|
|
|
return logging.getLogger('.'.join([self.name, name]))
|
|
|
|
logging.Logger.getChild = getChild
|
|
|
|
|
|
|
|
|
|
|
|
def patch_all():
|
|
|
|
"""
|
|
|
|
Run all the patch_* functions in this module.
|
|
|
|
"""
|
2014-02-14 17:57:43 +00:00
|
|
|
monkeys = [(k, v) for (k, v) in globals().iteritems() if k.startswith('patch_') and k != 'patch_all']
|
2011-05-19 17:17:03 +00:00
|
|
|
monkeys.sort()
|
2014-02-14 17:57:43 +00:00
|
|
|
for k, v in monkeys:
|
2011-05-19 17:19:16 +00:00
|
|
|
log.debug('Patching %s', k)
|
2011-05-18 21:46:49 +00:00
|
|
|
v()
|