From 894e419f4068915765d960fb3514596b1fdda47f Mon Sep 17 00:00:00 2001 From: Ruud Date: Wed, 15 Jan 2014 21:08:19 +0100 Subject: [PATCH] Allow config delete --- couchpotato/core/downloaders/rtorrent/main.py | 31 +++++++++++++------ couchpotato/core/plugins/base.py | 7 +++-- couchpotato/core/settings/__init__.py | 3 ++ 3 files changed, 30 insertions(+), 11 deletions(-) diff --git a/couchpotato/core/downloaders/rtorrent/main.py b/couchpotato/core/downloaders/rtorrent/main.py index 7dc6abbf..92a21772 100755 --- a/couchpotato/core/downloaders/rtorrent/main.py +++ b/couchpotato/core/downloaders/rtorrent/main.py @@ -1,9 +1,9 @@ from base64 import b16encode, b32decode from bencode import bencode, bdecode from couchpotato.core.downloaders.base import Downloader, ReleaseDownloadList -from couchpotato.core.event import fireEvent +from couchpotato.core.event import fireEvent, addEvent from couchpotato.core.helpers.encoding import sp -from couchpotato.core.helpers.variable import cleanHost +from couchpotato.core.helpers.variable import cleanHost, splitString from couchpotato.core.logger import CPLog from datetime import timedelta from hashlib import sha1 @@ -22,11 +22,24 @@ class rTorrent(Downloader): # Migration url to host options def __init__(self): super(rTorrent, self).__init__() - if self.conf('url'): - self.conf('ssl', value = (self.conf('url').split('://')[0].strip() == 'https')) - self.conf('host', value = self.conf('url').split('://')[-1].split('/')[0].strip()) - self.conf('rpc_url', value = self.conf('url').split('://')[-1].split('/',1)[1].strip('/ ')) - self.conf('url', value = '') + + addEvent('app.load', self.migrate) + + def migrate(self): + + url = self.conf('url') + if url: + print url + + url = 'http://localhost:8080/RPC2teasd/asdasd//' + host_split = splitString(url.split('://')[-1], split_on = '/') + + self.conf('ssl', value = url.startswith('https')) + self.conf('host', value = host_split[0].strip()) + self.conf('rpc_url', value = '/'.join(host_split[1:])) + + self.deleteConf('url') + #self.conf('url', value = '') def connect(self): # Already connected? @@ -167,14 +180,14 @@ class rTorrent(Downloader): torrent_files = [] for file_item in torrent.get_files(): torrent_files.append(sp(os.path.join(torrent.directory, file_item.path))) - + status = 'busy' if torrent.complete: if torrent.active: status = 'seeding' else: status = 'completed' - + release_downloads.append({ 'id': torrent.info_hash, 'name': torrent.name, diff --git a/couchpotato/core/plugins/base.py b/couchpotato/core/plugins/base.py index 588a2030..0296af50 100644 --- a/couchpotato/core/plugins/base.py +++ b/couchpotato/core/plugins/base.py @@ -52,8 +52,11 @@ class Plugin(object): self.registerStatic(inspect.getfile(self.__class__)) def conf(self, attr, value = None, default = None, section = None): - class_name = self.getName().lower().split(':') - return Env.setting(attr, section = section if section else class_name[0].lower(), value = value, default = default) + class_name = self.getName().lower().split(':')[0].lower() + return Env.setting(attr, section = section if section else class_name, value = value, default = default) + + def deleteConf(self, attr): + return Env._settings.delete(attr, section = self.getName().lower().split(':')[0].lower()) def getName(self): return self._class_name or self.__class__.__name__ diff --git a/couchpotato/core/settings/__init__.py b/couchpotato/core/settings/__init__.py index 61d982f2..e2c82117 100644 --- a/couchpotato/core/settings/__init__.py +++ b/couchpotato/core/settings/__init__.py @@ -110,6 +110,9 @@ class Settings(object): except: return default + def delete(self, option = '', section = 'core'): + self.p.remove_option(section, option) + def getEnabler(self, section, option): return self.getBool(section, option)