python3 fixes
This commit is contained in:
parent
49a30d0c43
commit
d222dff214
2 changed files with 22 additions and 18 deletions
|
@ -39,7 +39,7 @@ class DistributedClient:
|
||||||
def next(self):
|
def next(self):
|
||||||
url = '%s/next' % self.url
|
url = '%s/next' % self.url
|
||||||
r = requests.get(url)
|
r = requests.get(url)
|
||||||
data = json.loads(r.content)
|
data = r.json()
|
||||||
if 'oshash' in data:
|
if 'oshash' in data:
|
||||||
self.encode(data['oshash'], data['cmd'], data['output'])
|
self.encode(data['oshash'], data['cmd'], data['output'])
|
||||||
return True
|
return True
|
||||||
|
@ -59,7 +59,7 @@ class DistributedClient:
|
||||||
n = 0
|
n = 0
|
||||||
while True:
|
while True:
|
||||||
r = p.poll()
|
r = p.poll()
|
||||||
if r == None:
|
if r is None:
|
||||||
if n % 60 == 0:
|
if n % 60 == 0:
|
||||||
self.ping(oshash)
|
self.ping(oshash)
|
||||||
n = 0
|
n = 0
|
||||||
|
@ -95,6 +95,7 @@ class DistributedClient:
|
||||||
else:
|
else:
|
||||||
new = True
|
new = True
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
url = 'http://127.0.0.1:8789'
|
url = 'http://127.0.0.1:8789'
|
||||||
if len(sys.args) == 0:
|
if len(sys.args) == 0:
|
||||||
|
|
|
@ -6,6 +6,9 @@ import os
|
||||||
import json
|
import json
|
||||||
import shutil
|
import shutil
|
||||||
import time
|
import time
|
||||||
|
try:
|
||||||
|
import _thread as thread
|
||||||
|
except:
|
||||||
import thread
|
import thread
|
||||||
from Queue import Queue
|
from Queue import Queue
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
|
@ -96,12 +99,12 @@ class Server(Resource):
|
||||||
|
|
||||||
def render_json(self, request, response):
|
def render_json(self, request, response):
|
||||||
request.setHeader('Content-Type', 'application/json')
|
request.setHeader('Content-Type', 'application/json')
|
||||||
return json.dumps(response, indent=2)
|
return json.dumps(response, indent=2).encode()
|
||||||
|
|
||||||
def getChild(self, name, request):
|
def getChild(self, name, request):
|
||||||
# make source media available via oshash
|
# make source media available via oshash
|
||||||
if request.path.startswith('/get/'):
|
if request.path.startswith(b'/get/'):
|
||||||
oshash = request.path.split('/')[-1]
|
oshash = request.path.decode().split('/')[-1]
|
||||||
for path in self.client.path(oshash):
|
for path in self.client.path(oshash):
|
||||||
if os.path.exists(path):
|
if os.path.exists(path):
|
||||||
f = File(path, 'application/octet-stream')
|
f = File(path, 'application/octet-stream')
|
||||||
|
@ -110,8 +113,8 @@ class Server(Resource):
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def render_PUT(self, request):
|
def render_PUT(self, request):
|
||||||
if request.path.startswith('/upload'):
|
if request.path.startswith(b'/upload'):
|
||||||
parts = request.path.split('/')
|
parts = request.path.decode().split('/')
|
||||||
oshash = parts[-1]
|
oshash = parts[-1]
|
||||||
if len(oshash) == 16:
|
if len(oshash) == 16:
|
||||||
path = self.media_path(oshash)
|
path = self.media_path(oshash)
|
||||||
|
@ -129,8 +132,8 @@ class Server(Resource):
|
||||||
return '404 unkown location'
|
return '404 unkown location'
|
||||||
|
|
||||||
def render_POST(self, request):
|
def render_POST(self, request):
|
||||||
if request.path.startswith('/status'):
|
if request.path.startswith(b'/status'):
|
||||||
oshash = request.path.split('/')[-1]
|
oshash = request.path.decode().split('/')[-1]
|
||||||
error = request.args['error']
|
error = request.args['error']
|
||||||
self.update_status(oshash, 'failed')
|
self.update_status(oshash, 'failed')
|
||||||
return self.render_json(request, {})
|
return self.render_json(request, {})
|
||||||
|
@ -138,7 +141,7 @@ class Server(Resource):
|
||||||
return '404 unkown location'
|
return '404 unkown location'
|
||||||
|
|
||||||
def render_GET(self, request):
|
def render_GET(self, request):
|
||||||
if request.path.startswith('/next'):
|
if request.path.startswith(b'/next'):
|
||||||
response = {}
|
response = {}
|
||||||
files = self.queued_encodes()
|
files = self.queued_encodes()
|
||||||
for oshash in files:
|
for oshash in files:
|
||||||
|
@ -162,17 +165,17 @@ class Server(Resource):
|
||||||
print(oshash, f)
|
print(oshash, f)
|
||||||
return self.render_json(request, response)
|
return self.render_json(request, response)
|
||||||
return self.render_json(request, response)
|
return self.render_json(request, response)
|
||||||
elif request.path.startswith('/ping/'):
|
elif request.path.startswith(b'/ping/'):
|
||||||
parts = request.path.split('/')
|
parts = request.path.decode().split('/')
|
||||||
# FIXME: store client id somewhere
|
# FIXME: store client id somewhere
|
||||||
client = parts[-1]
|
client = parts[-1]
|
||||||
oshash = parts[-2]
|
oshash = parts[-2]
|
||||||
self.update_status(oshash, 'active')
|
self.update_status(oshash, 'active')
|
||||||
return self.render_json(request, {})
|
return self.render_json(request, {})
|
||||||
elif request.path.startswith('/update'):
|
elif request.path.startswith(b'/update'):
|
||||||
thread.start_new_thread(self.update, ())
|
thread.start_new_thread(self.update, ())
|
||||||
return self.render_json(request, {'status': True})
|
return self.render_json(request, {'status': True})
|
||||||
elif request.path.startswith('/status'):
|
elif request.path.startswith(b'/status'):
|
||||||
queued, offline = self.queued()
|
queued, offline = self.queued()
|
||||||
return self.render_json(request, {
|
return self.render_json(request, {
|
||||||
'active': self.active_encodes(),
|
'active': self.active_encodes(),
|
||||||
|
@ -180,7 +183,7 @@ class Server(Resource):
|
||||||
'offline': offline
|
'offline': offline
|
||||||
})
|
})
|
||||||
request.setHeader('Content-Type', 'text/html')
|
request.setHeader('Content-Type', 'text/html')
|
||||||
data = 'pandora_client distributed encoding server'
|
data = b'pandora_client distributed encoding server'
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
|
|
Loading…
Reference in a new issue