diff --git a/sickbeard/traktChecker.py b/sickbeard/traktChecker.py index eec11e15..4ed03292 100644 --- a/sickbeard/traktChecker.py +++ b/sickbeard/traktChecker.py @@ -152,19 +152,23 @@ class TraktChecker(): logger.log(u"Adding show " + str(indexerid)) root_dirs = sickbeard.ROOT_DIRS.split('|') - location = root_dirs[int(root_dirs[0]) + 1] + if root_dirs: + location = root_dirs[int(root_dirs[0]) + 1] - showPath = ek.ek(os.path.join, location, helpers.sanitizeFileName(name)) - dir_exists = helpers.makeDir(showPath) - if not dir_exists: - logger.log(u"Unable to create the folder " + showPath + ", can't add the show", logger.ERROR) - return + showPath = ek.ek(os.path.join, location, helpers.sanitizeFileName(name)) + dir_exists = helpers.makeDir(showPath) + if not dir_exists: + logger.log(u"Unable to create the folder " + showPath + ", can't add the show", logger.ERROR) + return + else: + helpers.chmodAsParent(showPath) + + sickbeard.showQueueScheduler.action.addShow(1, int(indexerid), showPath, status, + int(sickbeard.QUALITY_DEFAULT), + int(sickbeard.FLATTEN_FOLDERS_DEFAULT)) else: - helpers.chmodAsParent(showPath) - - sickbeard.showQueueScheduler.action.addShow(1, int(indexerid), showPath, status, - int(sickbeard.QUALITY_DEFAULT), - int(sickbeard.FLATTEN_FOLDERS_DEFAULT)) + logger.log(u"There was an error creating the show, no root directory setting found", logger.ERROR) + return def setEpisodeToWanted(self, show, s, e): """ diff --git a/sickbeard/webserve.py b/sickbeard/webserve.py index b83e9615..063201b7 100644 --- a/sickbeard/webserve.py +++ b/sickbeard/webserve.py @@ -2830,25 +2830,29 @@ class NewHomeAddShows(MainHandler): return root_dirs = sickbeard.ROOT_DIRS.split('|') - location = root_dirs[int(root_dirs[0]) + 1] + if root_dirs: + location = root_dirs[int(root_dirs[0]) + 1] - show_dir = ek.ek(os.path.join, location, helpers.sanitizeFileName(showName)) - dir_exists = helpers.makeDir(show_dir) - if not dir_exists: - logger.log(u"Unable to create the folder " + show_dir + ", can't add the show", logger.ERROR) - return + show_dir = ek.ek(os.path.join, location, helpers.sanitizeFileName(showName)) + dir_exists = helpers.makeDir(show_dir) + if not dir_exists: + logger.log(u"Unable to create the folder " + show_dir + ", can't add the show", logger.ERROR) + return + else: + helpers.chmodAsParent(show_dir) + + sickbeard.showQueueScheduler.action.addShow(1, int(indexer_id), show_dir, + default_status=sickbeard.STATUS_DEFAULT, + quality=sickbeard.QUALITY_DEFAULT, + flatten_folders=sickbeard.FLATTEN_FOLDERS_DEFAULT, + subtitles=sickbeard.SUBTITLES_DEFAULT, + anime=sickbeard.ANIME_DEFAULT, + scene=sickbeard.SCENE_DEFAULT) + + ui.notifications.message('Show added', 'Adding the specified show into ' + show_dir) else: - helpers.chmodAsParent(show_dir) - - sickbeard.showQueueScheduler.action.addShow(1, int(indexer_id), show_dir, - default_status=sickbeard.STATUS_DEFAULT, - quality=sickbeard.QUALITY_DEFAULT, - flatten_folders=sickbeard.FLATTEN_FOLDERS_DEFAULT, - subtitles=sickbeard.SUBTITLES_DEFAULT, - anime=sickbeard.ANIME_DEFAULT, - scene=sickbeard.SCENE_DEFAULT) - - ui.notifications.message('Show added', 'Adding the specified show into ' + show_dir) + logger.log(u"There was an error creating the show, no root directory setting found", logger.ERROR) + return # done adding show redirect('/home/') diff --git a/sickbeard/webserveInit.py b/sickbeard/webserveInit.py index ee95b01a..9f629742 100644 --- a/sickbeard/webserveInit.py +++ b/sickbeard/webserveInit.py @@ -13,6 +13,7 @@ from tornado.web import Application, StaticFileHandler, RedirectHandler, HTTPErr from tornado.httpserver import HTTPServer from tornado.ioloop import IOLoop + class MultiStaticFileHandler(StaticFileHandler): def initialize(self, paths, default_filename=None): self.paths = paths @@ -34,6 +35,7 @@ class MultiStaticFileHandler(StaticFileHandler): # Oops file not found anywhere! raise HTTPError(404) + class SRWebServer(threading.Thread): def __init__(self, options={}, io_loop=None): threading.Thread.__init__(self) @@ -48,10 +50,18 @@ class SRWebServer(threading.Thread): self.options.setdefault('log_dir', None) self.options.setdefault('username', '') self.options.setdefault('password', '') - self.options.setdefault('web_root', '/') + self.options.setdefault('web_root', None) assert isinstance(self.options['port'], int) 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 self.enable_https = self.options['enable_https'] self.https_cert = self.options['https_cert'] @@ -59,7 +69,8 @@ class SRWebServer(threading.Thread): if self.enable_https: # 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): logger.log(u"Unable to create CERT/KEY files, disabling HTTPS") sickbeard.ENABLE_HTTPS = False @@ -72,39 +83,45 @@ class SRWebServer(threading.Thread): # Load the app self.app = Application([], - debug=True, - autoreload=False, - gzip=True, - xheaders=sickbeard.HANDLE_REVERSE_PROXY, - cookie_secret='61oETzKXQAGaYdkL5gEmGeJJFuYh7EQnp2XdTP1o/Vo=' + debug=True, + autoreload=False, + gzip=True, + xheaders=sickbeard.HANDLE_REVERSE_PROXY, + cookie_secret='61oETzKXQAGaYdkL5gEmGeJJFuYh7EQnp2XdTP1o/Vo=' ) # Main Handler self.app.add_handlers(".*$", [ - (r'%s/api/(.*)(/?)' % self.options['web_root'], webapi.Api), - (r'%s/(.*)(/?)' % self.options['web_root'], webserve.MainHandler), + (r'%s/api/(.*)' % self.options['web_root'], webapi.Api), + (r'%s/(.*)' % self.options['web_root'], webserve.MainHandler), (r'(.*)', webserve.MainHandler) ]) # Static Path Handler 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')]}), - (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'), 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')]}), - (r'%s/%s/(.*)(/?)' % (self.options['web_root'], 'js'), MultiStaticFileHandler, - {'paths': [os.path.join(self.options['data_root'], 'js')]}) - + (r'%s/%s/(.*)' % (self.options['web_root'], 'js'), MultiStaticFileHandler, + {'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): if self.enable_https: protocol = "https" self.server = HTTPServer(self.app, no_keep_alive=True, - ssl_options={"certfile": self.https_cert, "keyfile": self.https_key}) + ssl_options={"certfile": self.https_cert, "keyfile": self.https_key}) else: protocol = "http" self.server = HTTPServer(self.app, no_keep_alive=True) @@ -116,7 +133,9 @@ class SRWebServer(threading.Thread): self.server.listen(self.options['port'], self.options['host']) except: 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 try: