Ejemplo n.º 1
0
def detectPort():
    try:
        if not isRunning(AceProxy.ace):
            logger.error("Couldn't detect port! Ace Engine is not running?")
            clean_proc()
            sys.exit(1)
    except AttributeError:
        logger.error("Ace Engine is not running!")
        clean_proc()
        sys.exit(1)
    from urllib3.packages.six.moves.winreg import ConnectRegistry, OpenKey, QueryValueEx, HKEY_CURRENT_USER
    try:
        key = OpenKey(ConnectRegistry(None, HKEY_CURRENT_USER),
                      r'Software\AceStream')
    except:
        logger.error("Can't find AceStream!")
        clean_proc()
        sys.exit(1)
    else:
        engine = QueryValueEx(key, 'EnginePath')
        AceProxy.acedir = os.path.dirname(engine[0])
        try:
            gevent.sleep(AceConfig.acestartuptimeout)
            with open(AceProxy.acedir + '\\acestream.port', 'r') as f:
                AceConfig.ace['aceAPIport'] = f.read()
        except IOError:
            logger.error(
                "Couldn't detect port! acestream.port file doesn't exist?")
            clean_proc()
            sys.exit(1)
        else:
            logger.info(
                'Detected ace port: {aceAPIport}'.format(**AceConfig.ace))
Ejemplo n.º 2
0
def spawnAce(cmd='' if AceConfig.osplatform == 'Windows' else
             AceConfig.acecmd.split(),
             delay=AceConfig.acestartuptimeout):
    if AceConfig.osplatform == 'Windows':
        from urllib3.packages.six.moves.winreg import ConnectRegistry, OpenKey, QueryValueEx, HKEY_CURRENT_USER
        try:
            key = OpenKey(ConnectRegistry(None, HKEY_CURRENT_USER),
                          r'Software\AceStream')
        except:
            logger.error("Can't find acestream!")
            sys.exit(1)
        else:
            engine = QueryValueEx(key, 'EnginePath')
            cmd, AceProxy.acedir = engine[0].split(), os.path.dirname(
                engine[0])
    try:
        logger.debug('AceEngine start up .....')
        AceProxy.ace = gevent.event.AsyncResult()
        gevent.spawn(
            lambda: psutil.Popen(cmd, stdout=DEVNULL, stderr=DEVNULL)).link(
                AceProxy.ace)
        AceProxy.ace = AceProxy.ace.get(timeout=delay if delay >= 0 else 0.5)
        return isRunning(AceProxy.ace)
    except:
        return False