Switched event system (again)
This commit is contained in:
@@ -1,42 +1,20 @@
|
||||
from couchpotato.api.file_browser import FileBrowser
|
||||
from couchpotato.core.settings.loader import settings_loader
|
||||
from couchpotato.core.settings.model import Resource
|
||||
from couchpotato.environment import Env
|
||||
from flask import Module
|
||||
from flask.helpers import jsonify
|
||||
import flask
|
||||
|
||||
api = Module(__name__)
|
||||
|
||||
def addApiView(route, func):
|
||||
api.add_url_rule(route + '/', route, func)
|
||||
|
||||
|
||||
@api.route('')
|
||||
def index():
|
||||
return jsonify({'test': 'bla'})
|
||||
|
||||
|
||||
@api.route('settings/')
|
||||
def settings_view():
|
||||
return jsonify({
|
||||
'sections': settings_loader.sections,
|
||||
'values': Env.get('settings').getValues()
|
||||
})
|
||||
|
||||
@api.route('setting.save/')
|
||||
def setting_save_view():
|
||||
a = flask.request.args
|
||||
|
||||
section = a.get('section')
|
||||
option = a.get('name')
|
||||
value = a.get('value')
|
||||
|
||||
Env.setting(option, section, value).save()
|
||||
|
||||
return jsonify({
|
||||
'success': True,
|
||||
});
|
||||
|
||||
@api.route('movie/')
|
||||
def movie():
|
||||
|
||||
return jsonify({
|
||||
'success': True,
|
||||
'movies': [
|
||||
@@ -50,18 +28,3 @@ def movie():
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
@api.route('directory.list/')
|
||||
def director_list():
|
||||
a = flask.request.args
|
||||
|
||||
try:
|
||||
fb = FileBrowser(a.get('path', '/'))
|
||||
dirs = fb.getDirectories()
|
||||
except:
|
||||
dirs = []
|
||||
|
||||
return jsonify({
|
||||
'empty': len(dirs) == 0,
|
||||
'dirs': dirs,
|
||||
})
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
import os
|
||||
import string
|
||||
|
||||
if os.name == 'nt':
|
||||
import win32file
|
||||
|
||||
class FileBrowser():
|
||||
|
||||
def __init__(self, path = '/'):
|
||||
self.path = path
|
||||
|
||||
def getDirectories(self):
|
||||
|
||||
# Return driveletters or root if path is empty
|
||||
if self.path == '/' or not self.path:
|
||||
if os.name == 'nt':
|
||||
return self.getDriveLetters()
|
||||
self.path = '/'
|
||||
|
||||
dirs = []
|
||||
for f in os.listdir(self.path):
|
||||
path = os.path.join(self.path, f)
|
||||
if(os.path.isdir(path)):
|
||||
dirs.append(path)
|
||||
|
||||
return dirs
|
||||
|
||||
def getFiles(self):
|
||||
pass
|
||||
|
||||
def getDriveLetters(self):
|
||||
|
||||
driveletters = []
|
||||
for drive in string.ascii_uppercase:
|
||||
if win32file.GetDriveType(drive + ":") == win32file.DRIVE_FIXED:
|
||||
driveletters.append(drive + ":")
|
||||
|
||||
return driveletters
|
||||
Reference in New Issue
Block a user