Skip to content

Instantly share code, notes, and snippets.

@jplattel
Created February 26, 2011 21:29
Show Gist options
  • Save jplattel/845642 to your computer and use it in GitHub Desktop.
Save jplattel/845642 to your computer and use it in GitHub Desktop.
Print pretty signals with the correct timestamp excluding delta's
import subprocess, os, sys
from datetime import datetime
import time
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
time = int(0)
try:
f = open(path, 'rb')
print path
while True:
msDelta = uvarintRead(f)
dataLength = uvarintRead(f)
data = f.read(dataLength)
time = time + int(msDelta)
timestamp = datetime.fromtimestamp(time / 1000)
print timestamp
try:
# This tries to open an existing file but creates a new file if necessary.
logfile = open("log4.txt", "a")
logfile.write(str(timestamp) + ',' + 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