diff --git a/SickBeard.py b/SickBeard.py index e5a36cc7..591eddf6 100755 --- a/SickBeard.py +++ b/SickBeard.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +# !/usr/bin/env python2 # Author: Nic Wolfe # URL: http://code.google.com/p/sickbeard/ # @@ -19,12 +19,14 @@ # Check needed software dependencies to nudge users to fix their setup import sys + if sys.version_info < (2, 6): print "Sorry, requires Python 2.6 or 2.7." sys.exit(1) try: import Cheetah + if Cheetah.Version[0] != '2': raise ValueError except ValueError: @@ -35,11 +37,12 @@ except: sys.exit(1) import os + sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), 'lib'))) # We only need this for compiling an EXE and I will just always do that on 2.6+ if sys.hexversion >= 0x020600F0: - from multiprocessing import freeze_support # @UnresolvedImport + from multiprocessing import freeze_support # @UnresolvedImport import locale import datetime @@ -65,7 +68,8 @@ from lib.configobj import ConfigObj signal.signal(signal.SIGINT, sickbeard.sig_handler) signal.signal(signal.SIGTERM, sickbeard.sig_handler) -throwaway = datetime.datetime.strptime('20110101','%Y%m%d') +throwaway = datetime.datetime.strptime('20110101', '%Y%m%d') + def loadShowsFromDB(): """ @@ -80,10 +84,12 @@ def loadShowsFromDB(): curShow = TVShow(int(sqlShow["indexer"]), int(sqlShow["indexer_id"])) sickbeard.showList.append(curShow) except Exception, e: - logger.log(u"There was an error creating the show in " + sqlShow["location"] + ": " + str(e).decode('utf-8'), logger.ERROR) + logger.log( + u"There was an error creating the show in " + sqlShow["location"] + ": " + str(e).decode('utf-8'), + logger.ERROR) logger.log(traceback.format_exc(), logger.DEBUG) - # TODO: update the existing shows if the showlist has something in it + # TODO: update the existing shows if the showlist has something in it def daemonize(): @@ -101,7 +107,7 @@ def daemonize(): sys.stderr.write("fork #1 failed: %d (%s)\n" % (e.errno, e.strerror)) sys.exit(1) - os.setsid() # @UndefinedVariable - only available in UNIX + os.setsid(pid) # @UndefinedVariable - only available in UNIX # Make sure I can read my own files and shut out others prev = os.umask(0) @@ -139,6 +145,7 @@ def daemonize(): os.dup2(stdout.fileno(), sys.stdout.fileno()) os.dup2(stderr.fileno(), sys.stderr.fileno()) + def main(): """ TV for me @@ -194,7 +201,9 @@ def main(): threading.currentThread().name = "MAIN" try: - opts, args = getopt.getopt(sys.argv[1:], "qfdp::", ['quiet', 'forceupdate', 'daemon', 'port=', 'pidfile=', 'nolaunch', 'config=', 'datadir=']) # @UnusedVariable + opts, args = getopt.getopt(sys.argv[1:], "qfdp::", + ['quiet', 'forceupdate', 'daemon', 'port=', 'pidfile=', 'nolaunch', 'config=', + 'datadir=']) # @UnusedVariable except getopt.GetoptError: print "Available Options: --quiet, --forceupdate, --port, --daemon, --pidfile, --config, --datadir" sys.exit() @@ -300,13 +309,17 @@ def main(): CUR_DB_VERSION = db.DBConnection().checkDBVersion() if CUR_DB_VERSION > 0: if CUR_DB_VERSION < MIN_DB_VERSION: - raise SystemExit("Your database version (" + str(db.DBConnection().checkDBVersion()) + ") is too old to migrate from with this version of SickRage (" + str(MIN_DB_VERSION) + ").\n" + \ + raise SystemExit("Your database version (" + str( + db.DBConnection().checkDBVersion()) + ") is too old to migrate from with this version of SickRage (" + str( + MIN_DB_VERSION) + ").\n" + \ "Upgrade using a previous version of SB first, or start with no database file to begin fresh.") if CUR_DB_VERSION > MAX_DB_VERSION: - raise SystemExit("Your database version (" + str(db.DBConnection().checkDBVersion()) + ") has been incremented past what this version of SickRage supports (" + str(MAX_DB_VERSION) + ").\n" + \ + raise SystemExit("Your database version (" + str( + db.DBConnection().checkDBVersion()) + ") has been incremented past what this version of SickRage supports (" + str( + MAX_DB_VERSION) + ").\n" + \ "If you have used other forks of SB, your database may be unusable due to their modifications.") - # Initialize the config and our threads + # Initialize the config and our threads sickbeard.initialize(consoleLogging=consoleLogging) sickbeard.showList = [] @@ -342,16 +355,16 @@ def main(): initWebServer({ 'port': startPort, 'host': webhost, - 'data_root': os.path.join(sickbeard.PROG_DIR, 'gui/'+sickbeard.GUI_NAME), + 'data_root': os.path.join(sickbeard.PROG_DIR, 'gui/' + sickbeard.GUI_NAME), 'web_root': sickbeard.WEB_ROOT, 'log_dir': log_dir, 'username': sickbeard.WEB_USERNAME, 'password': sickbeard.WEB_PASSWORD, 'enable_https': sickbeard.ENABLE_HTTPS, - 'handle_reverse_proxy': sickbeard.HANDLE_REVERSE_PROXY, + 'handle_reverse_proxy': sickbeard.HANDLE_REVERSE_PROXY, 'https_cert': sickbeard.HTTPS_CERT, 'https_key': sickbeard.HTTPS_KEY, - }) + }) except IOError: logger.log(u"Unable to start web server, is something else running on port %d?" % startPort, logger.ERROR) if sickbeard.LAUNCH_BROWSER and not sickbeard.DAEMON: @@ -372,7 +385,7 @@ def main(): # Start an update if we're supposed to if forceUpdate or sickbeard.UPDATE_SHOWS_ON_START: - sickbeard.showUpdateScheduler.action.run(force=True) # @UndefinedVariable + sickbeard.showUpdateScheduler.action.run(force=True) # @UndefinedVariable # Stay alive while my threads do the work while (True): diff --git a/sickbeard/__init__.py b/sickbeard/__init__.py index 991b1b1d..c32181ac 100644 --- a/sickbeard/__init__.py +++ b/sickbeard/__init__.py @@ -1303,6 +1303,7 @@ def saveAndShutdown(restart=False): logger.log(u"Removing pidfile " + str(PIDFILE)) remove_pid_file(PIDFILE) + status = 0 if restart: install_type = versionCheckScheduler.action.install_type @@ -1325,9 +1326,11 @@ def saveAndShutdown(restart=False): popen_list += ['--nolaunch'] logger.log(u"Restarting SickRage with " + str(popen_list)) logger.close() - subprocess.Popen(popen_list, cwd=os.getcwd()) + p = subprocess.Popen(popen_list, cwd=os.getcwd()) + p.wait() + status = p.returncode - os._exit(0) + os._exit(status) def invoke_command(to_call, *args, **kwargs):