if response.error:
logging.error('failed to list remote cameras on %(url)s: %(msg)s' % {
'url': make_camera_url(local_config, camera=False),
- 'msg': unicode(response.error)})
+ 'msg': utils.pretty_http_error(response.error)})
- return callback(error=unicode(response.error))
+ return callback(error=utils.pretty_http_error(response.error))
try:
response = json.loads(response.body)
logging.error('failed to get config for remote camera %(id)s on %(url)s: %(msg)s' % {
'id': camera_id,
'url': make_camera_url(local_config),
- 'msg': unicode(response.error)})
+ 'msg': utils.pretty_http_error(response.error)})
- return callback(error=unicode(response.error))
+ return callback(error=utils.pretty_http_error(response.error))
try:
response = json.loads(response.body)
logging.error('failed to set config for remote camera %(id)s on %(url)s: %(msg)s' % {
'id': camera_id,
'url': make_camera_url(local_config),
- 'msg': unicode(response.error)})
+ 'msg': utils.pretty_http_error(response.error)})
- return callback(error=unicode(response.error))
+ return callback(error=utils.pretty_http_error(response.error))
callback()
logging.error('failed to set preview for remote camera %(id)s on %(url)s: %(msg)s' % {
'id': camera_id,
'url': make_camera_url(local_config),
- 'msg': unicode(response.error)})
+ 'msg': utils.pretty_http_error(response.error)})
- return callback(error=unicode(response.error))
+ return callback(error=utils.pretty_http_error(response.error))
callback()
logging.error('failed to get current picture for remote camera %(id)s on %(url)s: %(msg)s' % {
'id': camera_id,
'url': make_camera_url(local_config),
- 'msg': unicode(response.error)})
+ 'msg': utils.pretty_http_error(response.error)})
- return callback(error=unicode(response.error))
+ return callback(error=utils.pretty_http_error(response.error))
callback(motion_detected, response.body)
logging.error('failed to get media list for remote camera %(id)s on %(url)s: %(msg)s' % {
'id': camera_id,
'url': make_camera_url(local_config),
- 'msg': unicode(response.error)})
+ 'msg': utils.pretty_http_error(response.error)})
- return callback(error=unicode(response.error))
+ return callback(error=utils.pretty_http_error(response.error))
try:
response = json.loads(response.body)
'filename': filename,
'id': camera_id,
'url': make_camera_url(local_config),
- 'msg': unicode(response.error)})
+ 'msg': utils.pretty_http_error(response.error)})
- return callback(error=unicode(response.error))
+ return callback(error=utils.pretty_http_error(response.error))
return callback(response.body)
'group': group,
'id': camera_id,
'url': make_camera_url(local_config),
- 'msg': unicode(response.error)})
+ 'msg': utils.pretty_http_error(response.error)})
- return callback(error=unicode(response.error))
+ return callback(error=utils.pretty_http_error(response.error))
try:
key = json.loads(response.body)['key']
logging.error('failed to download zip file for remote camera %(id)s on %(url)s: %(msg)s' % {
'id': camera_id,
'url': make_camera_url(local_config),
- 'msg': unicode(response.error)})
+ 'msg': utils.pretty_http_error(response.error)})
- return callback(error=unicode(response.error))
+ return callback(error=utils.pretty_http_error(response.error))
callback({
'data': response.body,
'url': make_camera_url(local_config),
'int': interval,
'framerate': framerate,
- 'msg': unicode(response.error)})
+ 'msg': utils.pretty_http_error(response.error)})
- return callback(error=unicode(response.error))
+ return callback(error=utils.pretty_http_error(response.error))
try:
response = json.loads(response.body)
logging.error('failed to check timelapse movie status for remote camera %(id)s on %(url)s: %(msg)s' % {
'id': camera_id,
'url': make_camera_url(local_config),
- 'msg': unicode(response.error)})
+ 'msg': utils.pretty_http_error(response.error)})
- return callback(error=unicode(response.error))
+ return callback(error=utils.pretty_http_error(response.error))
try:
response = json.loads(response.body)
logging.error('failed to download timelapse movie for remote camera %(id)s on %(url)s: %(msg)s' % {
'id': camera_id,
'url': make_camera_url(local_config),
- 'msg': unicode(response.error)})
+ 'msg': utils.pretty_http_error(response.error)})
- return callback(error=unicode(response.error))
+ return callback(error=utils.pretty_http_error(response.error))
callback({
'data': response.body,
'filename': filename,
'id': camera_id,
'url': make_camera_url(local_config),
- 'msg': unicode(response.error)})
+ 'msg': utils.pretty_http_error(response.error)})
- return callback(error=unicode(response.error))
+ return callback(error=utils.pretty_http_error(response.error))
callback(response.body)
'filename': filename,
'id': camera_id,
'url': make_camera_url(local_config),
- 'msg': unicode(response.error)})
+ 'msg': utils.pretty_http_error(response.error)})
- return callback(error=unicode(response.error))
+ return callback(error=utils.pretty_http_error(response.error))
callback()
'group': group,
'id': camera_id,
'url': make_camera_url(local_config),
- 'msg': unicode(response.error)})
+ 'msg': utils.pretty_http_error(response.error)})
- return callback(error=unicode(response.error))
+ return callback(error=utils.pretty_http_error(response.error))
callback()
import hashlib
import logging
import os
+import re
import time
import urllib
import urlparse
size, unit = size / 1024.0 / 1024 / 1024, 'GB'
return '%.1f %s' % (size, unit)
-
+
+
+def pretty_http_error(http_error):
+ msg = unicode(http_error)
+ if msg.startswith('HTTP '):
+ msg = msg.split(':', 1)[-1].strip()
+
+ if msg.startswith('[Errno '):
+ msg = msg.split(']', 1)[-1].strip()
+
+ return msg
+
def get_disk_usage(path):
logging.debug('getting disk usage for path %(path)s...' % {
http_client = AsyncHTTPClient()
called = [False]
+ not_2xx = [False]
def on_header(header):
+ if not_2xx[0]:
+ return # ignore headers unless the status is 2xx
+
header = header.lower()
if header.startswith('content-type'):
content_type = header.split(':')[1].strip()
called[0] = True
+ else:
+ m = re.match('^http/1.\d (\d+) ', header)
+ if m and int(m.group(1)) / 100 != 2:
+ not_2xx[0] = True
+
def on_response(response):
if not called[0]:
called[0] = True
- callback(error=unicode(response.error) if response.error else 'not a network camera')
+ callback(error=pretty_http_error(response.error) if response.error else 'not a network camera')
username = data['username'] or None
password = data['password'] or None