def main(): global srCore, srConfig, srLogger, DATA_DIR if sys.version_info < (2, 7): print("Sorry, SiCKRAGE requires Python 2.7+") sys.exit(1) # add sickrage module to python system path path = os.path.dirname(os.path.realpath(__file__)) if path not in sys.path: sys.path.insert(0, os.path.dirname(os.path.realpath(__file__))) try: opts, _ = getopt.getopt(sys.argv[1:], "hqdp::", [ 'help', 'dev', 'quiet', 'nolaunch', 'daemon', 'pidfile=', 'port=', 'datadir=', 'config=', 'noresize', 'install-optional', 'ssl', 'debug' ]) except getopt.GetoptError: sys.exit(help_message(PROG_DIR)) # defaults PIDFILE = os.path.abspath(os.path.join(DATA_DIR, 'sickrage.pid')) DEVELOPER = False DAEMONIZE = False WEB_PORT = None INSTALL_OPTIONAL = False WEB_NOLAUNCH = False SSL = False DEBUG = False CONFIG_FILE = "config.ini" CONSOLE = not hasattr(sys, "frozen") for o, a in opts: # help message if o in ('-h', '--help'): sys.exit(help_message(PROG_DIR)) # For now we'll just silence the logging if o in ('-q', '--quiet'): CONSOLE = False # developer mode if o in ('--dev', ): print("!!! DEVELOPER MODE ENABLED !!!") DEVELOPER = True # Suppress launching web browser # Needed for OSes without default browser assigned # Prevent duplicate browser window when restarting in the app if o in ('--nolaunch', ): WEB_NOLAUNCH = True # Override default/configured port if o in ('-p', '--port'): try: WEB_PORT = int(a) except ValueError: sys.exit("Port: " + str(a) + " is not a number. Exiting.") # Run as a double forked daemon if o in ('-d', '--daemon'): DAEMONIZE = (False, True)[not sys.platform == 'win32'] WEB_NOLAUNCH = True CONSOLE = False # Write a pidfile if requested if o in ('--pidfile', ): PIDFILE = str(a) # If the pidfile already exists, sickrage may still be running, so exit if os.path.exists(PIDFILE): sys.exit("PID file: " + PIDFILE + " already exists. Exiting.") # Specify folder to use as the data dir if o in ('--datadir', ): DATA_DIR = os.path.abspath(os.path.expanduser(a)) # Specify folder to load the config file from if o in ('--config', ): CONFIG_FILE = os.path.abspath(os.path.expanduser(a)) # Prevent resizing of the banner/posters even if PIL is installed if o in ('--noresize', ): NO_RESIZE = True # Install optional packages from requirements folder if o in ('--install-optional', ): INSTALL_OPTIONAL = True # Install ssl packages from requirements folder if o in ('--ssl', ): SSL = True # Install ssl packages from requirements folder if o in ('--debug', ): print("!!! DEBUGGING MODE ENABLED !!!") DEBUG = True try: # daemonize sickrage ? if DAEMONIZE: daemonize(PIDFILE) import core from core.helpers import makeDir # Make sure that we can create the data dir if not os.access(DATA_DIR, os.F_OK): try: os.makedirs(DATA_DIR, 0o744) except os.error: raise SystemExit("Unable to create data directory '" + DATA_DIR + "'") # Make sure we can write to the data dir if not os.access(DATA_DIR, os.W_OK): raise SystemExit("Data directory must be writeable '" + DATA_DIR + "'") print("Starting SiCKRAGE ...") # init logger srLogger = core.srLogger() # init core srCore = core.srCore() # init config srConfig = core.srConfig(CONFIG_FILE) # load config srConfig.load_config() # start logger srLogger.logFile = os.path.abspath( os.path.join(DATA_DIR, srConfig.LOG_DIR, srConfig.LOG_FILE)) srLogger.logSize = srConfig.LOG_SIZE srLogger.logNr = srConfig.LOG_NR srLogger.consoleLogging = CONSOLE srLogger.debugLogging = DEBUG or srConfig.DEBUG srLogger.fileLogging = makeDir( os.path.abspath(os.path.join(DATA_DIR, srConfig.LOG_DIR))) srLogger.start() # start core srCore.start() # start web-ui srCore.WEBSERVER.open_browser = (True, False)[WEB_NOLAUNCH] srCore.WEBSERVER.port = (srConfig.WEB_PORT, WEB_PORT)[WEB_PORT is not None] srCore.WEBSERVER.start() except ImportError: # install pip package manager install_pip() # install required packages install_requirements() # restart sickrage silently os.execl(sys.executable, sys.executable, *sys.argv) except KeyboardInterrupt: pass except Exception: exc_type, exc_value, exc_traceback = sys.exc_info() traceback.print_tb(exc_traceback) traceback.print_exception(exc_type, exc_value, exc_traceback) sys.exit(1) sys.exit(0)
def main(): global srCore, srConfig, srLogger if sys.version_info < (2, 7): print("Sorry, SiCKRAGE requires Python 2.7+") sys.exit(1) print("Starting SiCKRAGE ...") # add sickrage module to python system path path = os.path.dirname(os.path.realpath(__file__)) if path not in sys.path: sys.path.insert(0, os.path.dirname(os.path.realpath(__file__))) # set thread name threading.currentThread().setName('MAIN') PROG_DIR = os.path.abspath(os.path.dirname(__file__)) DATA_DIR = os.path.join(os.path.expanduser("~"), '.sickrage') CONFIG_FILE = "config.ini" try: opts, _ = getopt.getopt( sys.argv[1:], "hqdp::", ['help', 'dev', 'quiet', 'nolaunch', 'daemon', 'pidfile=', 'port=', 'datadir=', 'config=', 'noresize', 'install-optional', 'ssl', 'debug'] ) except getopt.GetoptError: sys.exit(help_message(PROG_DIR)) # defaults PIDFILE = os.path.abspath(os.path.join(DATA_DIR, 'sickrage.pid')) DEVELOPER = False DAEMONIZE = False WEB_PORT = 8081 INSTALL_OPTIONAL = False WEB_NOLAUNCH = False SSL = False DEBUG = False CONSOLE = not hasattr(sys, "frozen") for o, a in opts: # help message if o in ('-h', '--help'): sys.exit(help_message(PROG_DIR)) # For now we'll just silence the logging if o in ('-q', '--quiet'): CONSOLE = False # developer mode if o in ('--dev',): print("!!! DEVELOPER MODE ENABLED !!!") DEVELOPER = True # Suppress launching web browser # Needed for OSes without default browser assigned # Prevent duplicate browser window when restarting in the app if o in ('--nolaunch',): WEB_NOLAUNCH = True # Override default/configured port if o in ('-p', '--port'): try: WEB_PORT = int(a) except ValueError: sys.exit("Port: " + str(a) + " is not a number. Exiting.") # Run as a double forked daemon if o in ('-d', '--daemon'): DAEMONIZE = (False, True)[not sys.platform == 'win32'] WEB_NOLAUNCH = True CONSOLE = False # Write a pidfile if requested if o in ('--pidfile',): PIDFILE = str(a) # If the pidfile already exists, sickrage may still be running, so exit if os.path.exists(PIDFILE): sys.exit("PID file: " + PIDFILE + " already exists. Exiting.") # Specify folder to use as the data dir if o in ('--datadir',): DATA_DIR = os.path.abspath(a) # Specify folder to load the config file from if o in ('--config',): CONFIG_FILE = os.path.abspath(a) # Prevent resizing of the banner/posters even if PIL is installed if o in ('--noresize',): NO_RESIZE = True # Install optional packages from requirements folder if o in ('--install-optional',): INSTALL_OPTIONAL = True # Install ssl packages from requirements folder if o in ('--ssl',): SSL = True # Install ssl packages from requirements folder if o in ('--debug',): print("!!! DEBUGGING MODE ENABLED !!!") DEBUG = True try: # daemonize sickrage ? if DAEMONIZE: daemonize(PIDFILE) # install/upgrade pip and ssl contexts for required/optional imports if not DEVELOPER: REQS_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), 'requirements')) # install pip package manager install_pip(path=REQS_DIR, user=root_check()) # install required packages install_requirements(path=REQS_DIR, optional=INSTALL_OPTIONAL, ssl=SSL, user=root_check()) import core from core.helpers import makeDir # init logger srLogger = core.srLogger() # init core srCore = core.srCore(PROG_DIR, DATA_DIR) # init config srConfig = core.srConfig(CONFIG_FILE) # load config srConfig.load_config() # start logger srLogger.logFile = os.path.abspath(os.path.join(srCore.DATA_DIR, srConfig.LOG_DIR, srConfig.LOG_FILE)) srLogger.logSize = srConfig.LOG_SIZE srLogger.logNr = srConfig.LOG_NR srLogger.consoleLogging = CONSOLE srLogger.debugLogging = DEBUG or srConfig.DEBUG srLogger.fileLogging = makeDir(os.path.abspath(os.path.join(srCore.DATA_DIR, srConfig.LOG_DIR))) srLogger.start() # start core srCore.start() # start web-ui srCore.WEBSERVER.open_browser = (True, False)[WEB_NOLAUNCH] srCore.WEBSERVER.port = (srConfig.WEB_PORT, WEB_PORT)[WEB_PORT != srConfig.WEB_PORT] srCore.WEBSERVER.start() except KeyboardInterrupt: pass except Exception: exc_type, exc_value, exc_traceback = sys.exc_info() traceback.print_tb(exc_traceback) traceback.print_exception(exc_type, exc_value, exc_traceback) sys.exit(1) sys.exit(0)
sickrage.srConfig.HTTPS_KEY = "server.key" sickrage.srConfig.WEB_USERNAME = "******" sickrage.srConfig.WEB_PASSWORD = "******" sickrage.srConfig.WEB_COOKIE_SECRET = "sickrage" sickrage.srConfig.WEB_ROOT = "" sickrage.srCore.WEBSERVER = None sickrage.srConfig.CPU_PRESET = "NORMAL" sickrage.srConfig.EXTRA_SCRIPTS = [] sickrage.srConfig.LOG_FILE = os.path.join(sickrage.srConfig.LOG_DIR, 'sickrage.log') sickrage.srConfig.LOG_NR = 5 sickrage.srConfig.LOG_SIZE = 1048576 sickrage.srLogger = srLogger(logFile=sickrage.srConfig.LOG_FILE, logSize=sickrage.srConfig.LOG_SIZE, logNr=sickrage.srConfig.LOG_NR, fileLogging=sickrage.srConfig.LOG_DIR, debugLogging=True) sickrage.srConfig.GIT_USERNAME = sickrage.srConfig.check_setting_str('General', 'git_username', '') sickrage.srConfig.GIT_PASSWORD = sickrage.srConfig.check_setting_str('General', 'git_password', '') sickrage.srCore.providersDict = { GenericProvider.NZB: {p.id: p for p in NZBProvider.getProviderList()}, GenericProvider.TORRENT: {p.id: p for p in TorrentProvider.getProviderList()}, } sickrage.srCore.INDEXER_API = srIndexerApi sickrage.srCore.SCHEDULER = srScheduler() sickrage.srCore.NAMECACHE = srNameCache()
def main(): global srCore, srConfig, srLogger, DATA_DIR if sys.version_info < (2, 7): print("Sorry, SiCKRAGE requires Python 2.7+") sys.exit(1) # add sickrage module to python system path path = os.path.dirname(os.path.realpath(__file__)) if path not in sys.path: sys.path.insert(0, os.path.dirname(os.path.realpath(__file__))) # set thread name threading.currentThread().setName("MAIN") try: opts, _ = getopt.getopt( sys.argv[1:], "hqdp::", [ "help", "dev", "quiet", "nolaunch", "daemon", "pidfile=", "port=", "datadir=", "config=", "noresize", "install-optional", "ssl", "debug", ], ) except getopt.GetoptError: sys.exit(help_message(PROG_DIR)) # defaults PIDFILE = os.path.abspath(os.path.join(DATA_DIR, "sickrage.pid")) DEVELOPER = False DAEMONIZE = False WEB_PORT = None INSTALL_OPTIONAL = False WEB_NOLAUNCH = False SSL = False DEBUG = False CONFIG_FILE = "config.ini" CONSOLE = not hasattr(sys, "frozen") for o, a in opts: # help message if o in ("-h", "--help"): sys.exit(help_message(PROG_DIR)) # For now we'll just silence the logging if o in ("-q", "--quiet"): CONSOLE = False # developer mode if o in ("--dev",): print("!!! DEVELOPER MODE ENABLED !!!") DEVELOPER = True # Suppress launching web browser # Needed for OSes without default browser assigned # Prevent duplicate browser window when restarting in the app if o in ("--nolaunch",): WEB_NOLAUNCH = True # Override default/configured port if o in ("-p", "--port"): try: WEB_PORT = int(a) except ValueError: sys.exit("Port: " + str(a) + " is not a number. Exiting.") # Run as a double forked daemon if o in ("-d", "--daemon"): DAEMONIZE = (False, True)[not sys.platform == "win32"] WEB_NOLAUNCH = True CONSOLE = False # Write a pidfile if requested if o in ("--pidfile",): PIDFILE = str(a) # If the pidfile already exists, sickrage may still be running, so exit if os.path.exists(PIDFILE): sys.exit("PID file: " + PIDFILE + " already exists. Exiting.") # Specify folder to use as the data dir if o in ("--datadir",): DATA_DIR = os.path.abspath(a) # Specify folder to load the config file from if o in ("--config",): CONFIG_FILE = os.path.abspath(a) # Prevent resizing of the banner/posters even if PIL is installed if o in ("--noresize",): NO_RESIZE = True # Install optional packages from requirements folder if o in ("--install-optional",): INSTALL_OPTIONAL = True # Install ssl packages from requirements folder if o in ("--ssl",): SSL = True # Install ssl packages from requirements folder if o in ("--debug",): print("!!! DEBUGGING MODE ENABLED !!!") DEBUG = True try: print("Starting SiCKRAGE ...") # Make sure that we can create the data dir if not os.access(DATA_DIR, os.F_OK): try: os.makedirs(DATA_DIR, 0o744) except os.error: raise SystemExit("Unable to create data directory '" + DATA_DIR + "'") # Make sure we can write to the data dir if not os.access(DATA_DIR, os.W_OK): raise SystemExit("Data directory must be writeable '" + DATA_DIR + "'") # daemonize sickrage ? if DAEMONIZE: daemonize(PIDFILE) # install/upgrade pip and ssl contexts for required/optional imports if not DEVELOPER: # install pip package manager install_pip() # install required packages install_requirements(optional=INSTALL_OPTIONAL, ssl=SSL) import core from core.helpers import makeDir # init logger srLogger = core.srLogger() # init core srCore = core.srCore() # init config srConfig = core.srConfig(CONFIG_FILE) # load config srConfig.load_config() # start logger srLogger.logFile = os.path.abspath(os.path.join(DATA_DIR, srConfig.LOG_DIR, srConfig.LOG_FILE)) srLogger.logSize = srConfig.LOG_SIZE srLogger.logNr = srConfig.LOG_NR srLogger.consoleLogging = CONSOLE srLogger.debugLogging = DEBUG or srConfig.DEBUG srLogger.fileLogging = makeDir(os.path.abspath(os.path.join(DATA_DIR, srConfig.LOG_DIR))) srLogger.start() # start core srCore.start() # start web-ui srCore.WEBSERVER.open_browser = (True, False)[WEB_NOLAUNCH] srCore.WEBSERVER.port = (srConfig.WEB_PORT, WEB_PORT)[WEB_PORT is not None] srCore.WEBSERVER.start() except KeyboardInterrupt: pass except Exception: exc_type, exc_value, exc_traceback = sys.exc_info() traceback.print_tb(exc_traceback) traceback.print_exception(exc_type, exc_value, exc_traceback) sys.exit(1) sys.exit(0)