Last active
April 11, 2018 10:14
-
-
Save julian-klode/489aa5176914e16bb3408dbac44e2eb2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/python3 | |
import json | |
import os | |
import socket | |
import sys | |
socketFd=int(os.environ["APT_HOOK_SOCKET"]) | |
fobj=os.fdopen(socketFd, "r") | |
out=os.fdopen(socketFd, "w") | |
lines=iter(fobj) | |
while True: | |
line = next(lines) | |
request = json.loads(line) | |
print("Received call", request["method"], request.get("id")) | |
terminator = next(lines) | |
if terminator != '\n': | |
print("E: Invalid end of request: %r" % terminator) | |
if request["method"] == "org.debian.apt.hooks.hello": | |
print("Answering hello") | |
out.write("""{"jsonrpc": "2.0", "result": {"version": "0.1"}, "id": 0}\n\n""") | |
out.flush() | |
if request["method"] == "org.debian.apt.hooks.bye": | |
print("Bye bye") | |
sys.exit(0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment