From 1e36aeced3dddb8df74d93f71b9348aea774275f Mon Sep 17 00:00:00 2001 From: Ruud Date: Mon, 5 Sep 2011 22:09:54 +0200 Subject: [PATCH] Settings, directory browser --- couchpotato/core/helpers/variable.py | 3 +- couchpotato/core/plugins/__init__.py | 74 ----------- couchpotato/core/plugins/browser/main.py | 18 ++- couchpotato/core/plugins/library/main.py | 4 +- couchpotato/core/plugins/movie/main.py | 27 ++-- couchpotato/core/plugins/wizard/__init__.py | 2 +- .../torrent/thepiratebay/__init__.py | 20 +-- couchpotato/core/settings/__init__.py | 8 +- couchpotato/static/images/icon.folder.gif | Bin 0 -> 757 bytes couchpotato/static/images/right.arrow.png | Bin 0 -> 223 bytes .../library/form_replacement/form_check.js | 1 + couchpotato/static/scripts/page/settings.js | 106 +++++++++------ couchpotato/static/style/page/settings.css | 125 ++++++++++++++---- 13 files changed, 208 insertions(+), 180 deletions(-) create mode 100644 couchpotato/static/images/icon.folder.gif create mode 100644 couchpotato/static/images/right.arrow.png diff --git a/couchpotato/core/helpers/variable.py b/couchpotato/core/helpers/variable.py index 208709d1..dc92f6a0 100644 --- a/couchpotato/core/helpers/variable.py +++ b/couchpotato/core/helpers/variable.py @@ -4,7 +4,6 @@ import os.path def isDict(object): return isinstance(object, dict) - def mergeDicts(a, b): assert isDict(a), isDict(b) dst = a.copy() @@ -16,7 +15,7 @@ def mergeDicts(a, b): if key not in current_dst: current_dst[key] = current_src[key] else: - if isDict(current_src[key]) and isDict(current_dst[key]) : + if isDict(current_src[key]) and isDict(current_dst[key]): stack.append((current_dst[key], current_src[key])) else: current_dst[key] = current_src[key] diff --git a/couchpotato/core/plugins/__init__.py b/couchpotato/core/plugins/__init__.py index 84714c75..8b137891 100644 --- a/couchpotato/core/plugins/__init__.py +++ b/couchpotato/core/plugins/__init__.py @@ -1,75 +1 @@ -from uuid import uuid4 - -def start(): - pass - -config = [{ - 'name': 'core', - 'groups': [ - { - 'tab': 'general', - 'name': 'basics', - 'description': 'Needs restart before changes take effect.', - 'options': [ - { - 'name': 'username', - 'default': '', - }, - { - 'name': 'password', - 'default': '', - 'type': 'password', - }, - { - 'name': 'host', - 'advanced': True, - 'default': '0.0.0.0', - 'label': 'IP', - 'description': 'Host that I should listen to. "0.0.0.0" listens to all ips.', - }, - { - 'name': 'port', - 'default': 5000, - 'type': 'int', - 'description': 'The port I should listen to.', - }, - { - 'name': 'launch_browser', - 'default': 1, - 'type': 'bool', - 'label': 'Launch Browser', - 'description': 'Launch the browser when I start.', - }, - ], - }, - { - 'tab': 'general', - 'name': 'advanced', - 'description': "For those who know what the're doing", - 'advanced': True, - 'options': [ - { - 'name': 'api_key', - 'default': uuid4().hex, - 'readonly': 1, - 'label': 'Api Key', - 'description': "This is top-secret! Don't share this!", - }, - { - 'name': 'debug', - 'default': 0, - 'type': 'bool', - 'label': 'Debug', - 'description': 'Enable debugging.', - }, - { - 'name': 'url_base', - 'default': '', - 'label': 'Url Base', - 'description': 'When using mod_proxy use this to append the url with this.', - }, - ], - }, - ], -}] diff --git a/couchpotato/core/plugins/browser/main.py b/couchpotato/core/plugins/browser/main.py index d4829b40..d1d23730 100644 --- a/couchpotato/core/plugins/browser/main.py +++ b/couchpotato/core/plugins/browser/main.py @@ -1,6 +1,7 @@ from couchpotato.api import addApiView from couchpotato.core.helpers.request import getParam, jsonified from couchpotato.core.plugins.base import Plugin +import ctypes import os import string @@ -23,7 +24,7 @@ class FileBrowser(Plugin): dirs = [] for f in os.listdir(path): p = os.path.join(path, f) - if(os.path.isdir(p)): + if os.path.isdir(p) and ((self.is_hidden(p) and bool(int(show_hidden))) or not self.is_hidden(p)): dirs.append(p + '/') return dirs @@ -48,6 +49,21 @@ class FileBrowser(Plugin): dirs = [] return jsonified({ + 'is_root': getParam('path', '/') == '/', 'empty': len(dirs) == 0, 'dirs': dirs, }) + + + def is_hidden(self, filepath): + name = os.path.basename(os.path.abspath(filepath)) + return name.startswith('.') or self.has_hidden_attribute(filepath) + + def has_hidden_attribute(self, filepath): + try: + attrs = ctypes.windll.kernel32.GetFileAttributesW(unicode(filepath)) + assert attrs != -1 + result = bool(attrs & 2) + except (AttributeError, AssertionError): + result = False + return result diff --git a/couchpotato/core/plugins/library/main.py b/couchpotato/core/plugins/library/main.py index 77179b0a..d9876f1f 100644 --- a/couchpotato/core/plugins/library/main.py +++ b/couchpotato/core/plugins/library/main.py @@ -51,7 +51,9 @@ class LibraryPlugin(Plugin): library = db.query(Library).filter_by(identifier = identifier).first() done_status = fireEvent('status.get', 'done', single = True) - library_dict = library.to_dict(self.default_dict) + if library: + library_dict = library.to_dict(self.default_dict) + do_update = True if library.status_id == done_status.get('id') and not force: diff --git a/couchpotato/core/plugins/movie/main.py b/couchpotato/core/plugins/movie/main.py index c20048ad..2df4fa5e 100644 --- a/couchpotato/core/plugins/movie/main.py +++ b/couchpotato/core/plugins/movie/main.py @@ -10,6 +10,14 @@ from urllib import urlencode class MoviePlugin(Plugin): + default_dict = { + 'profile': {'types': {'quality': {}}}, + 'releases': {'status': {}, 'quality': {}, 'files':{}, 'info': {}}, + 'library': {'titles': {}, 'files':{}}, + 'files': {}, + 'status': {} + } + def __init__(self): addApiView('movie.search', self.search) addApiView('movie.list', self.list) @@ -30,12 +38,7 @@ class MoviePlugin(Plugin): movies = [] for movie in results: - temp = movie.to_dict(deep = { - 'releases': {'status': {}, 'quality': {}, 'files':{}, 'info': {}}, - 'library': {'titles': {}, 'files':{}}, - 'files': {} - }) - + temp = movie.to_dict(self.default_dict) movies.append(temp) return jsonified({ @@ -59,12 +62,7 @@ class MoviePlugin(Plugin): if movie: #addEvent('library.update.after', ) fireEventAsync('library.update', identifier = movie.library.identifier, default_title = default_title, force = True) - fireEventAsync('searcher.single', movie.to_dict(deep = { - 'profile': {'types': {'quality': {}}}, - 'releases': {'status': {}, 'quality': {}, 'files': {}, 'info': {}}, - 'library': {'titles': {}, 'files':{}}, - 'files': {} - })) + fireEventAsync('searcher.single', movie.to_dict(self.default_dict)) return jsonified({ 'success': True, @@ -119,10 +117,7 @@ class MoviePlugin(Plugin): m.status_id = status_active.get('id') db.commit() - movie_dict = m.to_dict(deep = { - 'releases': {'status': {}, 'quality': {}, 'files': {}, 'info': {}}, - 'library': {'titles': {}} - }) + movie_dict = m.to_dict(self.default_dict) return jsonified({ 'success': True, diff --git a/couchpotato/core/plugins/wizard/__init__.py b/couchpotato/core/plugins/wizard/__init__.py index 7ee4a45c..78876470 100644 --- a/couchpotato/core/plugins/wizard/__init__.py +++ b/couchpotato/core/plugins/wizard/__init__.py @@ -4,7 +4,7 @@ def start(): return Wizard() config = [{ - 'name': 'global', + 'name': 'core', 'groups': [ { 'tab': 'general', diff --git a/couchpotato/core/providers/torrent/thepiratebay/__init__.py b/couchpotato/core/providers/torrent/thepiratebay/__init__.py index 1e154ce0..810e713a 100644 --- a/couchpotato/core/providers/torrent/thepiratebay/__init__.py +++ b/couchpotato/core/providers/torrent/thepiratebay/__init__.py @@ -3,22 +3,4 @@ from .main import ThePirateBay def start(): return ThePirateBay() -config = [{ - 'name': 'themoviedb', - 'groups': [ - { - 'tab': 'providers', - 'name': 'tmdb', - 'label': 'TheMovieDB', - 'advanced': True, - 'description': 'Used for all calls to TheMovieDB.', - 'options': [ - { - 'name': 'api_key', - 'default': '9b939aee0aaafc12a65bf448e4af9543', - 'label': 'Api Key', - }, - ], - }, - ], -}] +config = [] diff --git a/couchpotato/core/settings/__init__.py b/couchpotato/core/settings/__init__.py index 1c462932..77813586 100644 --- a/couchpotato/core/settings/__init__.py +++ b/couchpotato/core/settings/__init__.py @@ -3,6 +3,7 @@ from couchpotato.api import addApiView from couchpotato.core.event import addEvent from couchpotato.core.helpers.encoding import isInt from couchpotato.core.helpers.request import getParams, jsonified +from couchpotato.core.helpers.variable import mergeDicts import ConfigParser import os.path import time @@ -93,7 +94,12 @@ class Settings(): self.p.set(section, option, value) def addOptions(self, section_name, options): - self.options[section_name] = options + + if not self.options.get(section_name): + self.options[section_name] = options + else: + options['groups'] = self.options[section_name].get('groups') + options.get('groups') + self.options[section_name] = mergeDicts(self.options[section_name], options) def getOptions(self): return self.options diff --git a/couchpotato/static/images/icon.folder.gif b/couchpotato/static/images/icon.folder.gif new file mode 100644 index 0000000000000000000000000000000000000000..e19ce53aa6c6129b5836d19b2ff45af23b8d311f GIT binary patch literal 757 zcmVu$<~}@0ZK5J>yv!Nq-h0mX|7W-t_|L(1KknZ; zH`!^FFDVfe{lHr(Ribq+*iy{I?TN|v)qeu+UL7B>9QFG8or$g{lUGrgpTp#X$1_Yb z-ib&pN?>7mtFZWNdabw%(Ce?Wqr-Vi_y$#DL;FXN>dGha8jw20j-UoKUD>XqL5NS zBWLZl1w%K&7Jv&`bxT?lc+?K57$&vjgGZz+MZMofv7%stQ4ZOvM+?9s#X~FbTv{h* zN;MA(mC?yyWR~I|VO6>$=I;}-8 z8EXNyw~J#_uRe|m&QEnD?7>Xh?&#m2Lsu>VGe$}pC6RTox--H{PRAiu`|U3LI&NM# zJP-w9MAz8SL_BsZVVm7q$7cQASWnfXWmdz|6H_V+Po~-c6*YRgIEGZ*O8WEvzdiHD2F}i0_MD^ON>SZO}|(dt~j=b)Lac+3cu7YxM<@ zO-aU*>zz`LvWO~a&-3$8