add option to open folder

This commit is contained in:
j 2015-11-30 17:50:03 +01:00
commit 216cb411fe
3 changed files with 33 additions and 0 deletions

View file

@ -2,6 +2,7 @@
# vi:si:et:sw=4:sts=4:ts=4
import json
import hashlib
import os
from sqlalchemy.orm import load_only
from sqlalchemy import func
@ -331,3 +332,13 @@ def cancelImport(data):
})
return {}
actions.register(cancelImport, cache=False)
def openFolder(data):
response = {}
item = models.Item.get(data['id'])
if item:
path = item.get_path()
if path:
utils.open_folder(os.path.dirname(path))
return response
actions.register(openFolder, cache=False)

View file

@ -329,3 +329,10 @@ def makefolder(path):
dirname = os.path.dirname(path)
if not os.path.exists(dirname):
os.makedirs(dirname)
def open_folder(folder):
cmd = 'open'
if sys.platform.startswith('linux'):
cmd = 'xdg-open'
subprocess.Popen([cmd, folder], close_fds=True)