Created
August 21, 2017 03:44
-
-
Save JohnCoates/a6bc413626df10a224a292f724d81bbd to your computer and use it in GitHub Desktop.
Hook Python function calls for debugging
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import subprocess | |
import os | |
def hook(hookfunc, oldfunc): | |
def foo(*args, **kwargs): | |
hookfunc(*args, **kwargs) | |
return oldfunc(*args, **kwargs) | |
return foo | |
def printFunction(*args, **kwargs): | |
command = args[0] | |
print(command) | |
def printCD(*args, **kwargs): | |
path = args[0] | |
print("cd " + path) | |
subprocess.call = hook(printFunction, subprocess.call) | |
os.chdir = hook(printCD, os.chdir) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I used this to figure out what a python build script was running