lines = _dict_to_conf(lines, main_config, list_names=['thread'])
try:
- file.writelines([l + '\n' for l in lines])
+ file.writelines([utils.make_str(l) + '\n' for l in lines])
except Exception as e:
logging.error('could not write main config file %(path)s: %(msg)s' % {
lines = _dict_to_conf(lines, camera_config)
try:
- file.writelines([l + '\n' for l in lines])
+ file.writelines([utils.make_str(l) + '\n' for l in lines])
except Exception as e:
logging.error('could not write camera config file %(path)s: %(msg)s' % {
from ordereddict import OrderedDict # @UnusedImport @Reimport
+_SIGNATURE_REGEX = re.compile('[^a-zA-Z0-9/?_.=&{}\[\]":, _-]')
+
+
def pretty_date_time(date_time, tzinfo=None, short=False):
if date_time is None:
return '('+ _('never') + ')'
return msg
+def make_str(s):
+ if isinstance(s, str):
+ return s
+
+ try:
+ return str(s)
+
+ except:
+ try:
+ return unicode(s, encoding='utf8').encode('utf8')
+
+ except:
+ return unicode(s).encode('utf8')
+
+
+def make_unicode(s):
+ if isinstance(s, unicode):
+ return s
+
+ try:
+ return unicode(s, encoding='utf8')
+
+ except:
+ try:
+ return unicode(s)
+
+ except:
+ return str(s).decode('utf8')
+
+
def get_disk_usage(path):
logging.debug('getting disk usage for path %(path)s...' % {
'path': path})
parts[0] = parts[1] = ''
parts[3] = query
uri = urlparse.urlunsplit(parts)
-
+ uri = _SIGNATURE_REGEX.sub('-', uri)
+ key = _SIGNATURE_REGEX.sub('-', key)
+
if body and body.startswith('---'):
body = None # file attachment
+ body = body and _SIGNATURE_REGEX.sub('-', body.decode('utf8'))
+
return hashlib.sha1('%s:%s:%s:%s' % (method, uri, body or '', key)).hexdigest().lower()
import stat
import subprocess
import time
+import utils
_resolutions_cache = {}
def list_resolutions(device):
global _resolutions_cache
+ device = utils.make_str(device)
+
if device in _resolutions_cache:
return _resolutions_cache[device]
resolutions = set()
output = ''
started = time.time()
- p = subprocess.Popen('v4l2-ctl -d %(device)s --list-formats-ext | grep -vi stepwise | grep -oE "[0-9]+x[0-9]+" || true' % {
+ p = subprocess.Popen('v4l2-ctl -d "%(device)s" --list-formats-ext | grep -vi stepwise | grep -oE "[0-9]+x[0-9]+" || true' % {
'device': device}, shell=True, stdout=subprocess.PIPE, bufsize=1)
fd = p.stdout.fileno()
def device_present(device):
+ device = utils.make_str(device)
+
try:
st = os.stat(device)
return stat.S_ISCHR(st.st_mode)
def find_persistent_device(device):
+ device = utils.make_str(device)
+
try:
devs_by_id = os.listdir(_DEV_V4L_BY_ID)
def _get_ctrl(device, control):
global _ctrl_values_cache
+ device = utils.make_str(device)
+
if not device_present(device):
return None
def _set_ctrl(device, control, value):
global _ctrl_values_cache
+ device = utils.make_str(device)
+
if not device_present(device):
return
output = ''
started = time.time()
- p = subprocess.Popen('v4l2-ctl -d %(device)s --set-ctrl %(control)s=%(value)s' % {
+ p = subprocess.Popen('v4l2-ctl -d "%(device)s" --set-ctrl %(control)s=%(value)s' % {
'device': device, 'control': control, 'value': value}, shell=True, stdout=subprocess.PIPE, bufsize=1)
fd = p.stdout.fileno()
def _list_ctrls(device):
global _ctrls_cache
+
+ device = utils.make_str(device)
if device in _ctrls_cache:
return _ctrls_cache[device]
output = ''
started = time.time()
- p = subprocess.Popen('v4l2-ctl -d %(device)s --list-ctrls' % {
+ p = subprocess.Popen('v4l2-ctl -d "%(device)s" --list-ctrls' % {
'device': device}, shell=True, stdout=subprocess.PIPE, bufsize=1)
fd = p.stdout.fileno()
var username = '';
var password = '';
var baseUri = null;
+var signatureRegExp = new RegExp('[^a-zA-Z0-9/?_.=&{}\\[\\]":, _-]', 'g');
/* utils */
query = query.filter(function (q) {return q.key !== '_signature';});
query.sortKey(function (q) {return q.key;});
query = query.map(function (q) {return q.key + '=' + encodeURIComponent(q.value);}).join('&');
- uri = baseUrl + '?' + query;
+ uri = baseUrl + '?' + query;
+ uri = uri.replace(signatureRegExp, '-');
+ body = body && body.replace(signatureRegExp, '-');
+ var password = window.password.replace(signatureRegExp, '-');
- return sha1(method + ':' + uri + ':' + (body || '') + ':' + window.password).toLowerCase();
+ return sha1(method + ':' + uri + ':' + (body || '') + ':' + password).toLowerCase();
}
function addAuthParams(method, url, body) {