Save data to user dir
This commit is contained in:
1 parent
138845ca9e
commit
36ed61f549
8 files changed
+37
-15
No files matched your search
@@ -69,7 +69,7 @@ config = [{
|
|||||||
{
|
{
|
||||||
'name': 'data_dir',
|
'name': 'data_dir',
|
||||||
'type': 'directory',
|
'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',
|
'name': 'url_base',
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ class Core(Plugin):
|
|||||||
|
|
||||||
if brk: break
|
if brk: break
|
||||||
|
|
||||||
time.sleep(1)
|
time.sleep(300)
|
||||||
|
|
||||||
if restart:
|
if restart:
|
||||||
self.createFile(self.restartFilePath(), 'This is the most suckiest way to register if CP is restarted. Ever...')
|
self.createFile(self.restartFilePath(), 'This is the most suckiest way to register if CP is restarted. Ever...')
|
||||||
|
|||||||
@@ -1,7 +1,25 @@
|
|||||||
import hashlib
|
import hashlib
|
||||||
import os.path
|
import os.path
|
||||||
|
import platform
|
||||||
import re
|
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):
|
def isDict(object):
|
||||||
return isinstance(object, dict)
|
return isinstance(object, dict)
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ from couchpotato.core.logger import CPLog
|
|||||||
from couchpotato.environment import Env
|
from couchpotato.environment import Env
|
||||||
from flask.helpers import send_from_directory
|
from flask.helpers import send_from_directory
|
||||||
from flask.templating import render_template_string
|
from flask.templating import render_template_string
|
||||||
from libs.multipartpost import MultipartPostHandler
|
from multipartpost import MultipartPostHandler
|
||||||
from urlparse import urlparse
|
from urlparse import urlparse
|
||||||
import cookielib
|
import cookielib
|
||||||
import glob
|
import glob
|
||||||
|
|||||||
+13
-9
@@ -2,6 +2,7 @@ from argparse import ArgumentParser
|
|||||||
from couchpotato import web
|
from couchpotato import web
|
||||||
from couchpotato.api import api
|
from couchpotato.api import api
|
||||||
from couchpotato.core.event import fireEventAsync
|
from couchpotato.core.event import fireEventAsync
|
||||||
|
from couchpotato.core.helpers.variable import getDataDir
|
||||||
from daemon import createDaemon
|
from daemon import createDaemon
|
||||||
from logging import handlers
|
from logging import handlers
|
||||||
from werkzeug.contrib.cache import FileSystemCache
|
from werkzeug.contrib.cache import FileSystemCache
|
||||||
@@ -11,17 +12,19 @@ import sys
|
|||||||
|
|
||||||
def getOptions(base_path, args):
|
def getOptions(base_path, args):
|
||||||
|
|
||||||
|
data_dir = getDataDir()
|
||||||
|
|
||||||
# Options
|
# Options
|
||||||
parser = ArgumentParser(prog = 'CouchPotato.py')
|
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)')
|
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')
|
dest = 'debug', help = 'Debug mode')
|
||||||
parser.add_argument('-q', '--quiet', action = 'store_true',
|
parser.add_argument('--console_log', action = 'store_true',
|
||||||
dest = 'quiet', help = "Don't log to console")
|
dest = 'console_log', help = "Log to console")
|
||||||
parser.add_argument('-d', '--daemon', action = 'store_true',
|
parser.add_argument('--daemon', action = 'store_true',
|
||||||
dest = 'daemonize', help = 'Daemonize the app')
|
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')
|
dest = 'nogit', help = 'Running from git')
|
||||||
|
|
||||||
options = parser.parse_args(args)
|
options = parser.parse_args(args)
|
||||||
@@ -41,7 +44,8 @@ def runCouchPotato(options, base_path, args):
|
|||||||
# Create data dir if needed
|
# Create data dir if needed
|
||||||
data_dir = os.path.expanduser(Env.setting('data_dir'))
|
data_dir = os.path.expanduser(Env.setting('data_dir'))
|
||||||
if data_dir == '':
|
if data_dir == '':
|
||||||
data_dir = os.path.join(base_path, '_data')
|
data_dir = getDataDir()
|
||||||
|
|
||||||
if not os.path.isdir(data_dir):
|
if not os.path.isdir(data_dir):
|
||||||
os.makedirs(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('db_path', 'sqlite:///' + os.path.join(data_dir, 'couchpotato.db'))
|
||||||
Env.set('cache_dir', os.path.join(data_dir, 'cache'))
|
Env.set('cache_dir', os.path.join(data_dir, 'cache'))
|
||||||
Env.set('cache', FileSystemCache(os.path.join(Env.get('cache_dir'), 'python')))
|
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('daemonize', options.daemonize)
|
||||||
Env.set('args', args)
|
Env.set('args', args)
|
||||||
Env.set('options', options)
|
Env.set('options', options)
|
||||||
@@ -82,7 +86,7 @@ def runCouchPotato(options, base_path, args):
|
|||||||
logger.setLevel(level)
|
logger.setLevel(level)
|
||||||
|
|
||||||
# To screen
|
# 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 = logging.StreamHandler(sys.stderr)
|
||||||
hdlr.setFormatter(formatter)
|
hdlr.setFormatter(formatter)
|
||||||
logger.addHandler(hdlr)
|
logger.addHandler(hdlr)
|
||||||
|
|||||||
+1
-1
@@ -42,7 +42,7 @@ status_cmd="${name}_status"
|
|||||||
stop_cmd="${name}_stop"
|
stop_cmd="${name}_stop"
|
||||||
|
|
||||||
command="/usr/sbin/daemon"
|
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.
|
# Check for wget and refuse to start without it.
|
||||||
if [ ! -x "${WGET}" ]; then
|
if [ ! -x "${WGET}" ]; then
|
||||||
|
|||||||
+1
-1
@@ -68,7 +68,7 @@
|
|||||||
<exec_method
|
<exec_method
|
||||||
type='method'
|
type='method'
|
||||||
name='start'
|
name='start'
|
||||||
exec='/opt/couchpotato/CouchPotato.py -d'
|
exec='/opt/couchpotato/CouchPotato.py --daemon'
|
||||||
timeout_seconds='60'>
|
timeout_seconds='60'>
|
||||||
</exec_method>
|
</exec_method>
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -18,7 +18,7 @@ APP_PATH=/usr/local/sbin/couchpotato
|
|||||||
DAEMON=/usr/bin/python
|
DAEMON=/usr/bin/python
|
||||||
|
|
||||||
# startup args
|
# startup args
|
||||||
DAEMON_OPTS=" CouchPotato.py -q"
|
DAEMON_OPTS=" CouchPotato.py"
|
||||||
|
|
||||||
# script name
|
# script name
|
||||||
NAME=couchpotato
|
NAME=couchpotato
|
||||||
|
|||||||
Reference in new issue
Block a user