2014-05-04 19:26:43 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# vi:si:et:sw=4:sts=4:ts=4
|
2014-09-03 00:32:44 +02:00
|
|
|
|
2014-05-04 19:26:43 +02:00
|
|
|
|
2019-01-20 18:40:04 +05:30
|
|
|
from os.path import normpath, dirname, abspath, join
|
2014-05-19 01:24:04 +02:00
|
|
|
import json
|
|
|
|
import os
|
2019-01-20 18:40:04 +05:30
|
|
|
import subprocess
|
|
|
|
import sys
|
2014-05-19 01:24:04 +02:00
|
|
|
|
|
|
|
import ox
|
2014-05-19 22:14:24 +02:00
|
|
|
from oxtornado import actions
|
|
|
|
|
2014-05-04 19:26:43 +02:00
|
|
|
import item.api
|
|
|
|
import user.api
|
2014-08-22 19:46:45 +02:00
|
|
|
import update
|
2014-05-19 01:24:04 +02:00
|
|
|
|
2016-02-23 13:45:37 +05:30
|
|
|
import logging
|
|
|
|
logger = logging.getLogger(__name__)
|
2014-05-19 22:14:24 +02:00
|
|
|
|
2019-01-20 18:40:04 +05:30
|
|
|
def win32_ui(type):
|
|
|
|
base = normpath(dirname(dirname(dirname(abspath(__file__)))))
|
|
|
|
cmd = [
|
|
|
|
join(base, 'platform_win32', 'python.exe'),
|
|
|
|
join(base, 'openmediablirary', 'oml', 'ui.py'), type
|
|
|
|
]
|
|
|
|
return cmd
|
|
|
|
|
2014-05-19 22:14:24 +02:00
|
|
|
def selectFolder(data):
|
2014-05-19 01:24:04 +02:00
|
|
|
'''
|
|
|
|
returns {
|
|
|
|
path
|
|
|
|
}
|
|
|
|
'''
|
|
|
|
cmd = ['./ctl', 'ui', 'folder']
|
2019-01-20 18:40:04 +05:30
|
|
|
if sys.platform == 'win32':
|
|
|
|
cmd = win32_ui('folder')
|
2014-08-22 18:49:11 +02:00
|
|
|
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, close_fds=True)
|
2014-05-19 01:24:04 +02:00
|
|
|
stdout, stderr = p.communicate()
|
|
|
|
path = stdout.decode('utf-8').strip()
|
|
|
|
return {
|
|
|
|
'path': path
|
|
|
|
}
|
|
|
|
actions.register(selectFolder, cache=False)
|
|
|
|
|
2014-05-19 22:14:24 +02:00
|
|
|
|
|
|
|
def selectFile(data):
|
2014-05-19 01:24:04 +02:00
|
|
|
'''
|
|
|
|
returns {
|
|
|
|
path
|
|
|
|
}
|
|
|
|
'''
|
|
|
|
cmd = ['./ctl', 'ui', 'file']
|
2019-01-20 18:40:04 +05:30
|
|
|
if sys.platform == 'win32':
|
|
|
|
cmd = win32_ui('file')
|
2014-05-19 01:24:04 +02:00
|
|
|
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 22:14:24 +02:00
|
|
|
|
|
|
|
def autocompleteFolder(data):
|
2014-05-19 01:24:04 +02: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):
|
2014-09-03 00:32:44 +02:00
|
|
|
prefix, folders, files = next(os.walk(folder))
|
2014-05-19 20:12:02 +02:00
|
|
|
folders = [os.path.join(prefix, f) for f in folders if (not name or f.startswith(name)) and not f.startswith('.')]
|
2014-05-19 01:24:04 +02:00
|
|
|
if prefix == path:
|
|
|
|
folders = [path] + folders
|
|
|
|
else:
|
|
|
|
folders = []
|
|
|
|
return {
|
|
|
|
'items': ox.sorted_strings(folders)
|
|
|
|
}
|
|
|
|
actions.register(autocompleteFolder, cache=False)
|
2016-01-08 10:02:24 +05:30
|
|
|
|
|
|
|
def quit(data):
|
|
|
|
'''
|
|
|
|
takes {
|
|
|
|
}
|
|
|
|
returns {
|
|
|
|
}
|
|
|
|
'''
|
2016-01-31 22:16:28 +05:30
|
|
|
import state
|
|
|
|
state.main.stop()
|
2016-01-08 10:02:24 +05:30
|
|
|
return {}
|
|
|
|
actions.register(quit, cache=False)
|
2016-02-23 13:45:37 +05:30
|
|
|
|
|
|
|
def logError(data):
|
|
|
|
'''
|
|
|
|
takes {
|
|
|
|
}
|
|
|
|
returns {
|
|
|
|
}
|
|
|
|
'''
|
|
|
|
#logger.debug('frontend error %s', data)
|
|
|
|
return {}
|
|
|
|
actions.register(logError, cache=False)
|