Skip to content

Instantly share code, notes, and snippets.

@jplattel
Created February 26, 2011 15:27
Show Gist options
  • Save jplattel/845302 to your computer and use it in GitHub Desktop.
Save jplattel/845302 to your computer and use it in GitHub Desktop.
MacLogger pretty-signal-print update
import subprocess, os, sys
from varints import uvarintRead, uvarintsDecode
def main():
signalName = sys.argv[1]
signal_repr = {
'mouse-pos': mouse_pos,
'input-idle': input_idle,
'front-window': front_window,
}[signalName]
signalDir = os.path.expanduser('~/Library/Application Support/MacLogger/signals/%s' % signalName)
path = '%s/%s' % (signalDir, list(sorted(os.listdir(signalDir)))[-1])
#p = subprocess.Popen(['tail', '-n', '0', '-f', path], stdout=subprocess.PIPE)
#f = p.stdout
try:
f = open(path, 'rb')
print path
while True:
msDelta = uvarintRead(f)
dataLength = uvarintRead(f)
data = f.read(dataLength)
print '[t += %.4d]: %s' % (msDelta, signal_repr(data))
msDeltaTime = '%.4d' % msDelta
try:
# This tries to open an existing file but creates a new file if necessary.
logfile = open("log.txt", "a")
logfile.write(msDeltaTime + ' ' + signal_repr(data) + '\n')
logfile.close()
except:
pass
except:
pass
def mouse_pos(data):
(x, y) = uvarintsDecode(data)
return '%d, %d' % (x, y)
def input_idle(data):
(value,) = uvarintsDecode(data)
return '%d' % value
def front_window(data):
return data
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment