Skip to content

Instantly share code, notes, and snippets.

@julian-klode
Last active April 11, 2018 10:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save julian-klode/489aa5176914e16bb3408dbac44e2eb2 to your computer and use it in GitHub Desktop.
Save julian-klode/489aa5176914e16bb3408dbac44e2eb2 to your computer and use it in GitHub Desktop.
#!/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