Example #1
0
from sickrage.core.tv import episode
from sickrage.core.webserver import SRWebServer

# =================
# test globals
# =================
from sickrage.indexers.indexer_api import indexerApi
from sickrage.metadata import get_metadata_generator_dict
from sickrage.providers import NewznabProvider, GenericProvider, NZBProvider, TorrentProvider, TorrentRssProvider

threading.currentThread().setName("TESTS")

socket.setdefaulttimeout(30)

# install packages
install_reqs()

TESTALL = False
TESTSKIPPED = ["test_issue_submitter", "test_ssl_sni"]
TESTDIR = os.path.abspath(os.path.dirname(__file__))
TESTDBNAME = "sickrage.db"
TESTCACHEDBNAME = "cache.db"
TESTFAILEDDBNAME = "failed.db"

SHOWNAME = "show name"
SEASON = 4
EPISODE = 2
FILENAME = "show name - s0" + str(SEASON) + "e0" + str(EPISODE) + ".mkv"
FILEDIR = os.path.join(TESTDIR, SHOWNAME)
FILEPATH = os.path.join(FILEDIR, FILENAME)
SHOWDIR = os.path.join(TESTDIR, SHOWNAME + " final")
Example #2
0
def main():
    global APP_NAME, MY_FULLNAME, NO_RESIZE, MY_ARGS, WEB_PORT, WEB_NOLAUNCH, CREATEPID, DAEMONIZE, PIDFILE, \
        ROOT_DIR, PROG_DIR, DATA_DIR, CONFIG_FILE, WEB_SERVER, VERSIONUPDATER, DEVELOPER, LOGGER

    if sys.version_info < (2, 7):
        print("Sorry, SiCKRAGE requires Python 2.7+")
        sys.exit(1)

    # set thread name
    threading.currentThread().setName('MAIN')

    APP_NAME = 'SiCKRAGE'
    DATA_DIR = ROOT_DIR = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
    PROG_DIR = os.path.abspath(os.path.dirname(__file__))
    MY_ARGS = sys.argv[1:]

    consoleLogging = (not hasattr(sys, "frozen")) or (APP_NAME.lower().find('-console') > 0)

    # defaults
    INSTALL_OPTIONAL = False

    # auto-detect user rights
    USER = root_check()

    try:
        opts, _ = getopt.getopt(
                sys.argv[1:], "hqdp::",
                ['help',
                 'dev',
                 'quiet',
                 'nolaunch',
                 'daemon',
                 'pidfile=',
                 'port=',
                 'datadir=',
                 'config=',
                 'noresize',
                 'install-optional',
                 'user']
        )
    except getopt.GetoptError:
        sys.exit(help_message())

    for o, a in opts:
        # help message
        if o in ('-h', '--help'):
            sys.exit(help_message())

        # For now we'll just silence the logging
        if o in ('-q', '--quiet'):
            consoleLogging = 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 = True
            WEB_NOLAUNCH = True
            consoleLogging = False

            if sys.platform == 'win32' or sys.platform == 'darwin':
                DAEMONIZE = False

        # Write a pidfile if requested
        if o in ('--pidfile',):
            CREATEPID = True
            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 load the config file from
        if o in ('--config',):
            CONFIG_FILE = os.path.abspath(a)

        # Specify folder to use as the data dir
        if o in ('--datadir',):
            DATA_DIR = 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 optional packages from requirements folder
        if o in ('--user',):
            USER = True


    # install/upgrade pip and ssl contexts for required/optional imports
    if not DEVELOPER:
        install_reqs(optional=INSTALL_OPTIONAL, user=USER)

    # init logging
    from sickrage.core.srlogger import srLogger
    LOGGER = srLogger(consoleLogging=consoleLogging)

    # The pidfile is only useful in daemon mode, make sure we can write the file properly
    if CREATEPID:
        if DAEMONIZE:
            pid_dir = os.path.dirname(PIDFILE)
            if not os.access(pid_dir, os.F_OK):
                sys.exit("PID dir: " + pid_dir + " doesn't exist. Exiting.")
            if not os.access(pid_dir, os.W_OK):
                sys.exit("PID dir: " + pid_dir + " must be writable (write permissions). Exiting.")

        else:
            CREATEPID = False
            LOGGER.info("Not running in daemon mode. PID file creation disabled.\n")

    # If they don't specify a config file then put it in the data dir
    if not CONFIG_FILE:
        CONFIG_FILE = os.path.join(DATA_DIR, "config.ini")

    # 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 datadir '" + DATA_DIR + "'")

    # Make sure we can write to the data dir
    if not os.access(DATA_DIR, os.W_OK):
        raise SystemExit("Datadir must be writeable '" + DATA_DIR + "'")

    # Make sure we can write to the config file
    if not os.access(CONFIG_FILE, os.W_OK):
        if os.path.isfile(CONFIG_FILE):
            raise SystemExit("Config file '" + CONFIG_FILE + "' must be writeable.")
        elif not os.access(os.path.dirname(CONFIG_FILE), os.W_OK):
            raise SystemExit(
                    "Config file root dir '" + os.path.dirname(CONFIG_FILE) + "' must be writeable.")

    try:
        # initialize and startup sickrage
        from sickrage import core
        if core.initialize():
            WEB_SERVER.start()
    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)