Path encode
This commit is contained in:
+1
-1
@@ -29,7 +29,7 @@ class Loader(object):
|
|||||||
|
|
||||||
# Get options via arg
|
# Get options via arg
|
||||||
from couchpotato.runner import getOptions
|
from couchpotato.runner import getOptions
|
||||||
self.options = getOptions(base_path, sys.argv[1:])
|
self.options = getOptions(sys.argv[1:])
|
||||||
|
|
||||||
# Load settings
|
# Load settings
|
||||||
settings = Env.get('settings')
|
settings = Env.get('settings')
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ from threading import RLock
|
|||||||
|
|
||||||
from couchpotato.api import addApiView
|
from couchpotato.api import addApiView
|
||||||
from couchpotato.core.event import addEvent, fireEvent, fireEventAsync
|
from couchpotato.core.event import addEvent, fireEvent, fireEventAsync
|
||||||
from couchpotato.core.helpers.encoding import ss
|
from couchpotato.core.helpers.encoding import ss, sp
|
||||||
from couchpotato.core.logger import CPLog
|
from couchpotato.core.logger import CPLog
|
||||||
from couchpotato.core.plugins.base import Plugin
|
from couchpotato.core.plugins.base import Plugin
|
||||||
from couchpotato.environment import Env
|
from couchpotato.environment import Env
|
||||||
@@ -182,7 +182,7 @@ class BaseUpdater(Plugin):
|
|||||||
|
|
||||||
def deletePyc(self, only_excess = True, show_logs = True):
|
def deletePyc(self, only_excess = True, show_logs = True):
|
||||||
|
|
||||||
for root, dirs, files in scandir.walk(ss(Env.get('app_dir'))):
|
for root, dirs, files in scandir.walk(Env.get('app_dir')):
|
||||||
|
|
||||||
pyc_files = filter(lambda filename: filename.endswith('.pyc'), files)
|
pyc_files = filter(lambda filename: filename.endswith('.pyc'), files)
|
||||||
py_files = set(filter(lambda filename: filename.endswith('.py'), files))
|
py_files = set(filter(lambda filename: filename.endswith('.py'), files))
|
||||||
@@ -322,6 +322,7 @@ class SourceUpdater(BaseUpdater):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
def replaceWith(self, path):
|
def replaceWith(self, path):
|
||||||
|
path = sp(path)
|
||||||
app_dir = ss(Env.get('app_dir'))
|
app_dir = ss(Env.get('app_dir'))
|
||||||
data_dir = ss(Env.get('data_dir'))
|
data_dir = ss(Env.get('data_dir'))
|
||||||
|
|
||||||
|
|||||||
@@ -238,7 +238,7 @@ class rTorrent(DownloaderBase):
|
|||||||
if torrent.is_multi_file() and torrent.directory.endswith(torrent.name):
|
if torrent.is_multi_file() and torrent.directory.endswith(torrent.name):
|
||||||
# Remove empty directories bottom up
|
# Remove empty directories bottom up
|
||||||
try:
|
try:
|
||||||
for path, _, _ in scandir.walk(torrent.directory, topdown = False):
|
for path, _, _ in scandir.walk(sp(torrent.directory), topdown = False):
|
||||||
os.rmdir(path)
|
os.rmdir(path)
|
||||||
except OSError:
|
except OSError:
|
||||||
log.info('Directory "%s" contains extra files, unable to remove', torrent.directory)
|
log.info('Directory "%s" contains extra files, unable to remove', torrent.directory)
|
||||||
|
|||||||
@@ -118,10 +118,7 @@ class Renamer(Plugin):
|
|||||||
to_folder = sp(self.conf('to'))
|
to_folder = sp(self.conf('to'))
|
||||||
|
|
||||||
# Get media folder to process
|
# Get media folder to process
|
||||||
media_folder = release_download.get('folder')
|
media_folder = sp(release_download.get('folder'))
|
||||||
|
|
||||||
# Quality order for calculation quality priority
|
|
||||||
quality_order = fireEvent('quality.order', single = True)
|
|
||||||
|
|
||||||
# Get all folders that should not be processed
|
# Get all folders that should not be processed
|
||||||
no_process = [to_folder]
|
no_process = [to_folder]
|
||||||
@@ -149,9 +146,9 @@ class Renamer(Plugin):
|
|||||||
|
|
||||||
# Update to the from folder
|
# Update to the from folder
|
||||||
if len(release_download.get('files', [])) == 1:
|
if len(release_download.get('files', [])) == 1:
|
||||||
new_media_folder = from_folder
|
new_media_folder = sp(from_folder)
|
||||||
else:
|
else:
|
||||||
new_media_folder = os.path.join(from_folder, os.path.basename(media_folder))
|
new_media_folder = sp(os.path.join(from_folder, os.path.basename(media_folder)))
|
||||||
|
|
||||||
if not os.path.isdir(new_media_folder):
|
if not os.path.isdir(new_media_folder):
|
||||||
log.error('The provided media folder %s does not exist and could also not be found in the \'from\' folder.', media_folder)
|
log.error('The provided media folder %s does not exist and could also not be found in the \'from\' folder.', media_folder)
|
||||||
@@ -319,7 +316,7 @@ class Renamer(Plugin):
|
|||||||
'3d': '3D' if group['meta_data']['quality'].get('is_3d', 0) else '',
|
'3d': '3D' if group['meta_data']['quality'].get('is_3d', 0) else '',
|
||||||
'3d_type': group['meta_data'].get('3d_type'),
|
'3d_type': group['meta_data'].get('3d_type'),
|
||||||
}
|
}
|
||||||
|
|
||||||
if replacements['mpaa_only'] not in ('G', 'PG', 'PG-13', 'R', 'NC-17'):
|
if replacements['mpaa_only'] not in ('G', 'PG', 'PG-13', 'R', 'NC-17'):
|
||||||
replacements['mpaa_only'] = 'Not Rated'
|
replacements['mpaa_only'] = 'Not Rated'
|
||||||
|
|
||||||
@@ -667,7 +664,7 @@ Remove it if you want it to be renamed (again, or at least let it try again)
|
|||||||
|
|
||||||
# Tag all files in release folder
|
# Tag all files in release folder
|
||||||
elif release_download['folder']:
|
elif release_download['folder']:
|
||||||
for root, folders, names in scandir.walk(release_download['folder']):
|
for root, folders, names in scandir.walk(sp(release_download['folder'])):
|
||||||
tag_files.extend([os.path.join(root, name) for name in names])
|
tag_files.extend([os.path.join(root, name) for name in names])
|
||||||
|
|
||||||
for filename in tag_files:
|
for filename in tag_files:
|
||||||
@@ -691,13 +688,13 @@ Remove it if you want it to be renamed (again, or at least let it try again)
|
|||||||
if isinstance(group, dict):
|
if isinstance(group, dict):
|
||||||
tag_files = [sorted(list(group['files']['movie']))[0]]
|
tag_files = [sorted(list(group['files']['movie']))[0]]
|
||||||
|
|
||||||
folder = group['parentdir']
|
folder = sp(group['parentdir'])
|
||||||
if not group.get('dirname') or not os.path.isdir(folder):
|
if not group.get('dirname') or not os.path.isdir(folder):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
elif isinstance(release_download, dict):
|
elif isinstance(release_download, dict):
|
||||||
|
|
||||||
folder = release_download['folder']
|
folder = sp(release_download['folder'])
|
||||||
if not os.path.isdir(folder):
|
if not os.path.isdir(folder):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@@ -731,7 +728,7 @@ Remove it if you want it to be renamed (again, or at least let it try again)
|
|||||||
if not release_download:
|
if not release_download:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
folder = release_download['folder']
|
folder = sp(release_download['folder'])
|
||||||
if not os.path.isdir(folder):
|
if not os.path.isdir(folder):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|||||||
+12
-12
@@ -16,14 +16,14 @@ from cache import FileSystemCache
|
|||||||
from couchpotato import KeyHandler, LoginHandler, LogoutHandler
|
from couchpotato import KeyHandler, LoginHandler, LogoutHandler
|
||||||
from couchpotato.api import NonBlockHandler, ApiHandler
|
from couchpotato.api import NonBlockHandler, ApiHandler
|
||||||
from couchpotato.core.event import fireEventAsync, fireEvent
|
from couchpotato.core.event import fireEventAsync, fireEvent
|
||||||
from couchpotato.core.helpers.encoding import toUnicode
|
from couchpotato.core.helpers.encoding import sp
|
||||||
from couchpotato.core.helpers.variable import getDataDir, tryInt
|
from couchpotato.core.helpers.variable import getDataDir, tryInt
|
||||||
from scandir import scandir
|
from scandir import scandir
|
||||||
from tornado.httpserver import HTTPServer
|
from tornado.httpserver import HTTPServer
|
||||||
from tornado.web import Application, StaticFileHandler, RedirectHandler
|
from tornado.web import Application, StaticFileHandler, RedirectHandler
|
||||||
|
|
||||||
|
|
||||||
def getOptions(base_path, args):
|
def getOptions(args):
|
||||||
|
|
||||||
# Options
|
# Options
|
||||||
parser = ArgumentParser(prog = 'CouchPotato.py')
|
parser = ArgumentParser(prog = 'CouchPotato.py')
|
||||||
@@ -86,7 +86,7 @@ def runCouchPotato(options, base_path, args, data_dir = None, log_dir = None, En
|
|||||||
Env.set('encoding', encoding)
|
Env.set('encoding', encoding)
|
||||||
|
|
||||||
# Do db stuff
|
# Do db stuff
|
||||||
db_path = toUnicode(os.path.join(data_dir, 'database'))
|
db_path = sp(os.path.join(data_dir, 'database'))
|
||||||
|
|
||||||
# Check if database exists
|
# Check if database exists
|
||||||
db = SuperThreadSafeDatabase(db_path)
|
db = SuperThreadSafeDatabase(db_path)
|
||||||
@@ -94,7 +94,7 @@ def runCouchPotato(options, base_path, args, data_dir = None, log_dir = None, En
|
|||||||
if db_exists:
|
if db_exists:
|
||||||
|
|
||||||
# Backup before start and cleanup old backups
|
# Backup before start and cleanup old backups
|
||||||
backup_path = toUnicode(os.path.join(data_dir, 'db_backup'))
|
backup_path = sp(os.path.join(data_dir, 'db_backup'))
|
||||||
backup_count = 5
|
backup_count = 5
|
||||||
existing_backups = []
|
existing_backups = []
|
||||||
if not os.path.isdir(backup_path): os.makedirs(backup_path)
|
if not os.path.isdir(backup_path): os.makedirs(backup_path)
|
||||||
@@ -114,7 +114,7 @@ def runCouchPotato(options, base_path, args, data_dir = None, log_dir = None, En
|
|||||||
os.remove(os.path.join(backup_path, eb[1]))
|
os.remove(os.path.join(backup_path, eb[1]))
|
||||||
|
|
||||||
# Create new backup
|
# Create new backup
|
||||||
new_backup = toUnicode(os.path.join(backup_path, '%s.tar.gz' % int(time.time())))
|
new_backup = sp(os.path.join(backup_path, '%s.tar.gz' % int(time.time())))
|
||||||
zipf = tarfile.open(new_backup, 'w:gz')
|
zipf = tarfile.open(new_backup, 'w:gz')
|
||||||
for root, dirs, files in scandir.walk(db_path):
|
for root, dirs, files in scandir.walk(db_path):
|
||||||
for zfilename in files:
|
for zfilename in files:
|
||||||
@@ -128,12 +128,12 @@ def runCouchPotato(options, base_path, args, data_dir = None, log_dir = None, En
|
|||||||
db.create()
|
db.create()
|
||||||
|
|
||||||
# Register environment settings
|
# Register environment settings
|
||||||
Env.set('app_dir', toUnicode(base_path))
|
Env.set('app_dir', sp(base_path))
|
||||||
Env.set('data_dir', toUnicode(data_dir))
|
Env.set('data_dir', sp(data_dir))
|
||||||
Env.set('log_path', toUnicode(os.path.join(log_dir, 'CouchPotato.log')))
|
Env.set('log_path', sp(os.path.join(log_dir, 'CouchPotato.log')))
|
||||||
Env.set('db', db)
|
Env.set('db', db)
|
||||||
Env.set('cache_dir', toUnicode(os.path.join(data_dir, 'cache')))
|
Env.set('cache_dir', sp(os.path.join(data_dir, 'cache')))
|
||||||
Env.set('cache', FileSystemCache(toUnicode(os.path.join(Env.get('cache_dir'), 'python'))))
|
Env.set('cache', FileSystemCache(sp(os.path.join(Env.get('cache_dir'), 'python'))))
|
||||||
Env.set('console_log', options.console_log)
|
Env.set('console_log', options.console_log)
|
||||||
Env.set('quiet', options.quiet)
|
Env.set('quiet', options.quiet)
|
||||||
Env.set('desktop', desktop)
|
Env.set('desktop', desktop)
|
||||||
@@ -245,13 +245,13 @@ def runCouchPotato(options, base_path, args, data_dir = None, log_dir = None, En
|
|||||||
static_path = '%sstatic/' % web_base
|
static_path = '%sstatic/' % web_base
|
||||||
for dir_name in ['fonts', 'images', 'scripts', 'style']:
|
for dir_name in ['fonts', 'images', 'scripts', 'style']:
|
||||||
application.add_handlers(".*$", [
|
application.add_handlers(".*$", [
|
||||||
('%s%s/(.*)' % (static_path, dir_name), StaticFileHandler, {'path': toUnicode(os.path.join(base_path, 'couchpotato', 'static', dir_name))})
|
('%s%s/(.*)' % (static_path, dir_name), StaticFileHandler, {'path': sp(os.path.join(base_path, 'couchpotato', 'static', dir_name))})
|
||||||
])
|
])
|
||||||
Env.set('static_path', static_path)
|
Env.set('static_path', static_path)
|
||||||
|
|
||||||
# Load configs & plugins
|
# Load configs & plugins
|
||||||
loader = Env.get('loader')
|
loader = Env.get('loader')
|
||||||
loader.preload(root = toUnicode(base_path))
|
loader.preload(root = sp(base_path))
|
||||||
loader.run()
|
loader.run()
|
||||||
|
|
||||||
# Fill database with needed stuff
|
# Fill database with needed stuff
|
||||||
|
|||||||
Reference in New Issue
Block a user