-
Notifications
You must be signed in to change notification settings - Fork 0
/
nk_bonjour.py
57 lines (47 loc) · 1.17 KB
/
nk_bonjour.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import nuke
import select
import sys
import pybonjour
import socket
import threading
name = socket.gethostname()
regtype = "_nuke._tcp"
port = 6980
def register_callback(sdRef, flags, errorCode, name, regtype, domain):
if errorCode == pybonjour.kDNSServiceErr_NoError:
print 'Registered service:'
print ' name =', name
print ' regtype =', regtype
print ' domain =', domain
sdRef = pybonjour.DNSServiceRegister(name = name,
regtype = regtype,
port = port,
callBack = register_callback)
def advertise():
try:
try:
while True:
ready = select.select([sdRef], [], [])
if sdRef in ready[0]:
pybonjour.DNSServiceProcessResult(sdRef)
except KeyboardInterrupt:
pass
finally:
sdRef.close()
threading.Thread( None, advertise ).start()
from base64 import urlsafe_b64decode as decode
from bottle import route, run
@route('/')
@route('/cmd/:cmdString')
def index(cmdString="world"):
cmd = "Cannot decode command.\n"
try:
cmd = decode(cmdString)
def c():
print cmd
eval(cmd)
nuke.executeInMainThread(c)
except:
pass
return cmd
threading.Thread(target=run, kwargs={"host":name+".local","port":6980} ).start()