Exemplo n.º 1
0
def restart(exit=False):
    log.info("Restarting")
    if exit:
        # Exit current process and restart a new one with the same args
        # Get executable and args
        popen_list = [sys.executable, autosubliminal.EXECUTABLE]
        popen_list += autosubliminal.ARGS
        # Stop without exit
        stop(exit=False)
        log.info("Exiting application with PID: %s" % autosubliminal.PID)
        log.info("Restarting application with command and arguments: %s" %
                 popen_list)
        log.info("#" * 50)
        # Shutdown the logger to make sure the logfile is released before starting a new process
        logging.shutdown()
        # Start new process
        subprocess.Popen(popen_list, cwd=os.getcwd())
        # Exit current process
        _exit(shutdown_logger=False)
    else:
        # Stop without killing current process and restart
        stop(exit=False)
        autosubliminal.initialize()
        start()
        log.info("Restarted")
Exemplo n.º 2
0
def restart(exit=False):
    log.info('Restarting')
    if exit:
        # Exit current process and restart a new one with the same args
        # Get executable and args
        popen_list = [sys.executable, autosubliminal.EXECUTABLE]
        popen_list += autosubliminal.ARGS
        # Stop without exit
        stop(exit=False)
        log.info('Restarting application with command and arguments: %s',
                 popen_list)
        log.info('Exiting application with PID: %s', autosubliminal.PID)
        # Shutdown
        _shutdown()
        # Start new process
        subprocess.Popen(popen_list, cwd=getcwd())
        # Exit current process
        _exit()
    else:
        # Stop without killing current process and restart
        stop(exit=False)
        autosubliminal.initialize()
        start_server(True)
        start()
        log.info('Restarted')
Exemplo n.º 3
0
def restart(exit=False):
    log.info("Restarting")
    if exit:
        # Exit current process and restart a new one with the same args
        # Get executable and args
        popen_list = [sys.executable, autosubliminal.EXECUTABLE]
        popen_list += autosubliminal.ARGS
        # Stop without exit
        stop(exit=False)
        log.info("Exiting application with PID: %s" % autosubliminal.PID)
        log.info("Restarting application with command and arguments: %s" % popen_list)
        log.info("#" * 50)
        # Shutdown the logger to make sure the logfile is released before starting a new process
        logging.shutdown()
        # Start new process
        subprocess.Popen(popen_list, cwd=os.getcwd())
        # Exit current process
        _exit(shutdown_logger=False)
    else:
        # Stop without killing current process and restart
        stop(exit=False)
        autosubliminal.initialize()
        start()
        log.info("Restarted")
Exemplo n.º 4
0
def restart(exit=False):
    log.info('Restarting')
    if exit:
        # Exit current process and restart a new one with the same args
        # Get executable and args
        popen_list = [sys.executable, autosubliminal.EXECUTABLE]
        popen_list += autosubliminal.ARGS
        # Stop without exit
        stop(exit=False)
        log.info('Restarting application with command and arguments: %s', popen_list)
        log.info('Exiting application with PID: %s', autosubliminal.PID)
        # Shutdown
        _shutdown()
        # Start new process
        subprocess.Popen(popen_list, cwd=getcwd())
        # Exit current process
        _exit()
    else:
        # Stop without killing current process and restart
        stop(exit=False)
        autosubliminal.initialize()
        start_server(True)
        start()
        log.info('Restarted')
Exemplo n.º 5
0
def main(argv=None):
    from six import binary_type

    import autosubliminal

    # Set startup parameters
    autosubliminal.EXECUTABLE = os.path.normpath(os.path.realpath(__file__))
    autosubliminal.ARGS = sys.argv[1:]

    # From Sickbeard / Headphones
    try:
        locale.setlocale(locale.LC_ALL, '')
        autosubliminal.SYSENCODING = locale.getpreferredencoding()
    except (locale.Error, IOError):
        pass

    # For OSes that are poorly configured, like synology & slackware
    if not autosubliminal.SYSENCODING or autosubliminal.SYSENCODING in (
            'ANSI_X3.4-1968', 'US-ASCII', 'ASCII'):
        autosubliminal.SYSENCODING = 'UTF-8'

    if argv is None:
        argv = sys.argv
    try:
        try:
            opts, args = getopt.getopt(
                argv[1:], 'hc:dl', ['help', 'config=', 'daemon', 'nolaunch'])
        except getopt.error as msg:
            raise Usage(msg)

        # Option processing
        for option, value in opts:
            if option in ('-h', '--help'):
                raise Usage(help_message)
            if option in ('-c', '--config'):
                if os.path.exists(value):
                    autosubliminal.CONFIGFILE = value
                else:
                    print('ERROR: Configfile does not exists.')
                    os._exit(0)
            if option in ('-l', '--nolaunch'):
                autosubliminal.LAUNCHBROWSER = False
            if option in ('-d', '--daemon'):
                if sys.platform == 'win32':
                    print('ERROR: No support for daemon mode in Windows.')
                else:
                    autosubliminal.DAEMON = True

    except Usage as err:
        sys.stderr.write(sys.argv[0].split('/')[-1] + ': ' +
                         binary_type(err.msg) + '\n')
        sys.stderr.write('For help use --help\n')
        return 2

    # Initialize configuration
    if os.path.isfile('config.properties.dev'):
        print('WARNING: Using development configuration file.')
        autosubliminal.CONFIGFILE = 'config.properties.dev'
    print('INFO: Initializing variables and loading config.')
    autosubliminal.initialize()

    # Setup application
    import autosubliminal.application

    # Setup signal handler
    signal.signal(signal.SIGINT, autosubliminal.application.signal_handler)

    # Setup daemon
    if autosubliminal.DAEMON:
        autosubliminal.application.daemon()

    # Set the PID
    autosubliminal.PID = os.getpid()

    print('INFO: Starting output to log.')
    print('INFO: Bye.')
    log = logging.getLogger(__name__)
    log.info('#' * 40)
    log.info('Running application with PID: %s', autosubliminal.PID)
    log.info('System encoding: %s', autosubliminal.SYSENCODING)
    log.info('Config version: %d', autosubliminal.CONFIGVERSION)
    log.info('Db version: %d', autosubliminal.DBVERSION)
    log.info('#' * 40)

    # Start server and application
    autosubliminal.application.start_server()
    autosubliminal.application.start()

    # Launch browser after threads because cherrypy webserver must be started first
    if autosubliminal.LAUNCHBROWSER:
        autosubliminal.application.launch_browser()

    log.info(
        'Application started, going into a loop to keep the main thread going')
    while True:
        time.sleep(1)
Exemplo n.º 6
0
def restart():
    log.debug("Restarting")
    stop(exit_app=False)
    autosubliminal.initialize()
    start()
    log.debug("Restarted")
Exemplo n.º 7
0
                if sys.platform == "win32":
                    print "ERROR: No support for daemon mode in Windows"
                else:
                    autosubliminal.DAEMON = True

    except Usage, err:
        print >> sys.stderr, sys.argv[0].split("/")[-1] + ": " + str(err.msg)
        print >> sys.stderr, "\t for help use --help"
        return 2

    # Initialize configuration
    if os.path.isfile('config.properties.dev'):
        print "WARNING: Using development configuration file."
        autosubliminal.CONFIGFILE = 'config.properties.dev'
    print "INFO: Initializing variables and loading config."
    autosubliminal.initialize()

    # Change to the new work directory
    if os.path.exists(autosubliminal.PATH):
        os.chdir(autosubliminal.PATH)
    else:
        print "ERROR: PATH does not exist, check config"
        os._exit(1)

    # Setup runner
    import autosubliminal.runner
    signal.signal(signal.SIGINT, autosubliminal.runner.signal_handler)

    if autosubliminal.DAEMON:
        autosubliminal.runner.daemon()
Exemplo n.º 8
0
                if sys.platform == "win32":
                    print "ERROR: No support for daemon mode in Windows"
                else:
                    autosubliminal.DAEMON = True

    except Usage, err:
        print >> sys.stderr, sys.argv[0].split("/")[-1] + ": " + str(err.msg)
        print >> sys.stderr, "\t for help use --help"
        return 2

    # Initialize configuration
    if os.path.isfile('config.properties.dev'):
        print "WARNING: Using development configuration file."
        autosubliminal.CONFIGFILE = 'config.properties.dev'
    print "INFO: Initializing variables and loading config."
    autosubliminal.initialize()

    # Change to the new work directory
    if os.path.exists(autosubliminal.PATH):
        os.chdir(autosubliminal.PATH)
    else:
        print "ERROR: PATH does not exist, check config"
        os._exit(1)

    # Setup runner
    import autosubliminal.runner
    signal.signal(signal.SIGINT, autosubliminal.runner.signal_handler)

    if autosubliminal.DAEMON:
        autosubliminal.runner.daemon()
Exemplo n.º 9
0
def main(argv=None):
    from six import binary_type

    import autosubliminal

    # Set startup parameters
    autosubliminal.EXECUTABLE = os.path.normpath(os.path.realpath(__file__))
    autosubliminal.ARGS = sys.argv[1:]

    # From Sickbeard / Headphones
    try:
        locale.setlocale(locale.LC_ALL, '')
        autosubliminal.SYSENCODING = locale.getpreferredencoding()
    except (locale.Error, IOError):
        pass

    # For OSes that are poorly configured, like synology & slackware
    if not autosubliminal.SYSENCODING or autosubliminal.SYSENCODING in ('ANSI_X3.4-1968', 'US-ASCII', 'ASCII'):
        autosubliminal.SYSENCODING = 'UTF-8'

    if argv is None:
        argv = sys.argv
    try:
        try:
            opts, args = getopt.getopt(argv[1:], 'hc:dl', ['help', 'config=', 'daemon', 'nolaunch'])
        except getopt.error as msg:
            raise Usage(msg)

        # Option processing
        for option, value in opts:
            if option in ('-h', '--help'):
                raise Usage(help_message)
            if option in ('-c', '--config'):
                if os.path.exists(value):
                    autosubliminal.CONFIGFILE = value
                else:
                    print('ERROR: Configfile does not exists.')
                    os._exit(0)
            if option in ('-l', '--nolaunch'):
                autosubliminal.LAUNCHBROWSER = False
            if option in ('-d', '--daemon'):
                if sys.platform == 'win32':
                    print('ERROR: No support for daemon mode in Windows.')
                else:
                    autosubliminal.DAEMON = True

    except Usage as err:
        sys.stderr.write(sys.argv[0].split('/')[-1] + ': ' + binary_type(err.msg) + '\n')
        sys.stderr.write('For help use --help\n')
        return 2

    # Initialize configuration
    if os.path.isfile('config.properties.dev'):
        print('WARNING: Using development configuration file.')
        autosubliminal.CONFIGFILE = 'config.properties.dev'
    print('INFO: Initializing variables and loading config.')
    autosubliminal.initialize()

    # Setup application
    import autosubliminal.application

    # Setup signal handler
    signal.signal(signal.SIGINT, autosubliminal.application.signal_handler)

    # Setup daemon
    if autosubliminal.DAEMON:
        autosubliminal.application.daemon()

    # Set the PID
    autosubliminal.PID = os.getpid()

    print('INFO: Starting output to log.')
    print('INFO: Bye.')
    log = logging.getLogger(__name__)
    log.info('#' * 40)
    log.info('Running application with PID: %s', autosubliminal.PID)
    log.info('System encoding: %s', autosubliminal.SYSENCODING)
    log.info('Config version: %d', autosubliminal.CONFIGVERSION)
    log.info('Db version: %d', autosubliminal.DBVERSION)
    log.info('#' * 40)

    # Start server and application
    autosubliminal.application.start_server()
    autosubliminal.application.start()

    # Launch browser after threads because cherrypy webserver must be started first
    if autosubliminal.LAUNCHBROWSER:
        autosubliminal.application.launch_browser()

    log.info('Application started, going into a loop to keep the main thread going')
    while True:
        time.sleep(1)