2014-05-04 17:26:43 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# vi:si:et:sw=4:sts=4:ts=4
|
2014-05-17 00:14:15 +00:00
|
|
|
from __future__ import division
|
2014-05-04 17:26:43 +00:00
|
|
|
|
2014-05-18 23:24:04 +00:00
|
|
|
import subprocess
|
|
|
|
import json
|
|
|
|
import os
|
|
|
|
|
|
|
|
import ox
|
2014-05-19 20:14:24 +00:00
|
|
|
from oxtornado import actions
|
|
|
|
|
2014-05-18 23:24:04 +00:00
|
|
|
|
2014-08-22 16:42:08 +00:00
|
|
|
import settings
|
|
|
|
|
2014-05-04 17:26:43 +00:00
|
|
|
import item.api
|
|
|
|
import user.api
|
2014-05-18 23:24:04 +00:00
|
|
|
|
2014-05-19 20:14:24 +00:00
|
|
|
|
|
|
|
def selectFolder(data):
|
2014-05-18 23:24:04 +00:00
|
|
|
'''
|
|
|
|
returns {
|
|
|
|
path
|
|
|
|
}
|
|
|
|
'''
|
|
|
|
cmd = ['./ctl', 'ui', 'folder']
|
|
|
|
p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
|
|
|
|
stdout, stderr = p.communicate()
|
|
|
|
path = stdout.decode('utf-8').strip()
|
|
|
|
return {
|
|
|
|
'path': path
|
|
|
|
}
|
|
|
|
actions.register(selectFolder, cache=False)
|
|
|
|
|
2014-05-19 20:14:24 +00:00
|
|
|
|
|
|
|
def selectFile(data):
|
2014-05-18 23:24:04 +00:00
|
|
|
'''
|
|
|
|
returns {
|
|
|
|
path
|
|
|
|
}
|
|
|
|
'''
|
|
|
|
cmd = ['./ctl', 'ui', 'file']
|
|
|
|
p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
|
|
|
|
stdout, stderr = p.communicate()
|
|
|
|
path = stdout.decode('utf-8').strip()
|
|
|
|
return {
|
|
|
|
'path': path
|
|
|
|
}
|
|
|
|
actions.register(selectFile, cache=False)
|
|
|
|
|
|
|
|
|
2014-05-19 20:14:24 +00:00
|
|
|
|
|
|
|
def autocompleteFolder(data):
|
2014-05-18 23:24:04 +00:00
|
|
|
'''
|
|
|
|
takes {
|
|
|
|
path
|
|
|
|
}
|
|
|
|
returns {
|
|
|
|
items
|
|
|
|
}
|
|
|
|
'''
|
|
|
|
path = data['path']
|
|
|
|
path = os.path.expanduser(path)
|
|
|
|
if os.path.isdir(path):
|
|
|
|
if path.endswith('/') and path != '/':
|
|
|
|
path = path[:-1]
|
|
|
|
folder = path
|
|
|
|
name = ''
|
|
|
|
else:
|
|
|
|
folder, name = os.path.split(path)
|
|
|
|
if os.path.exists(folder):
|
|
|
|
prefix, folders, files = os.walk(folder).next()
|
2014-05-19 18:12:02 +00:00
|
|
|
folders = [os.path.join(prefix, f) for f in folders if (not name or f.startswith(name)) and not f.startswith('.')]
|
2014-05-18 23:24:04 +00:00
|
|
|
if prefix == path:
|
|
|
|
folders = [path] + folders
|
|
|
|
else:
|
|
|
|
folders = []
|
|
|
|
return {
|
|
|
|
'items': ox.sorted_strings(folders)
|
|
|
|
}
|
|
|
|
actions.register(autocompleteFolder, cache=False)
|
2014-08-22 16:42:08 +00:00
|
|
|
|
|
|
|
def getVersion(data):
|
|
|
|
'''
|
|
|
|
check if new version is available
|
|
|
|
'''
|
|
|
|
response = {
|
|
|
|
'current': settings.MINOR_VERSION,
|
|
|
|
'upgrade': False,
|
|
|
|
}
|
|
|
|
if not os.path.exists(os.path.join(settings.updates_path, 'release.json')):
|
|
|
|
return response
|
|
|
|
if not os.path.exists(os.path.join(settings.config_path, 'release.json')):
|
|
|
|
return response
|
|
|
|
with open(os.path.join(settings.updates_path, 'release.json')) as fd:
|
|
|
|
release = json.load(fd)
|
|
|
|
current = settings.release['modules']['openmedialibrary']['version']
|
|
|
|
response['current'] = current
|
|
|
|
new = release['modules']['openmedialibrary']['version']
|
|
|
|
response['new'] = new
|
|
|
|
response['update'] = current < new
|
|
|
|
return response
|
|
|
|
actions.register(getVersion, cache=False)
|
|
|
|
|
|
|
|
def restart(data):
|
|
|
|
'''
|
|
|
|
restart (and upgrade if upgrades are available)
|
|
|
|
'''
|
|
|
|
#subprocess.Popen(['./ctl', 'restart'], preexec_fn=os.setpgrp, close_fds=True)
|
|
|
|
subprocess.Popen(['./ctl', 'restart'], close_fds=True)
|
|
|
|
return {}
|
|
|
|
actions.register(restart, cache=False)
|