2014-05-04 17:26:43 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# vi:si:et:sw=4:sts=4:ts=4
|
2014-09-02 22:32:44 +00:00
|
|
|
|
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-05-04 17:26:43 +00:00
|
|
|
import item.api
|
|
|
|
import user.api
|
2014-08-22 17:46:45 +00:00
|
|
|
import update
|
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']
|
2014-08-22 16:49:11 +00:00
|
|
|
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, close_fds=True)
|
2014-05-18 23:24:04 +00:00
|
|
|
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):
|
2014-09-02 22:32:44 +00:00
|
|
|
prefix, folders, files = next(os.walk(folder))
|
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)
|