'Start SickRage'

def start(self):

    sickbeard.MY_FULLNAME = ek(os.path.normpath, ek(os.path.abspath, __file__))
    sickbeard.MY_NAME = ek(os.path.basename, sickbeard.MY_FULLNAME)
    sickbeard.PROG_DIR = ek(os.path.dirname, sickbeard.MY_FULLNAME)
    sickbeard.LOCALE_DIR = ek(os.path.join, sickbeard.PROG_DIR, u'locale')
    sickbeard.DATA_DIR = sickbeard.PROG_DIR
    sickbeard.MY_ARGS = sys.argv[1:]
    try:
        locale.setlocale(locale.LC_ALL, u'')
        sickbeard.SYS_ENCODING = locale.getpreferredencoding()
    except (locale.Error, IOError):
        sickbeard.SYS_ENCODING = u'UTF-8'
    if ((not sickbeard.SYS_ENCODING) or (sickbeard.SYS_ENCODING.lower() in (u'ansi_x3.4-1968', u'us-ascii', u'ascii', u'charmap')) or (sys.platform.startswith(u'win') and (sys.getwindowsversion()[0] >= 6) and (str(getattr(sys.stdout, u'device', sys.stdout).encoding).lower() in (u'cp65001', u'charmap')))):
        sickbeard.SYS_ENCODING = u'UTF-8'
    if (not hasattr(sys, u'setdefaultencoding')):
        reload_module(sys)
    try:
        sys.setdefaultencoding(sickbeard.SYS_ENCODING)
    except (AttributeError, LookupError):
        sys.exit(u'Sorry,    you    MUST    add    the    SickRage    folder    to    the    PYTHONPATH    environment    variable\nor    find    another    way    to    force    Python    to    use    {}    for    string    encoding.'.format(sickbeard.SYS_ENCODING))
    threading.currentThread().name = u'MAIN'
    args = SickRageArgumentParser(sickbeard.PROG_DIR).parse_args()
    if args.force_update:
        result = self.force_update()
        sys.exit(int((not result)))
    sickbeard.NO_RESIZE = args.noresize
    self.console_logging = ((not hasattr(sys, u'frozen')) or ((sickbeard.MY_NAME.lower().find(u'-console') > 0) and (not args.quiet)))
    self.no_launch = args.nolaunch
    self.forced_port = args.port
    if args.daemon:
        self.run_as_daemon = (platform.system() != u'Windows')
        self.console_logging = False
        self.no_launch = True
    self.create_pid = bool(args.pidfile)
    self.pid_file = args.pidfile
    if (self.pid_file and ek(os.path.exists, self.pid_file)):
        raise SystemExit(u'PID    file:    {0}    already    exists.    Exiting.'.format(self.pid_file))
    sickbeard.DATA_DIR = (ek(os.path.abspath, args.datadir) if args.datadir else sickbeard.DATA_DIR)
    sickbeard.CONFIG_FILE = (ek(os.path.abspath, args.config) if args.config else ek(os.path.join, sickbeard.DATA_DIR, u'config.ini'))
    if self.create_pid:
        if self.run_as_daemon:
            pid_dir = ek(os.path.dirname, self.pid_file)
            if (not ek(os.access, pid_dir, os.F_OK)):
                sys.exit(u"PID    dir:    {0}    doesn't    exist.    Exiting.".format(pid_dir))
            if (not ek(os.access, pid_dir, os.W_OK)):
                raise SystemExit(u'PID    dir:    {0}    must    be    writable    (write    permissions).    Exiting.'.format(pid_dir))
        else:
            if self.console_logging:
                sys.stdout.write(u'Not    running    in    daemon    mode.    PID    file    creation    disabled.\n')
            self.create_pid = False
    if (not ek(os.access, sickbeard.DATA_DIR, os.F_OK)):
        try:
            ek(os.makedirs, sickbeard.DATA_DIR, 484)
        except os.error:
            raise SystemExit(u'Unable    to    create    data    directory:    {0}'.format(sickbeard.DATA_DIR))
    if (not ek(os.access, sickbeard.DATA_DIR, os.W_OK)):
        raise SystemExit(u'Data    directory    must    be    writeable:    {0}'.format(sickbeard.DATA_DIR))
    if (not ek(os.access, sickbeard.CONFIG_FILE, os.W_OK)):
        if ek(os.path.isfile, sickbeard.CONFIG_FILE):
            raise SystemExit(u'Config    file    must    be    writeable:    {0}'.format(sickbeard.CONFIG_FILE))
        elif (not ek(os.access, ek(os.path.dirname, sickbeard.CONFIG_FILE), os.W_OK)):
            raise SystemExit(u'Config    file    root    dir    must    be    writeable:    {0}'.format(ek(os.path.dirname, sickbeard.CONFIG_FILE)))
    ek(os.chdir, sickbeard.DATA_DIR)
    restore_dir = ek(os.path.join, sickbeard.DATA_DIR, u'restore')
    if ek(os.path.exists, restore_dir):
        success = self.restore_db(restore_dir, sickbeard.DATA_DIR)
        if self.console_logging:
            sys.stdout.write(u'Restore:    restoring    DB    and    config.ini    {0}!\n'.format((u'FAILED', u'SUCCESSFUL')[success]))
    if (self.console_logging and (not ek(os.path.isfile, sickbeard.CONFIG_FILE))):
        sys.stdout.write(u'Unable    to    find    {0},    all    settings    will    be    default!\n'.format(sickbeard.CONFIG_FILE))
    sickbeard.CFG = ConfigObj(sickbeard.CONFIG_FILE, encoding=u'UTF-8')
    sickbeard.initialize(consoleLogging=self.console_logging)
    if self.run_as_daemon:
        self.daemonize()
    sickbeard.PID = os.getpid()
    self.load_shows_from_db()
    logger.log(u"Starting    SickRage    [{branch}]    using    '{config}'".format(branch=sickbeard.BRANCH, config=sickbeard.CONFIG_FILE))
    self.clear_cache()
    if self.forced_port:
        logger.log(u'Forcing    web    server    to    port    {port}'.format(port=self.forced_port))
        self.start_port = self.forced_port
    else:
        self.start_port = sickbeard.WEB_PORT
    if sickbeard.WEB_LOG:
        self.log_dir = sickbeard.LOG_DIR
    else:
        self.log_dir = None
    if (sickbeard.WEB_HOST and (sickbeard.WEB_HOST != u'0.0.0.0')):
        self.web_host = sickbeard.WEB_HOST
    else:
        self.web_host = (u'' if sickbeard.WEB_IPV6 else u'0.0.0.0')
    self.web_options = {u'port': int(self.start_port), u'host': self.web_host, u'data_root': ek(os.path.join, sickbeard.PROG_DIR, u'gui', sickbeard.GUI_NAME), u'web_root': sickbeard.WEB_ROOT, u'log_dir': self.log_dir, u'username': sickbeard.WEB_USERNAME, u'password': sickbeard.WEB_PASSWORD, u'enable_https': sickbeard.ENABLE_HTTPS, u'handle_reverse_proxy': sickbeard.HANDLE_REVERSE_PROXY, u'https_cert': ek(os.path.join, sickbeard.PROG_DIR, sickbeard.HTTPS_CERT), u'https_key': ek(os.path.join, sickbeard.PROG_DIR, sickbeard.HTTPS_KEY)}
    self.web_server = SRWebServer(self.web_options)
    self.web_server.start()
    sickbeard.start()
    name_cache.buildNameCache()
    network_timezones.update_network_dict()
    if sickbeard.USE_FAILED_DOWNLOADS:
        failed_history.trimHistory()
    if (sickbeard.LAUNCH_BROWSER and (not (self.no_launch or self.run_as_daemon))):
        sickbeard.launchBrowser((u'https' if sickbeard.ENABLE_HTTPS else u'http'), self.start_port, sickbeard.WEB_ROOT)
    while True:
        time.sleep(1)
