Browse Source

Save data to user dir

pull/62/head
Ruud 14 years ago
parent
commit
36ed61f549
  1. 2
      couchpotato/core/_base/_core/__init__.py
  2. 2
      couchpotato/core/_base/_core/main.py
  3. 18
      couchpotato/core/helpers/variable.py
  4. 2
      couchpotato/core/plugins/base.py
  5. 22
      couchpotato/runner.py
  6. 2
      init/freebsd
  7. 2
      init/solaris11
  8. 2
      init/ubuntu

2
couchpotato/core/_base/_core/__init__.py

@ -69,7 +69,7 @@ config = [{
{
'name': 'data_dir',
'type': 'directory',
'description': 'Where cache/logs/etc are stored. Keep empty for <strong>./_data</strong>.',
'description': 'Where cache/logs/etc are stored. Keep empty for defaults.',
},
{
'name': 'url_base',

2
couchpotato/core/_base/_core/main.py

@ -45,7 +45,7 @@ class Core(Plugin):
if brk: break
time.sleep(1)
time.sleep(300)
if restart:
self.createFile(self.restartFilePath(), 'This is the most suckiest way to register if CP is restarted. Ever...')

18
couchpotato/core/helpers/variable.py

@ -1,7 +1,25 @@
import hashlib
import os.path
import platform
import re
def getDataDir():
# Windows
try:
from win32com.shell import shellcon, shell
return os.path.join(shell.SHGetFolderPath(0, shellcon.CSIDL_APPDATA, 0, 0), 'CouchPotato')
except ImportError:
dir = os.path.expanduser("~")
# OSX
if 'darwin' in platform.platform().lower():
return os.path.join(dir, 'Library', 'Application Support', 'CouchPotato')
# Linux
return os.path.join(dir, '.couchpotato')
def isDict(object):
return isinstance(object, dict)

2
couchpotato/core/plugins/base.py

@ -5,7 +5,7 @@ from couchpotato.core.logger import CPLog
from couchpotato.environment import Env
from flask.helpers import send_from_directory
from flask.templating import render_template_string
from libs.multipartpost import MultipartPostHandler
from multipartpost import MultipartPostHandler
from urlparse import urlparse
import cookielib
import glob

22
couchpotato/runner.py

@ -2,6 +2,7 @@ from argparse import ArgumentParser
from couchpotato import web
from couchpotato.api import api
from couchpotato.core.event import fireEventAsync
from couchpotato.core.helpers.variable import getDataDir
from daemon import createDaemon
from logging import handlers
from werkzeug.contrib.cache import FileSystemCache
@ -11,17 +12,19 @@ import sys
def getOptions(base_path, args):
data_dir = getDataDir()
# Options
parser = ArgumentParser(prog = 'CouchPotato.py')
parser.add_argument('-c', '--config_file', default = os.path.join(base_path, '_data', 'settings.conf'),
parser.add_argument('--config_file', default = os.path.join(data_dir, 'settings.conf'),
dest = 'config_file', help = 'Absolute or ~/ path of the settings file (default ./_data/settings.conf)')
parser.add_argument('-t', '--test', '--debug', action = 'store_true',
parser.add_argument('--debug', action = 'store_true',
dest = 'debug', help = 'Debug mode')
parser.add_argument('-q', '--quiet', action = 'store_true',
dest = 'quiet', help = "Don't log to console")
parser.add_argument('-d', '--daemon', action = 'store_true',
parser.add_argument('--console_log', action = 'store_true',
dest = 'console_log', help = "Log to console")
parser.add_argument('--daemon', action = 'store_true',
dest = 'daemonize', help = 'Daemonize the app')
parser.add_argument('-g', '--nogit', action = 'store_true',
parser.add_argument('--nogit', action = 'store_true',
dest = 'nogit', help = 'Running from git')
options = parser.parse_args(args)
@ -41,7 +44,8 @@ def runCouchPotato(options, base_path, args):
# Create data dir if needed
data_dir = os.path.expanduser(Env.setting('data_dir'))
if data_dir == '':
data_dir = os.path.join(base_path, '_data')
data_dir = getDataDir()
if not os.path.isdir(data_dir):
os.makedirs(data_dir)
@ -63,7 +67,7 @@ def runCouchPotato(options, base_path, args):
Env.set('db_path', 'sqlite:///' + os.path.join(data_dir, 'couchpotato.db'))
Env.set('cache_dir', os.path.join(data_dir, 'cache'))
Env.set('cache', FileSystemCache(os.path.join(Env.get('cache_dir'), 'python')))
Env.set('quiet', options.quiet)
Env.set('console_log', options.console_log)
Env.set('daemonize', options.daemonize)
Env.set('args', args)
Env.set('options', options)
@ -82,7 +86,7 @@ def runCouchPotato(options, base_path, args):
logger.setLevel(level)
# To screen
if debug and not options.quiet and not options.daemonize:
if (debug or options.console_log) and not options.daemonize:
hdlr = logging.StreamHandler(sys.stderr)
hdlr.setFormatter(formatter)
logger.addHandler(hdlr)

2
init/freebsd

@ -42,7 +42,7 @@ status_cmd="${name}_status"
stop_cmd="${name}_stop"
command="/usr/sbin/daemon"
command_args="-f -p ${couchpotato_pid} python ${couchpotato_dir}/couchpotato.py ${couchpotato_flags} --quiet"
command_args="-f -p ${couchpotato_pid} python ${couchpotato_dir}/couchpotato.py ${couchpotato_flags}"
# Check for wget and refuse to start without it.
if [ ! -x "${WGET}" ]; then

2
init/solaris11

@ -68,7 +68,7 @@
<exec_method
type='method'
name='start'
exec='/opt/couchpotato/CouchPotato.py -d'
exec='/opt/couchpotato/CouchPotato.py --daemon'
timeout_seconds='60'>
</exec_method>

2
init/ubuntu

@ -18,7 +18,7 @@ APP_PATH=/usr/local/sbin/couchpotato
DAEMON=/usr/bin/python
# startup args
DAEMON_OPTS=" CouchPotato.py -q"
DAEMON_OPTS=" CouchPotato.py"
# script name
NAME=couchpotato

Loading…
Cancel
Save