CouchPotato: rework addon

Signed-off-by: Stephan Raue <stephan@openelec.tv>
This commit is contained in:
Stephan Raue 2011-04-24 17:18:21 +02:00
parent 4ea36c414b
commit e2284d1a31
13 changed files with 386 additions and 173 deletions

View File

@ -20,13 +20,13 @@
################################################################################ ################################################################################
PKG_NAME="CouchPotato" PKG_NAME="CouchPotato"
PKG_VERSION="datadir" PKG_VERSION="ded60e1"
PKG_REV="1" PKG_REV="1"
PKG_ARCH="any" PKG_ARCH="any"
PKG_LICENSE="OSS" PKG_LICENSE="OSS"
PKG_SITE="https://github.com/travisghansen/CouchPotato.git" PKG_SITE="https://github.com/RuudBurger/CouchPotato"
PKG_URL="http://antant.openelec.tv/$PKG_NAME-$PKG_VERSION.tar.bz2" PKG_URL="$OPENELEC_SRC/$PKG_NAME-$PKG_VERSION.tar.bz2"
PKG_DEPENDS="Python Cheetah SABnzbd" PKG_DEPENDS="Python SABnzbd"
PKG_BUILD_DEPENDS="toolchain Python" PKG_BUILD_DEPENDS="toolchain Python"
PKG_PRIORITY="optional" PKG_PRIORITY="optional"
PKG_SECTION="downloadmanager" PKG_SECTION="downloadmanager"
@ -35,5 +35,6 @@ PKG_LONGDESC="CouchPotato: automated movie downloading."
PKG_IS_ADDON="yes" PKG_IS_ADDON="yes"
PKG_ADDON_TYPE="xbmc.service" PKG_ADDON_TYPE="xbmc.service"
PKG_ADDON_REQUIRES="addon.downloadmanager.SABnzbd:0.99.1"
PKG_AUTORECONF="no" PKG_AUTORECONF="no"

View File

@ -1,49 +0,0 @@
From 16f5fe91074fb59cda5762d0d296bcd09b44c10c Mon Sep 17 00:00:00 2001
From: Anthony Nash <nash.ant@gmail.com>
Date: Wed, 20 Apr 2011 15:58:16 +0100
Subject: [PATCH] Remove port, updater and browser fields
---
app/views/config/index.html | 19 -------------------
1 files changed, 0 insertions(+), 19 deletions(-)
diff --git a/app/views/config/index.html b/app/views/config/index.html
index 8fe9f06..58b1656 100644
--- a/app/views/config/index.html
+++ b/app/views/config/index.html
@@ -20,10 +20,6 @@
<input type="text" name="global.host" value="${config.get('global', 'host')}" class="textInput large"/>
</div>
<div class="ctrlHolder">
- <label>Port</label>
- <input type="text" name="global.port" value="${config.get('global', 'port')}" class="textInput large"/>
- </div>
- <div class="ctrlHolder">
<label>Username</label>
<input type="text" name="global.username" value="${config.get('global', 'username')}" autocomplete="off" class="textInput large"/>
</div>
@@ -31,21 +27,6 @@
<label>Password</label>
<input type="password" name="global.password" value="${config.get('global', 'password')}" autocomplete="off" class="textInput large"/>
</div>
- <div class="ctrlHolder">
- <label>Launch browser</label>
- <input type="checkbox" name="global.launchbrowser" value="True" ${' checked="checked"' if config.get('global', 'launchbrowser') else ''} />
- </div>
- <div class="ctrlHolder checkbox">
- <label>Use updater</label>
- <% hasGit = updater.hasGit() %>
- <input type="checkbox" name="global.updater" value="True" ${' checked="checked"' if config.get('global', 'updater') and not hasGit else ''} ${' disabled="disabled"' if hasGit else ''} />
- % if hasGit:
- <p class="formHint">
- To enable the CouchPotato Updater, remove the ".git" folder.
- Otherwise use "git pull".
- </p>
- % endif
- </div>
</fieldset>
<fieldset class="inlineLabels">
<h3>Search</h3>
--
1.7.4.4

View File

@ -1,31 +0,0 @@
From a2196e61c14dd0437754406d007ae6e8273eb9a6 Mon Sep 17 00:00:00 2001
From: Anthony Nash <nash.ant@gmail.com>
Date: Wed, 20 Apr 2011 16:00:07 +0100
Subject: [PATCH 2/2] Set defaults
---
app/config/configApp.py | 6 +++---
1 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/app/config/configApp.py b/app/config/configApp.py
index fb0e2d0..8247df6 100644
--- a/app/config/configApp.py
+++ b/app/config/configApp.py
@@ -39,11 +39,11 @@ class configApp():
self.addSection('global')
self.setDefault('global', 'server.environment', 'production')
self.setDefault('global', 'host', '0.0.0.0')
- self.setDefault('global', 'port', 5000)
+ self.setDefault('global', 'port', 8083)
self.setDefault('global', 'username', '')
self.setDefault('global', 'password', '')
- self.setDefault('global', 'launchbrowser', True)
- self.setDefault('global', 'updater', True)
+ self.setDefault('global', 'launchbrowser', False)
+ self.setDefault('global', 'updater', False)
self.setDefault('global', 'git', 'git')
self.setDefault('global', 'urlBase', '')
self.setDefault('global', 'ignoreWords', '')
--
1.7.4.4

View File

@ -0,0 +1,186 @@
diff -Naur CouchPotato-ded60e1/app/config/db.py CouchPotato-ded60e1.patch/app/config/db.py
--- CouchPotato-ded60e1/app/config/db.py 2011-04-23 19:55:33.000000000 +0200
+++ CouchPotato-ded60e1.patch/app/config/db.py 2011-04-23 20:26:44.495557932 +0200
@@ -10,6 +10,7 @@
import datetime
import os
import sys
+import app.config
log = CPLog(__name__)
@@ -24,7 +25,7 @@
else:
path = os.path.join(os.path.abspath(os.path.curdir), 'data.db')
else:
- path = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))), 'data.db')
+ path = os.path.join(app.config.DATADIR, 'data.db')
engine = create_engine('sqlite:///%s' % path)
metadata = MetaData(engine)
diff -Naur CouchPotato-ded60e1/app/config/__init__.py CouchPotato-ded60e1.patch/app/config/__init__.py
--- CouchPotato-ded60e1/app/config/__init__.py 2011-04-23 19:55:33.000000000 +0200
+++ CouchPotato-ded60e1.patch/app/config/__init__.py 2011-04-23 20:26:44.480558230 +0200
@@ -0,0 +1 @@
+DATADIR=None
diff -Naur CouchPotato-ded60e1/app/controllers/log.py CouchPotato-ded60e1.patch/app/controllers/log.py
--- CouchPotato-ded60e1/app/controllers/log.py 2011-04-23 19:55:33.000000000 +0200
+++ CouchPotato-ded60e1.patch/app/controllers/log.py 2011-04-23 20:26:44.505557734 +0200
@@ -4,6 +4,7 @@
from markupsafe import escape
import cherrypy
import os
+import app.config
log = CPLog(__name__)
file = 'CouchPotato.log'
@@ -56,7 +57,7 @@
return redirect(url(controller = 'log', action = 'index'))
def logDir(self):
- return os.path.join(cherrypy.config.get('runPath'), 'logs')
+ return os.path.join(app.config.DATADIR, 'logs')
def logFile(self):
return os.path.join(self.logDir(), file)
diff -Naur CouchPotato-ded60e1/CouchPotato.py CouchPotato-ded60e1.patch/CouchPotato.py
--- CouchPotato-ded60e1/CouchPotato.py 2011-04-23 19:55:33.000000000 +0200
+++ CouchPotato-ded60e1.patch/CouchPotato.py 2011-04-23 20:26:50.127445945 +0200
@@ -3,6 +3,7 @@
import os
rundir = os.path.dirname(os.path.abspath(__file__))
+
try:
frozen = sys.frozen
except AttributeError:
@@ -20,28 +21,9 @@
sys.path.insert(0, path_base)
sys.path.insert(0, os.path.join(path_base, 'library'))
-# Configure logging
-from app.config.cplog import CPLog
-debug = os.path.isfile(os.path.join(path_base, 'debug.conf'))
-log = CPLog()
-log.config(os.path.join(rundir, 'logs'), debug)
-
-# Create cache dir
-cachedir = os.path.join(rundir, 'cache')
-if not os.path.isdir(cachedir):
- os.mkdir(cachedir)
-
-import cherrypy
-import app.config.render
-from app.config.db import initDb
-from optparse import OptionParser
-from app.config.configApp import configApp
-from app.config.routes import setup as Routes
-from app.lib.cron import CronJobs
-from app.config.updater import Updater
-from cherrypy.process import plugins
-
def server_start():
+ from optparse import OptionParser
+
p = OptionParser()
p.add_option('-d', action = "store_true",
dest = 'daemonize', help = "Run the server as a daemon")
@@ -50,19 +32,80 @@
p.add_option('-p', '--pidfile',
dest = 'pidfile', default = None,
help = "Store the process id in the given file")
+ p.add_option('--config',
+ dest = 'config', default = None,
+ help = "Path to config.ini file")
+ p.add_option('--datadir',
+ dest = 'datadir', default = None,
+ help = "Path to the data directory")
+
options, args = p.parse_args()
+
+ if options.datadir:
+ datadir = options.datadir
+
+ if not os.path.isdir(datadir):
+ os.makedirs(datadir)
+
+ else:
+ datadir = rundir
+
+ datadir = os.path.abspath(datadir)
+
+ if not os.access(datadir, os.W_OK):
+ raise SystemExit("Data dir must be writeable '" + datadir + "'")
+
+ import app.config
+ app.config.DATADIR = datadir
+
+ if options.config:
+ config = options.config
+ else:
+ config = os.path.join(datadir, 'config.ini')
+
+ config = os.path.abspath(config)
- config = os.path.join(rundir, 'config.ini')
+ if not os.access(os.path.dirname(config), os.W_OK) and not os.access(config, os.W_OK):
+ if not os.path.exists(os.path.dirname(config)):
+ os.makedirs(os.path.dirname(config))
+ else:
+ raise SystemExit("Directory for config file must be writeable")
+
+ import cherrypy
+ import app.config.render
+
+ # Configure logging
+ from app.config.cplog import CPLog
+
+ # Setup logging
+ debug = os.path.isfile(os.path.join(datadir, 'debug.conf'))
+ log = CPLog()
+ log.config(os.path.join(datadir, 'logs'), debug)
+
+ # Create cache dir
+ cachedir = os.path.join(datadir, 'cache')
+ if not os.path.isdir(cachedir):
+ os.mkdir(cachedir)
# Stop logging
if options.quiet or options.daemonize:
cherrypy.config.update({'log.screen': False})
+
# Config app
+ from app.config.configApp import configApp
ca = configApp(config)
+
+ # Setup db
+ from app.config.db import initDb
initDb()
+ from app.config.routes import setup as Routes
+ from app.lib.cron import CronJobs
+ from app.config.updater import Updater
+ from cherrypy.process import plugins
+
# Check an see if CP is already running
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
@@ -129,7 +172,7 @@
},
'/cache':{
'tools.staticdir.on': True,
- 'tools.staticdir.root': rundir,
+ 'tools.staticdir.root': datadir,
'tools.staticdir.dir': "cache",
'tools.expires.on': True,
'tools.expires.secs': 3600 * 24 * 7
@@ -173,7 +216,6 @@
if hasattr(cherrypy.engine, "console_control_handler"):
cherrypy.engine.console_control_handler.subscribe()
-
## start the app
try:
cherrypy.engine.start()

View File

@ -0,0 +1,117 @@
#!/usr/bin/env python
################################################################################
# This file is part of OpenELEC - http://www.openelec.tv
# Copyright (C) 2011 Travis Glenn Hansen (travisghansen@openelec.tv)
#
# This Program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This Program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with OpenELEC.tv; see the file COPYING. If not, write to
# the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
# http://www.gnu.org/copyleft/gpl.html
################################################################################
from configobj import ConfigObj
import sys
import os
import string
python_major = sys.version_info[0]
python_minor = sys.version_info[1]
prog="ini_tool"
description="""Read/Write config files.
Examples:
%(prog)s --file config.ini --action read --option [section:]username
%(prog)s --file config.ini --action write --option [section:]username --value foo""" % {'prog':prog}
def option_required_error(option):
parser.print_usage()
print prog + ": error: " + option + " is required"
exit(2)
if python_major > 2 or (python_major == 2 and python_minor >= 7):
import argparse
parser = argparse.ArgumentParser(
prog=prog,
description=description,
formatter_class=argparse.RawDescriptionHelpFormatter,
)
parser.add_argument('--file', help='file to read/write to/from', required=True)
parser.add_argument('--action', help='read|write', required=True)
parser.add_argument('--option', help='the option key', required=True)
parser.add_argument('--value', help='value to store in the given option (only for write action)')
options = parser.parse_args()
else:
import optparse
parser = optparse.OptionParser(
prog=prog,
description=description,
)
parser.add_option('--file', help='file to read/write to/from')
parser.add_option('--action', help='read|write')
parser.add_option('--option', help='the option key')
parser.add_option('--value', help='value to store in the given option (only for write action)')
(options, args) = parser.parse_args()
if not options.file:
option_required_error("--file")
if not options.action:
option_required_error("--action")
if not options.option:
option_required_error("--option")
if options.action != "read" and options.action != "write":
print "'" + options.action + "' is not a valid action"
parser.print_help()
exit(2)
if options.action == "read" and not os.path.isfile(options.file):
print "'" + options.file + "' is not a file"
exit(2)
config = ConfigObj(options.file)
keys = string.split(options.option, ":")
key_len = len(keys)
current_section = config
if options.action == 'read':
i = 1
for key in keys:
if i == key_len:
print current_section[key]
exit(0)
else:
current_section = current_section[key]
i += 1
elif options.action == 'write':
i = 1
for key in keys:
if i == key_len:
current_section[key] = options.value
elif key not in current_section:
current_section[key] = {}
current_section = current_section[key]
i += 1
config.write()
else:
exit(1)

View File

@ -23,4 +23,4 @@ import xbmcaddon
import os import os
if ( __name__ == "__main__" ): if ( __name__ == "__main__" ):
os.system("sh start.sh") os.system("start.sh")

View File

@ -1,13 +0,0 @@
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<strings>
<!-- CouchPotato -->
<string id="1000">CouchPotato</string>
<string id="1010">Gebruikers instellingen</string>
<string id="1021">Gebruik verificatie</string>
<string id="1022">Gebruikersnaam</string>
<string id="1023">Wachtwoord</string>
<string id="2010">Netwerk instellingen</string>
<string id="2021">Toegestane IP adressen</string>
</strings>

View File

@ -1,13 +0,0 @@
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<strings>
<!-- CouchPotato -->
<string id="1000">CouchPotato</string>
<string id="1010">User Settings</string>
<string id="1021">Use authentification</string>
<string id="1022">Username</string>
<string id="1023">Password</string>
<string id="2010">Network Settings</string>
<string id="2021">Allowed IP addresses</string>
</strings>

View File

@ -1,13 +0,0 @@
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<strings>
<!-- CouchPotato -->
<string id="1000">CouchPotato</string>
<string id="1010">Préférences utilisateur</string>
<string id="1021">Utiliser une authentification</string>
<string id="1022">Nom d'utilisateur</string>
<string id="1023">Mot de passe</string>
<string id="2010">Préférences réseau</string>
<string id="2021">Adresses IP autorisées</string>
</strings>

View File

@ -1,13 +0,0 @@
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<strings>
<!-- CouchPotato -->
<string id="1000">CouchPotato</string>
<string id="1010">Benutzer Einstellungen</string>
<string id="1021">Authentifizierung verwenden</string>
<string id="1022">Benutzername</string>
<string id="1023">Passwort</string>
<string id="2010">Netzwerk Einstellungen</string>
<string id="2021">Erlaubte IP Adressen</string>
</strings>

View File

@ -1,13 +0,0 @@
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<strings>
<!-- CouchPotato -->
<string id="1000">CouchPotato</string>
<string id="1010">Bruker Instillinger</string>
<string id="1021">Bruk inlogging</string>
<string id="1022">Brukernavn</string>
<string id="1023">Passord</string>
<string id="2010">Nettverksinstillinger</string>
<string id="2021">Tilatte IP addresser</string>
</strings>

View File

@ -1,16 +0,0 @@
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<settings>
<!-- CouchPotato -->
<category label="1000">
<setting label="1010" type="lsep"/>
<setting type="sep" />
<setting id="COUCHPOTATO_AUTH" type="bool" label="1021" default="false" />
<setting id="COUCHPOTATO_USER" type="text" label="1022" default="openelec" enable="eq(-1,true)"/>
<setting id="COUCHPOTATO_PWD" type="text" label="1023" default="openelec" enable="eq(-2,true)"/>
<setting label="2010" type="lsep"/>
<setting type="sep" />
<setting id="COUCHPOTATO_IP" type="text" label="2021" default="0.0.0.0"/>
</category>
</settings>

View File

@ -21,12 +21,82 @@
# http://www.gnu.org/copyleft/gpl.html # http://www.gnu.org/copyleft/gpl.html
################################################################################ ################################################################################
COUCHPOTATO_HOME="$HOME/.xbmc/userdata/addon_data/addon.downloadmanager.CouchPotato" export PATH="$PATH:./bin"
COUCHPOTATO_SETTINGS="$COUCHPOTATO_HOME/settings.xml" export PYTHONPATH="$PYTHONPATH:./pylib"
mkdir -p /var/run COUCHPOTATO_HOME="$HOME/.xbmc/userdata/addon_data/addon.downloadmanager.CouchPotato"
mkdir -p $COUCHPOTATO_HOME SABNZBD_SETTINGS="$HOME/.xbmc/userdata/addon_data/addon.downloadmanager.SABnzbd/sabnzbd.ini"
XBMC_SETTINGS="$HOME/.xbmc/userdata/guisettings.xml"
python ./CouchPotato/CouchPotato.py -d \ write_ini() {
--pidfile=/var/run/couchpotato.pid \ python bin/ini_tool --action=write \
--datadir $COUCHPOTATO_HOME --file=$COUCHPOTATO_HOME/config.ini \
--option="$1:$2" \
--value="$3"
}
read_sabconfig() {
python bin/ini_tool --action=read \
--file=$SABNZBD_SETTINGS \
--option="$1:$2"
}
read_xbmcconfig() {
grep "<$1>" $XBMC_SETTINGS | sed -e "s,[[:space:]]*<$1>,," -e "s,</$1>,,"
}
mkdir -p $COUCHPOTATO_HOME
chmod +x ./bin/*
sleep 5
if [ ! -f "$COUCHPOTATO_HOME/config.ini" ]; then
COUCHPOTATO_FIRSTRUN="yes"
fi
# default values
COUCHPOTATO_LAUNCHBROWSER="False"
COUCHPOTATO_VERSIONCHECK="False"
COUCHPOTATO_PORT="8083"
COUCHPOTATO_USEXBMC="True"
COUCHPOTATO_UPDATEXBMC="True"
# read xbmc settings
XBMC_HOST="127.0.0.1"
XBMC_PORT=`read_xbmcconfig webserverport`
XBMC_USER=`read_xbmcconfig webserverusername`
XBMC_PWD=`read_xbmcconfig webserverpassword`
# read sabnzbd settings
SABNZBD_HOST="127.0.0.1"
SABNZBD_PORT="8081"
SABNZBD_APIKEY=`read_sabconfig misc api_key`
SABNZBD_WEBUSERNAME=`read_sabconfig misc username`
SABNZBD_WEBPASSWORD=`read_sabconfig misc password`
if [ -z "$COUCHPOTATO_HOST" ]; then
COUCHPOTATO_HOST="0.0.0.0"
fi
write_ini global host $COUCHPOTATO_HOST
write_ini global port $COUCHPOTATO_PORT
write_ini global username $SABNZBD_WEBUSERNAME
write_ini global password $SABNZBD_WEBPASSWORD
write_ini global launchbrowser $COUCHPOTATO_LAUNCHBROWSER
write_ini global updater $COUCHPOTATO_VERSIONCHECK
write_ini Sabnzbd username $SABNZBD_WEBUSERNAME
write_ini Sabnzbd password $SABNZBD_WEBPASSWORD
write_ini Sabnzbd apikey $SABNZBD_APIKEY
write_ini Sabnzbd host "$SABNZBD_HOST:$SABNZBD_PORT"
write_ini XBMC enabled $COUCHPOTATO_USEXBMC
write_ini XBMC host "$XBMC_HOST:$XBMC_PORT"
write_ini XBMC username $XBMC_USER
write_ini XBMC password $XBMC_PWD
if [ "$COUCHPOTATO_FIRSTRUN" = "yes" ]; then
write_ini XBMC updateoneonly $COUCHPOTATO_UPDATEXBMC
fi
python ./CouchPotato/CouchPotato.py -d --datadir $COUCHPOTATO_HOME --config $COUCHPOTATO_HOME/config.ini