Switched event system (again)

This commit is contained in:
Ruud
2011-03-01 11:12:56 +01:00
parent fd5a41435b
commit f9523444f4
24 changed files with 580 additions and 142 deletions
+4
View File
@@ -0,0 +1,4 @@
class Plugin():
def __init__(self):
pass
@@ -0,0 +1,6 @@
from couchpotato.core.plugins.file_browser.main import FileBrowser
def start():
return FileBrowser()
config = []
@@ -0,0 +1,56 @@
from couchpotato.api import addApiView
from couchpotato.environment import Env
from flask.helpers import jsonify
import os
import string
if os.name == 'nt':
import win32file
class FileBrowser():
def __init__(self, path = '/'):
self.path = path
addApiView('directory.list', self.view)
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
def view(self):
try:
fb = FileBrowser(Env.getParam('path', '/'))
dirs = fb.getDirectories()
except:
dirs = []
return jsonify({
'empty': len(dirs) == 0,
'dirs': dirs,
})
@@ -0,0 +1,6 @@
from couchpotato.core.plugins.movie_add.main import MovieAdd
def start():
return MovieAdd()
config = []
@@ -0,0 +1,30 @@
from couchpotato.api import addApiView
from couchpotato.core.event import getEvent, fireEvent
from couchpotato.core.plugins.base import Plugin
from couchpotato.environment import Env
from flask.helpers import jsonify
class MovieAdd(Plugin):
def __init__(self):
addApiView('movie.add.search', self.search)
def search(self):
a = Env.getParams()
print fireEvent('provider.movie.search', q = a.get('q'))
movies = [
{'id': 1, 'name': 'test'}
]
return jsonify({
'success': True,
'empty': len(movies) == 0,
'movies': movies,
})
def select(self):
pass
@@ -1,3 +1,6 @@
def start():
pass
config = [{
'name': 'Renamer',
'tab': 'renaming',