Fixed issues with trakt and root dirs.

Fixed web root issues.
This commit is contained in:
echel0n 2014-07-09 11:41:04 -07:00
parent e891e9d637
commit 2d0c31510e
3 changed files with 72 additions and 45 deletions

View file

@ -152,6 +152,7 @@ class TraktChecker():
logger.log(u"Adding show " + str(indexerid)) logger.log(u"Adding show " + str(indexerid))
root_dirs = sickbeard.ROOT_DIRS.split('|') root_dirs = sickbeard.ROOT_DIRS.split('|')
if root_dirs:
location = root_dirs[int(root_dirs[0]) + 1] location = root_dirs[int(root_dirs[0]) + 1]
showPath = ek.ek(os.path.join, location, helpers.sanitizeFileName(name)) showPath = ek.ek(os.path.join, location, helpers.sanitizeFileName(name))
@ -165,6 +166,9 @@ class TraktChecker():
sickbeard.showQueueScheduler.action.addShow(1, int(indexerid), showPath, status, sickbeard.showQueueScheduler.action.addShow(1, int(indexerid), showPath, status,
int(sickbeard.QUALITY_DEFAULT), int(sickbeard.QUALITY_DEFAULT),
int(sickbeard.FLATTEN_FOLDERS_DEFAULT)) int(sickbeard.FLATTEN_FOLDERS_DEFAULT))
else:
logger.log(u"There was an error creating the show, no root directory setting found", logger.ERROR)
return
def setEpisodeToWanted(self, show, s, e): def setEpisodeToWanted(self, show, s, e):
""" """

View file

@ -2830,6 +2830,7 @@ class NewHomeAddShows(MainHandler):
return return
root_dirs = sickbeard.ROOT_DIRS.split('|') root_dirs = sickbeard.ROOT_DIRS.split('|')
if root_dirs:
location = root_dirs[int(root_dirs[0]) + 1] location = root_dirs[int(root_dirs[0]) + 1]
show_dir = ek.ek(os.path.join, location, helpers.sanitizeFileName(showName)) show_dir = ek.ek(os.path.join, location, helpers.sanitizeFileName(showName))
@ -2849,6 +2850,9 @@ class NewHomeAddShows(MainHandler):
scene=sickbeard.SCENE_DEFAULT) scene=sickbeard.SCENE_DEFAULT)
ui.notifications.message('Show added', 'Adding the specified show into ' + show_dir) ui.notifications.message('Show added', 'Adding the specified show into ' + show_dir)
else:
logger.log(u"There was an error creating the show, no root directory setting found", logger.ERROR)
return
# done adding show # done adding show
redirect('/home/') redirect('/home/')

View file

@ -13,6 +13,7 @@ from tornado.web import Application, StaticFileHandler, RedirectHandler, HTTPErr
from tornado.httpserver import HTTPServer from tornado.httpserver import HTTPServer
from tornado.ioloop import IOLoop from tornado.ioloop import IOLoop
class MultiStaticFileHandler(StaticFileHandler): class MultiStaticFileHandler(StaticFileHandler):
def initialize(self, paths, default_filename=None): def initialize(self, paths, default_filename=None):
self.paths = paths self.paths = paths
@ -34,6 +35,7 @@ class MultiStaticFileHandler(StaticFileHandler):
# Oops file not found anywhere! # Oops file not found anywhere!
raise HTTPError(404) raise HTTPError(404)
class SRWebServer(threading.Thread): class SRWebServer(threading.Thread):
def __init__(self, options={}, io_loop=None): def __init__(self, options={}, io_loop=None):
threading.Thread.__init__(self) threading.Thread.__init__(self)
@ -48,10 +50,18 @@ class SRWebServer(threading.Thread):
self.options.setdefault('log_dir', None) self.options.setdefault('log_dir', None)
self.options.setdefault('username', '') self.options.setdefault('username', '')
self.options.setdefault('password', '') self.options.setdefault('password', '')
self.options.setdefault('web_root', '/') self.options.setdefault('web_root', None)
assert isinstance(self.options['port'], int) assert isinstance(self.options['port'], int)
assert 'data_root' in self.options assert 'data_root' in self.options
# video root
root_dirs = sickbeard.ROOT_DIRS.split('|')
self.video_root = root_dirs[int(root_dirs[0]) + 1] if root_dirs else None
# web root
self.options['web_root'] = ('/' + self.options['web_root'].lstrip('/')) if self.options[
'web_root'] else ''
# tornado setup # tornado setup
self.enable_https = self.options['enable_https'] self.enable_https = self.options['enable_https']
self.https_cert = self.options['https_cert'] self.https_cert = self.options['https_cert']
@ -59,7 +69,8 @@ class SRWebServer(threading.Thread):
if self.enable_https: if self.enable_https:
# If either the HTTPS certificate or key do not exist, make some self-signed ones. # If either the HTTPS certificate or key do not exist, make some self-signed ones.
if not (self.https_cert and os.path.exists(self.https_cert)) or not (self.https_key and os.path.exists(self.https_key)): if not (self.https_cert and os.path.exists(self.https_cert)) or not (
self.https_key and os.path.exists(self.https_key)):
if not create_https_certificates(self.https_cert, self.https_key): if not create_https_certificates(self.https_cert, self.https_key):
logger.log(u"Unable to create CERT/KEY files, disabling HTTPS") logger.log(u"Unable to create CERT/KEY files, disabling HTTPS")
sickbeard.ENABLE_HTTPS = False sickbeard.ENABLE_HTTPS = False
@ -81,23 +92,29 @@ class SRWebServer(threading.Thread):
# Main Handler # Main Handler
self.app.add_handlers(".*$", [ self.app.add_handlers(".*$", [
(r'%s/api/(.*)(/?)' % self.options['web_root'], webapi.Api), (r'%s/api/(.*)' % self.options['web_root'], webapi.Api),
(r'%s/(.*)(/?)' % self.options['web_root'], webserve.MainHandler), (r'%s/(.*)' % self.options['web_root'], webserve.MainHandler),
(r'(.*)', webserve.MainHandler) (r'(.*)', webserve.MainHandler)
]) ])
# Static Path Handler # Static Path Handler
self.app.add_handlers(".*$", [ self.app.add_handlers(".*$", [
(r'/(favicon\.ico)', MultiStaticFileHandler, (r'%s/(favicon\.ico)' % self.options['web_root'], MultiStaticFileHandler,
{'paths': [os.path.join(self.options['data_root'], 'images/ico/favicon.ico')]}), {'paths': [os.path.join(self.options['data_root'], 'images/ico/favicon.ico')]}),
(r'%s/%s/(.*)(/?)' % (self.options['web_root'], 'images'), MultiStaticFileHandler, (r'%s/%s/(.*)' % (self.options['web_root'], 'images'), MultiStaticFileHandler,
{'paths': [os.path.join(self.options['data_root'], 'images'), {'paths': [os.path.join(self.options['data_root'], 'images'),
os.path.join(sickbeard.CACHE_DIR, 'images')]}), os.path.join(sickbeard.CACHE_DIR, 'images')]}),
(r'%s/%s/(.*)(/?)' % (self.options['web_root'], 'css'), MultiStaticFileHandler, (r'%s/%s/(.*)' % (self.options['web_root'], 'css'), MultiStaticFileHandler,
{'paths': [os.path.join(self.options['data_root'], 'css')]}), {'paths': [os.path.join(self.options['data_root'], 'css')]}),
(r'%s/%s/(.*)(/?)' % (self.options['web_root'], 'js'), MultiStaticFileHandler, (r'%s/%s/(.*)' % (self.options['web_root'], 'js'), MultiStaticFileHandler,
{'paths': [os.path.join(self.options['data_root'], 'js')]}) {'paths': [os.path.join(self.options['data_root'], 'js')]}),
])
# Static Videos Path
if self.video_root:
self.app.add_handlers(".*$", [
(r'%s/%s/(.*)' % (self.options['web_root'], self.video_root), MultiStaticFileHandler,
{'paths': [self.video_root]}),
]) ])
def run(self): def run(self):
@ -116,7 +133,9 @@ class SRWebServer(threading.Thread):
self.server.listen(self.options['port'], self.options['host']) self.server.listen(self.options['port'], self.options['host'])
except: except:
etype, evalue, etb = sys.exc_info() etype, evalue, etb = sys.exc_info()
logger.log("Could not start webserver on %s. Excpeption: %s, Error: %s" % (self.options['port'], etype, evalue), logger.ERROR) logger.log(
"Could not start webserver on %s. Excpeption: %s, Error: %s" % (self.options['port'], etype, evalue),
logger.ERROR)
return return
try: try: