Exemple #1
0
def run():
    url = "http://localhost:9001"
    s = xmlrpclib.ServerProxy(url)

    while 1:
        try:
            response = s.broker.get()
        except Exception, e:
            log.exception("Problem connecting to %s: %s", url, e)
            break

        if not response:
            print log.info("Nothing to do.")
            break

        cmd, arg = response
        log.info("Received: %s %s", cmd, arg)

        if not arg:
            log.error("Missing argument for command %s.", cmd)

        #        if cmd == 'index':
        #            index(arg)

        elif cmd == "update":
            update(arg)

        elif cmd == "invalidate":
            invalidate(arg)
Exemple #2
0
def worker(worker_info, password, remote):
  global ALIVE

  payload = {
    'worker_info': worker_info,
    'password': password,
  }

  try:
    req = requests.post(remote + '/api/request_version', data=json.dumps(payload), headers={'Content-type': 'application/json'})
    req = json.loads(req.text)

    if 'version' not in req:
      print 'Incorrect username/password'
      time.sleep(5)
      sys.exit(1)

    if req['version'] > WORKER_VERSION:
      print 'Updating worker version to %d' % (req['version'])
      update()

    req = requests.post(remote + '/api/request_task', data=json.dumps(payload), headers={'Content-type': 'application/json'})
    req = json.loads(req.text)
  except:
    sys.stderr.write('Exception accessing host:\n')
    traceback.print_exc()
    time.sleep(10)
    return

  if 'error' in req:
    raise Exception('Error from remote: %s' % (req['error']))

  # No tasks ready for us yet, just wait...
  if 'task_waiting' in req:
    print 'No tasks available at this time, waiting...'
    time.sleep(10)
    return

  success = True
  run, task_id = req['run'], req['task_id']
  try:
    run_games(worker_info, password, remote, run, task_id)
  except:
    sys.stderr.write('\nException running games:\n')
    traceback.print_exc()
    success = False
  finally:
    payload = {
      'username': worker_info['username'],
      'password': password,
      'run_id': str(run['_id']),
      'task_id': task_id
    }
    try:
      requests.post(remote + '/api/failed_task', data=json.dumps(payload), headers={'Content-type': 'application/json'})
    except:
      pass
    sys.stderr.write('Task exited\n')

  return success
    async def start_macro(self):
        ''' Starts the main batch process '''
        options = self.get_selected_options()
        self.builder.get_object('start')['state'] = 'disabled'
        save_state({
            'options': self.get_options(),
            'accounts': self.accounts,
        })
        update(self.logger)

        for idx, account in enumerate(self.accounts):
            if len(account) == 2:
                tree = self.builder.get_object('accounts')
                child_id = tree.get_children()[idx]
                tree.focus(child_id)
                tree.selection_set(child_id)
                try:
                    account_ = types.SimpleNamespace(username=account[0],
                                                     password=account[1],
                                                     region=REGION,
                                                     locale=LOCALE)
                    response = await self.macro.do_macro(options, account_)
                    self.builder_wrapper.set_cell('accounts', idx, 3,
                                                  response['blue_essence'])
                    self.accounts[idx].append(response['blue_essence'])
                except AuthenticationFailureException:
                    logging.info('Account %s has invalid credentials',
                                 account[0])
                except ConsentRequiredException:
                    logging.info('Account %s needs consent', account[0])
            progress = (idx + 1) * 100 // len(self.accounts)
            self.builder.get_object('progress')['value'] = progress
        self.builder.get_object('start')['state'] = 'normal'
Exemple #4
0
    def test_update(self, run_command, fs):
        run_command.return_value = {}

        update(mock.MagicMock(), {})
        run_command.assert_called_once_with([
            'yum', 'update', '--disablerepo="*"',
            '--enablerepo=' + ','.join(DEFAULT_REPOS), '-y'
        ])
Exemple #5
0
def read_user_input():
    option = raw_input("Please enter your choice :")
    if (int(option) == 1):
        logger_modules.print_list()
    elif (int(option) == 2):
        attack_modules.print_list()
    elif (int(option) == 3):
        updater.update()
Exemple #6
0
    def test_update_with_additional_repos(self, run_command, fs):
        run_command.return_value = {}

        repos = DEFAULT_REPOS + ('totoro', 'lalala')
        update(mock.MagicMock(), {'repos': 'totoro, lalala'})
        run_command.assert_called_once_with([
            'yum', 'update', '--disablerepo="*"',
            '--enablerepo=' + ','.join(repos), '-y'
        ])
Exemple #7
0
    def test_update_with_packages(self, run_command, fs):
        run_command.return_value = {}

        packages = 'toto tata titi'
        update(mock.MagicMock(), {'packages': packages})
        run_command.assert_called_once_with([
            'yum', 'update', '--disablerepo="*"',
            '--enablerepo=' + ','.join(DEFAULT_REPOS), '-y', packages
        ])
Exemple #8
0
def worker(worker_info, password, remote):
    global ALIVE

    payload = {"worker_info": worker_info, "password": password}

    try:
        req = requests.post(remote + "/api/request_version", data=json.dumps(payload))
        req = json.loads(req.text)

        if "version" not in req:
            print "Incorrect username/password"
            time.sleep(5)
            sys.exit(1)

        if req["version"] > WORKER_VERSION:
            print "Updating worker version to %d" % (req["version"])
            update()

        req = requests.post(remote + "/api/request_task", data=json.dumps(payload))
        req = json.loads(req.text)
    except:
        sys.stderr.write("Exception accessing host:\n")
        traceback.print_exc()
        time.sleep(10)
        return

    if "error" in req:
        raise Exception("Error from remote: %s" % (req["error"]))

    # No tasks ready for us yet, just wait...
    if "task_waiting" in req:
        time.sleep(10)
        return

    success = True
    run, task_id = req["run"], req["task_id"]
    try:
        run_games(worker_info, password, remote, run, task_id)
    except:
        sys.stderr.write("\nException running games:\n")
        traceback.print_exc()
        success = False
    finally:
        payload = {
            "username": worker_info["username"],
            "password": password,
            "run_id": str(run["_id"]),
            "task_id": task_id,
        }
        try:
            requests.post(remote + "/api/failed_task", data=json.dumps(payload))
        except:
            pass
        sys.stderr.write("Task exited\n")

    return success
Exemple #9
0
    def test_update_during_update(self, run_command, fs):
        fs.create_file(pytest.plugins_lock_file, contents='update')

        run_command.return_value = {}

        update(mock.MagicMock(), {})
        run_command.assert_called_once_with([
            'yum', 'update', '--disablerepo="*"',
            '--enablerepo=' + ','.join(DEFAULT_REPOS), '-y'
        ])
Exemple #10
0
    def test_update_error(self, run_command, fs):
        run_command.side_effect = Exception('Error!')

        with pytest.raises(XenAPIPlugin.Failure) as e:
            update(mock.MagicMock(), {})
        run_command.assert_called_once_with([
            'yum', 'update', '--disablerepo="*"',
            '--enablerepo=' + ','.join(DEFAULT_REPOS), '-y'
        ])
        assert e.value.params[0] == '-1'
        assert e.value.params[1] == 'Error!'
Exemple #11
0
    def test_update_with_additional_repos_and_packages(self, run_command, fs):
        run_command.return_value = {}

        repos = DEFAULT_REPOS + ('riri', 'fifi', 'loulou')
        packages = 'donald hortense'
        update(mock.MagicMock(), {
            'repos': 'riri, fifi, loulou',
            'packages': packages
        })
        run_command.assert_called_once_with([
            'yum', 'update', '--disablerepo="*"',
            '--enablerepo=' + ','.join(repos), '-y', packages
        ])
Exemple #12
0
def run():
	xbmc.output("[totlol.py] run")
	
	# Imprime en el log los parámetros de entrada
	xbmc.output("[totlol.py] sys.argv=%s" % str(sys.argv))
	
	# Crea el diccionario de parametros
	params = dict()
	if len(sys.argv)>=2 and len(sys.argv[2])>0:
		params = dict(part.split('=') for part in sys.argv[ 2 ][ 1: ].split('&'))
	xbmc.output("[totlol.py] params=%s" % str(params))
	
	# Extrae la url de la página
	if (params.has_key("url")):
		url = urllib.unquote_plus( params.get("url") )
	else:
		url=''
	xbmc.output("[totlol.py] url="+url)

	# Extrae la accion
	if (params.has_key("action")):
		action = params.get("action")
	else:
		action = "selectchannel"
	xbmc.output("[totlol.py] action="+action)

	# Extrae la categoria
	if (params.has_key("category")):
		category = params.get("category")
	else:
		if params.has_key("channel"):
			category = params.get("channel")
		else:
			category = ""
	xbmc.output("[totlol.py] category="+category)


	# Accion por defecto - elegir canal
	if ( action=="selectchannel" ):
		import channelselector as plugin
		plugin.listchannels(params, url, category)
	# Actualizar version
	elif ( action=="update" ):
		import updater
		updater.update(params)
		import channelselector as plugin
		plugin.listchannels(params, url, category)
	# El resto de acciones vienen en el parámetro "action", y el canal en el parámetro "channel"
	else:
		exec "import "+params.get("channel")+" as plugin"
		exec "plugin."+action+"(params, url, category)"
Exemple #13
0
def run():
    xbmc.output("[mywebtv.py] run")

    # Imprime en el log los parámetros de entrada
    xbmc.output("[mywebtv.py] sys.argv=%s" % str(sys.argv))

    # Crea el diccionario de parametros
    params = dict()
    if len(sys.argv) >= 2 and len(sys.argv[2]) > 0:
        params = dict(part.split('=') for part in sys.argv[2][1:].split('&'))
    xbmc.output("[mywebtv.py] params=%s" % str(params))

    # Extrae la url de la página
    if (params.has_key("url")):
        url = urllib.unquote_plus(params.get("url"))
    else:
        url = ''
    xbmc.output("[mywebtv.py] url=" + url)

    # Extrae la accion
    if (params.has_key("action")):
        action = params.get("action")
    else:
        action = "selectchannel"
    xbmc.output("[mywebtv.py] action=" + action)

    # Extrae la categoria
    if (params.has_key("category")):
        category = urllib.unquote_plus(params.get("category"))
    else:
        if params.has_key("channel"):
            category = params.get("channel")
        else:
            category = ""
    xbmc.output("[mywebtv.py] category=" + category)

    # Accion por defecto - elegir canal
    if (action == "selectchannel"):
        import channelselector as plugin
        plugin.listchannels(params, url, category)
    # Actualizar version
    elif (action == "update"):
        import updater
        updater.update(params)
        import channelselector as plugin
        plugin.listchannels(params, url, category)
    # El resto de acciones vienen en el parámetro "action", y el canal en el parámetro "channel"
    else:
        exec "import " + params.get("channel") + " as plugin"
        exec "plugin." + action + "(params, url, category)"
Exemple #14
0
def show_stock(request, symbol):
    stks = Stock.objects.filter(symbol=symbol)
    if stks.count() == 0:
        stk = Stock(symbol=symbol, price=0.0)
        stk.save()
    elif stks.count() == 1:
        stk = stks[0]
    else:
        return HttpResponse("%s" % stks.count())
    try:
        ss = stk.history.order_by('date')[0]
    except:
        update(stk)
        ss = stk.history.order_by('date')[0]
    return render_to_response('stock.html', {'stock': stk, 'status': ss})
Exemple #15
0
def login():
    if not session.get('logged_in'):
        form = LoginForm(request.form)
        if request.method == 'POST':
            username = request.form['username'].lower()
            password = request.form['password']
            if form.validate():
                if helpers.credentials_valid(username, password):
                    session['logged_in'] = True
                    session['username'] = username
                    return json.dumps({'status': 'Login successful'})
                return json.dumps({'status': 'Invalid user/pass'})
            return json.dumps({'status': 'Both fields required'})
        return render_template('login.html', form=form)
    user = helpers.get_user()
    updater.update()
    return render_template('home.html', user=user)
Exemple #16
0
def handler(event, contenxt):
    res = requests.get('https://www.s-n-p.jp/kishou.htm')
    soup = BeautifulSoup(res.content, 'html.parser', from_encoding='shift-jis')

    tbls = soup.select('table')

    data = parse_table1({}, tbls[0].select('td'))
    data = parse_table2(data, tbls[1].select('td'))
    data = parse_table3(data, tbls[2].select('tr'))

    dynamodb = boto3.resource('dynamodb', region_name='ap-northeast-1')
    table = dynamodb.Table(os.environ['TABLE_NAME'])
    table.put_item(Item=data)

    updater.update(os.environ['TABLE_NAME'], os.environ['BUCKET_NAME'])

    return data
Exemple #17
0
    def test_update_during_update(self, run_command, timeout, TimeoutException,
                                  fs):
        fs.create_file(pytest.plugins_lock_file, contents='update')
        run_command.return_value = {}
        timeout.return_value = 1

        # When an update is already in progress and if we try to run another update command,
        # we throw an exception before timeout. So there is only one lock test.
        with mock.patch('fcntl.flock', wraps=mocked_flock_locked) as flock:
            with pytest.raises(XenAPIPlugin.Failure) as e:
                update(mock.MagicMock(), {})
            flock.assert_called_once_with(mock.ANY,
                                          fcntl.LOCK_EX | fcntl.LOCK_NB)
        TimeoutException.assert_not_called()

        assert timeout.call_args_list == [((10, ), ), (), ()]
        assert e.value.params[0] == '-1'
        assert e.value.params[1] == 'Update already in progress'
 def update_process(self):
     process = input("Process:")
     self.debug_msg("UPDATER", "Waiting for keepalive to stop...")
     self.eKeep_alive.wait()
     self.eUpdate.clear()
     self.debug_msg("UPDATER", "Updating Process...")
     ud = updater.update()
     ud.update_py_process(process)
     self.eUpdate.set()
     self.debug_msg("UPDATER", "Update Done...")
Exemple #19
0
def update_command():
    """
    Updates the server.
    """

    output = update()

    if output == 0:  # No update needed
        return "You are already on the latest version."
    else:
        return "Update successful. Please restart the server."
    def run(self):
        if (update()):
            messagebox.showinfo("Update Available",
                                "Update Available Please Restart program")

        if not os.path.exists(self.config_file):
            setup_gui = Setup_GUI(self.config_file)
            setup_gui.start()
            while (not setup_gui.complete):
                time.sleep(1)
        srs_gui = SRSGUI.Run_GUI(self, self.run_delay)
        srs_gui.start()
Exemple #21
0
    def test_scheduler(self):
        stock_stub = {
            "price": 1.,
            "low_price": 1.,
            "open_price": 1.,
            "high_price": 1.,
            "close_price": 1.,
            "ticker": "GOOG",
            "volume": "0"
        }

        with app.app_context():
            mongo.db.stocks.delete_many({})
            mongo.db.stocks.insert_one(stock_stub)

        updater.update()

        with app.app_context():
            stock = mongo.db.stocks.find_one({'ticker': "GOOG"})

        self.assertTrue(stock != stock_stub)
Exemple #22
0
    def test_update_during_check_update_before_timeout(self, run_command,
                                                       timeout,
                                                       TimeoutException, fs):
        fs.create_file(pytest.plugins_lock_file, contents='check_update')
        run_command.return_value = {}
        timeout.return_value = 1

        with mock.patch('fcntl.flock',
                        wraps=mocked_flock_wait_and_lock) as flock:
            update(mock.MagicMock(), {})
            assert flock.call_args_list == [
                ((mock.ANY, fcntl.LOCK_EX | fcntl.LOCK_NB), ),
                ((
                    mock.ANY,
                    fcntl.LOCK_EX,
                ), ), ((
                    mock.ANY,
                    fcntl.LOCK_UN,
                ), )
            ]
        TimeoutException.assert_not_called()  # Success. \o/

        assert timeout.call_args_list == [((10, ), ), (), (), ()]
Exemple #23
0
    def test_update_during_check_update(self, run_command, timeout,
                                        TimeoutException, fs):
        fs.create_file(pytest.plugins_lock_file, contents='check_update')
        run_command.return_value = {}
        timeout.return_value = 1  # We don't want to wait a long time in the unit tests. ;)

        with mock.patch('fcntl.flock', wraps=mocked_flock_locked) as flock:
            with pytest.raises(XenAPIPlugin.Failure) as e:
                update(mock.MagicMock(), {})
            # Try a firstime without timeout and retry a second time with timer.
            assert flock.call_args_list == [
                ((mock.ANY, fcntl.LOCK_EX | fcntl.LOCK_NB), ),
                ((mock.ANY, fcntl.LOCK_EX), )
            ]
        TimeoutException.assert_called_once()

        # Note: By default we use 10s of timeout on `update` command.
        # The forced value of 0.1 is not set using the timeout setter, only the default value of 10.
        # The remaining calls without value are just the timeout getter.
        assert timeout.call_args_list == [((10, ), ), (), (), ()]
        assert e.value.params[0] == '-1'
        assert e.value.params[
            1] == 'The updater plugin is busy (current operation: check_update)'
Exemple #24
0
def process(scheduler=None, timer=None):
    # logging.basicConfig(filename="main.log", format='%(asctime)s %(message)s', datefmt='%m/%d/%Y %H:%M:%S', level=logging.DEBUG)

    logging.basicConfig(filename="error.log", format='%(asctime)s %(message)s', datefmt='%m/%d/%Y %H:%M:%S',
                        level=logging.ERROR)

    logging.info("--------------------begin downloading----------------------")
    download()
    logging.info("---------------------end downloading----------------------")

    logging.info("--------------------begin parsing----------------------")
    list = parse()
    logging.info("---------------------end parsing----------------------")

    logging.info("--------------------begin update----------------------")
    update(list)
    logging.info("---------------------end update----------------------")

    logging.info("--------------------begin achiever----------------------")
    achieve()
    logging.info("---------------------end achiever----------------------")
    if scheduler:
        scheduler.enter(timer, 1, process, (scheduler, timer))
Exemple #25
0
# Extrae la accion
if (params.has_key("action")):
	action = params.get("action")
else:
	action = ""
xbmc.output("[default.py] action="+action)

# Extrae la categoria
if (params.has_key("category")):
	category = params.get("category")
else:
	if params.has_key("channel"):
		category = params.get("channel")
	else:
		category = ""
xbmc.output("[default.py] category="+category)


# Accion por defecto - elegir canal
if ( action=="" ):
	goear.mainlist(params, url, category)
# Actualizar version
elif ( action=="update" ):
	import updater
	updater.update(params)
	goear.mainlist(params, url, category)
# El resto de acciones vienen en el parámetro "action", y el canal en el parámetro "channel"
else:
	exec "goear."+action+"(params, url, category)"
def run():
    logger.info("[pelisalacarta.py] run")
    
    # Verifica si el path de usuario del plugin está creado
    if not os.path.exists(config.DATA_PATH):
        logger.debug("[pelisalacarta.py] Path de usuario no existe, se crea: "+config.DATA_PATH)
        os.mkdir(config.DATA_PATH)

    # Imprime en el log los parámetros de entrada
    logger.info("[pelisalacarta.py] sys.argv=%s" % str(sys.argv))
    
    # Crea el diccionario de parametros
    params = dict()
    if len(sys.argv)>=2 and len(sys.argv[2])>0:
        params = dict(part.split('=') for part in sys.argv[ 2 ][ 1: ].split('&'))
    logger.info("[pelisalacarta.py] params=%s" % str(params))
    
    # Extrae la url de la página
    if (params.has_key("url")):
        url = urllib.unquote_plus( params.get("url") )
    else:
        url=''

    # Extrae la accion
    if (params.has_key("action")):
        action = params.get("action")
    else:
        action = "selectchannel"

    # Extrae el server
    if (params.has_key("server")):
        server = params.get("server")
    else:
        server = ""

    # Extrae la categoria
    if (params.has_key("category")):
        category = urllib.unquote_plus( params.get("category") )
    else:
        if params.has_key("channel"):
            category = params.get("channel")
        else:
            category = ""

    # Extrae la serie
    if (params.has_key("Serie")):
        serie = params.get("Serie")
    else:
        serie = ""
    logger.info("[pelisalacarta.py] url="+url+", action="+action+", server="+server+", category="+category+", serie="+serie)

    #JUR - Gestión de Errores de Internet (Para que no casque el plugin 
    #      si no hay internet (que queda feo)
    try:

        # Accion por defecto - elegir canal
        if ( action=="selectchannel" ):
            import channelselector as plugin
            plugin.mainlist(params, url, category)

        # Actualizar version
        elif ( action=="update" ):
            try:
                import updater
                updater.update(params)
            except ImportError:
                logger.info("[pelisalacarta.py] Actualizacion automática desactivada")
                
            import channelselector as plugin
            plugin.mainlist(params, url, category)

        # Reproducir un STRM
        elif (action=="strm"):
            import xbmctools
            xbmctools.playstrm(params, url, category)

        # El resto de acciones vienen en el parámetro "action", y el canal en el parámetro "channel"
        else:

            # Actualiza el canal si ha cambiado    
            if action=="mainlist" and config.getSetting("updatechannels")=="true":
                try:
                    import updater
                    actualizado = updater.updatechannel(params.get("channel"))
    
                    if actualizado:
                        import xbmcgui
                        advertencia = xbmcgui.Dialog()
                        advertencia.ok("pelisalacarta",params.get("channel"),config.getLocalizedString(30063))
                except:
                    logger.info("Actualización de canales desactivada")

            # Ejecuta el canal
            exec "import "+params.get("channel")+" as channel"
            generico = False
            try:
                generico = channel.isGeneric()
            except:
                generico = False

            print "generico=" , generico 
            
            # Es un canal específico de xbmc
            if not generico:
                exec "channel."+action+"(params, url, category)"
            
            # Es un canal genérico
            else:
                if params.has_key("title"):
                    title = urllib.unquote_plus( params.get("title") )
                else:
                    title = ""
                if params.has_key("thumbnail"):
                    thumbnail = urllib.unquote_plus( params.get("thumbnail") )
                else:
                    thumbnail = ""
                if params.has_key("plot"):
                    plot = urllib.unquote_plus( params.get("plot") )
                else:
                    plot = ""
                if params.has_key("server"):
                    server = urllib.unquote_plus( params.get("server") )
                else:
                    server = "directo"
            
                import xbmctools
                if action=="play":
                    xbmctools.playvideo(params.get("channel"),server,url,category,title,thumbnail,plot)
                else:
                    from item import Item
                    item = Item(channel=params.get("channel"), title=title , url=url, thumbnail=thumbnail , plot=plot , server=server)
        
                    if action!="findvideos":
                        exec "itemlist = channel."+action+"(item)"
                    else:
                        # Intenta ejecutar una posible funcion "findvideos" del canal
                        try:
                            exec "itemlist = channel."+action+"(item)"
                        # Si no funciona, lanza el método genérico para detectar vídeos
                        except:
                            itemlist = findvideos(item)

                    xbmctools.renderItems(itemlist, params, url, category)
    
    except urllib2.URLError,e:
        for line in sys.exc_info():
            logger.error( "%s" % line )
        import xbmcgui
        ventana_error = xbmcgui.Dialog()
        # Agarra los errores surgidos localmente enviados por las librerias internas
        if hasattr(e, 'reason'):
            logger.info("Razon del error, codigo: %d , Razon: %s" %(e.reason[0],e.reason[1]))
            texto = config.getLocalizedString(30050) # "No se puede conectar con el sitio web"
            ok = ventana_error.ok ("pelisalacarta", texto)
        # Agarra los errores con codigo de respuesta del servidor externo solicitado     
        elif hasattr(e,'code'):
            logger.info("codigo de error HTTP : %d" %e.code)
            texto = (config.getLocalizedString(30051) % e.code) # "El sitio web no funciona correctamente (error http %d)"
            ok = ventana_error.ok ("pelisalacarta", texto)    
        else:
            pass
Exemple #27
0
        if pid == os.getpid():
            continue
        os.kill(pid, signal.SIGTERM)
    sys.exit(0)


if __name__ == "__main__":
    if len(sys.argv):
        for item in sys.argv:
            if item == 'test':
                utils.config_test(config)
                exit(0)
            if item == 'rmdirs':
                utils.remove_empty_directories(config)
                exit(0)
            if item == 'rmhidden':
                remove_hidden()
                exit(0)

    logger.debug("Current branch: %s", updater.active_branch())
    logger.debug("Current version: %s", updater.current_version())
    logger.debug("Latest version: %s", updater.latest_version())
    if config['use_git_autoupdater'] and updater.update():
        logger.debug("Restarting...")
        sys.exit(1)

    signal.signal(signal.SIGINT, exit_gracefully)
    signal.signal(signal.SIGTERM, exit_gracefully)
    signal.signal(signal.SIGHUP, exit_restart)
    start(config['unionfs_folder'])
Exemple #28
0
 def test_updater(self):
   file_list = updater.update(restart=False, test=True)
   print(file_list)
   self.assertTrue('worker' in file_list)
Exemple #29
0
def worker(worker_info, password, remote):
  global ALIVE

  payload = {
    'worker_info': worker_info,
    'password': password,
  }

  try:
    print('Fetch task...')
    t0 = datetime.utcnow()
    req = requests.post(remote + '/api/request_version', data=json.dumps(payload), headers={'Content-type': 'application/json'}, timeout=HTTP_TIMEOUT)
    req = json.loads(req.text)

    if 'version' not in req:
      print('Incorrect username/password')
      time.sleep(5)
      sys.exit(1)

    if req['version'] > WORKER_VERSION:
      print('Updating worker version to %s' % (req['version']))
      update()
    print("Worker version checked successfully in %ss" % ((datetime.utcnow() - t0).total_seconds()))

    t0 = datetime.utcnow()
    req = requests.post(remote + '/api/request_task', data=json.dumps(payload), headers={'Content-type': 'application/json'}, timeout=HTTP_TIMEOUT)
    req = json.loads(req.text)
  except:
    sys.stderr.write('Exception accessing host:\n')
    traceback.print_exc()
    time.sleep(random.randint(10,60))
    return

  print("Task requested in %ss" % ((datetime.utcnow() - t0).total_seconds()))
  if 'error' in req:
    raise Exception('Error from remote: %s' % (req['error']))

  # No tasks ready for us yet, just wait...
  if 'task_waiting' in req:
    print('No tasks available at this time, waiting...\n')
    # Note that after this sleep we have another ALIVE HTTP_TIMEOUT...
    time.sleep(random.randint(1,10))
    return

  success = True
  run, task_id = req['run'], req['task_id']
  try:
    pgn_file = run_games(worker_info, password, remote, run, task_id)
  except:
    sys.stderr.write('\nException running games:\n')
    traceback.print_exc()
    success = False
  finally:
    payload = {
      'username': worker_info['username'],
      'password': password,
      'run_id': str(run['_id']),
      'task_id': task_id
    }
    try:
      requests.post(remote + '/api/failed_task', data=json.dumps(payload), headers={'Content-type': 'application/json'}, timeout=HTTP_TIMEOUT)
    except:
      pass

    if success and ALIVE:
      sleep = random.randint(1,10)
      print('Wait %d seconds before upload of PGN...' % (sleep))
      time.sleep(sleep)
      if not 'spsa' in run['args']:
        try:
          with open(pgn_file, 'r') as f:
            data = f.read()
          payload['pgn'] = base64.b64encode(zlib.compress(data.encode('utf-8'))).decode()
          print('Uploading compressed PGN of %d bytes' % (len(payload['pgn'])))
          requests.post(remote + '/api/upload_pgn', data=json.dumps(payload), headers={'Content-type': 'application/json'}, timeout=HTTP_TIMEOUT)
        except:
          sys.stderr.write('\nException PGN upload:\n')
          traceback.print_exc()
    try:
      os.remove(pgn_file)
    except:
      pass
    sys.stderr.write('Task exited\n')

  return success
Exemple #30
0
def worker(worker_info, password, remote):
    global ALIVE

    payload = {
        'worker_info': worker_info,
        'password': password,
    }

    try:
        print('Fetch task...')
        if not get_rate():
            raise Exception('Near API limit')

        t0 = datetime.utcnow()
        req = requests.post(remote + '/api/request_version',
                            data=json.dumps(payload),
                            headers={'Content-type': 'application/json'},
                            timeout=HTTP_TIMEOUT)
        req = json.loads(req.text)

        if 'version' not in req:
            print('Incorrect username/password')
            time.sleep(5)
            sys.exit(1)

        if req['version'] > WORKER_VERSION:
            print('Updating worker version to %s' % (req['version']))
            update()
        print("Worker version checked successfully in %ss" %
              ((datetime.utcnow() - t0).total_seconds()))

        t0 = datetime.utcnow()
        worker_info['rate'] = rate
        req = requests.post(remote + '/api/request_task',
                            data=json.dumps(payload),
                            headers={'Content-type': 'application/json'},
                            timeout=HTTP_TIMEOUT)
        req = json.loads(req.text)
    except Exception as e:
        sys.stderr.write('Exception accessing host:\n')
        print(e)
        #    traceback.print_exc()
        time.sleep(random.randint(10, 60))
        return

    print("Task requested in %ss" % ((datetime.utcnow() - t0).total_seconds()))
    if 'error' in req:
        raise Exception('Error from remote: %s' % (req['error']))

    # No tasks ready for us yet, just wait...
    if 'task_waiting' in req:
        print('No tasks available at this time, waiting...\n')
        # Note that after this sleep we have another ALIVE HTTP_TIMEOUT...
        time.sleep(random.randint(1, 10))
        return

    success = True
    run, task_id = req['run'], req['task_id']
    try:
        pgn_file = run_games(worker_info, password, remote, run, task_id)
    except:
        sys.stderr.write('\nException running games:\n')
        traceback.print_exc()
        success = False
    finally:
        payload = {
            'username': worker_info['username'],
            'password': password,
            'run_id': str(run['_id']),
            'task_id': task_id
        }
        try:
            requests.post(remote + '/api/failed_task',
                          data=json.dumps(payload),
                          headers={'Content-type': 'application/json'},
                          timeout=HTTP_TIMEOUT)
        except:
            pass

        if success and ALIVE:
            sleep = random.randint(1, 10)
            print('Wait %d seconds before upload of PGN...' % (sleep))
            time.sleep(sleep)
            if not 'spsa' in run['args']:
                try:
                    with open(pgn_file, 'r') as f:
                        data = f.read()
                    # Ignore non utf-8 characters in PGN file
                    if sys.version_info[0] == 2:
                        data = data.decode('utf-8', 'ignore').encode(
                            'utf-8')  # Python 2
                    else:
                        data = bytes(data,
                                     'utf-8').decode('utf-8',
                                                     'ignore')  # Python 3
                    payload['pgn'] = base64.b64encode(
                        zlib.compress(data.encode('utf-8'))).decode()
                    print('Uploading compressed PGN of %d bytes' %
                          (len(payload['pgn'])))
                    requests.post(remote + '/api/upload_pgn',
                                  data=json.dumps(payload),
                                  headers={'Content-type': 'application/json'},
                                  timeout=HTTP_TIMEOUT)
                except Exception as e:
                    sys.stderr.write('\nException PGN upload:\n')
                    print(e)


#          traceback.print_exc()
        try:
            os.remove(pgn_file)
        except:
            pass
        sys.stderr.write('Task exited\n')

    return success
def run():
	logger.info("[pelisalacarta.py] run")
	
	# Imprime en el log los parámetros de entrada
	logger.info("[pelisalacarta.py] sys.argv=%s" % str(sys.argv))
	
	# Crea el diccionario de parametros
	params = dict()
	if len(sys.argv)>=2 and len(sys.argv[2])>0:
		params = dict(part.split('=') for part in sys.argv[ 2 ][ 1: ].split('&'))
	logger.info("[pelisalacarta.py] params=%s" % str(params))
	
	# Extrae la url de la página
	if (params.has_key("url")):
		url = urllib.unquote_plus( params.get("url") )
	else:
		url=''
	logger.info("[pelisalacarta.py] url="+url)

	# Extrae la accion
	if (params.has_key("action")):
		action = params.get("action")
	else:
		action = "selectchannel"
	logger.info("[pelisalacarta.py] action="+action)

	# Extrae el server
	if (params.has_key("server")):
		server = params.get("server")
	else:
		server = ""
	logger.info("[pelisalacarta.py] server="+server)

	# Extrae la categoria
	if (params.has_key("category")):
		category = urllib.unquote_plus( params.get("category") )
	else:
		if params.has_key("channel"):
			category = params.get("channel")
		else:
			category = ""
	logger.info("[pelisalacarta.py] category="+category)

	# Extrae la serie
	if (params.has_key("Serie")):
		serie = params.get("Serie")
	else:
		serie = ""
	logger.info("[pelisalacarta.py] Serie="+serie)

	#JUR - Gestión de Errores de Internet (Para que no casque el plugin 
	#      si no hay internet (que queda feo)
	try:
	# Accion por defecto - elegir canal
		if ( action=="selectchannel" ):
			import channelselector as plugin
			plugin.listchannels(params, url, category)
		# Actualizar version
		elif ( action=="update" ):
			import updater
			updater.update(params)
			import channelselector as plugin
			plugin.listchannels(params, url, category)
		# El resto de acciones vienen en el parámetro "action", y el canal en el parámetro "channel"
		elif (action=="strm"):
			xbmctools.playstrm(params, url, category)
		else:
			exec "import "+params.get("channel")+" as plugin"
			exec "plugin."+action+"(params, url, category)"
	
	except urllib2.URLError,e:
		ventana_error = xbmcgui.Dialog()
		# Agarra los errores surgidos localmente enviados por las librerias internas
		if hasattr(e, 'reason'):
			print "Razon del error, codigo: %d , Razon: %s" %(e.reason[0],e.reason[1])
			ok= ventana_error.ok ("pelisalacarta", "No se puede conectar con el servidor",'compruebe la direccion de la página',"o su conexión a internet")
		# Agarra los errores con codigo de respuesta del servidor externo solicitado 	
		elif hasattr(e,'code'):
			print "codigo de error HTTP : %d" %e.code 
			ok= ventana_error.ok ("pelisalacarta", "El servidor solicitado no pudo realizar la peticion", texto_error(e.code),"codigo de error : %d " %e.code)	
		else:
			pass	
Exemple #32
0
from updater import update
from model import get_model

update(get_model())
def run():
	logger.info("[pelisalacarta.py] run")
	
	# Verifica si el path de usuario del plugin está creado
	if not os.path.exists(config.DATA_PATH):
		logger.debug("[pelisalacarta.py] Path de usuario no existe, se crea: "+config.DATA_PATH)
		os.mkdir(config.DATA_PATH)

	# Imprime en el log los parámetros de entrada
	logger.info("[pelisalacarta.py] sys.argv=%s" % str(sys.argv))
	
	# Crea el diccionario de parametros
	params = dict()
	if len(sys.argv)>=2 and len(sys.argv[2])>0:
		params = dict(part.split('=') for part in sys.argv[ 2 ][ 1: ].split('&'))
	logger.info("[pelisalacarta.py] params=%s" % str(params))
	
	# Extrae la url de la página
	if (params.has_key("url")):
		url = urllib.unquote_plus( params.get("url") )
	else:
		url=''

	# Extrae la accion
	if (params.has_key("action")):
		action = params.get("action")
	else:
		action = "selectchannel"

	# Extrae el server
	if (params.has_key("server")):
		server = params.get("server")
	else:
		server = ""

	# Extrae la categoria
	if (params.has_key("category")):
		category = urllib.unquote_plus( params.get("category") )
	else:
		if params.has_key("channel"):
			category = params.get("channel")
		else:
			category = ""

	# Extrae la serie
	if (params.has_key("Serie")):
		serie = params.get("Serie")
	else:
		serie = ""
	logger.info("[pelisalacarta.py] url="+url+", action="+action+", server="+server+", category="+category+", serie="+serie)

	#JUR - Gestión de Errores de Internet (Para que no casque el plugin 
	#      si no hay internet (que queda feo)
	try:

		# Accion por defecto - elegir canal
		if ( action=="selectchannel" ):
			import channelselector as plugin
			plugin.mainlist(params, url, category)

		# Actualizar version
		elif ( action=="update" ):
			try:
				import updater
				updater.update(params)
			except ImportError:
				logger.info("[pelisalacarta.py] Actualizacion automática desactivada")
				
			import channelselector as plugin
			plugin.mainlist(params, url, category)

		# Reproducir un STRM
		elif (action=="strm"):
			import xbmctools
			xbmctools.playstrm(params, url, category)

		# El resto de acciones vienen en el parámetro "action", y el canal en el parámetro "channel"
		else:

			exec "import "+params.get("channel")+" as plugin"
			exec "plugin."+action+"(params, url, category)"
	
	except urllib2.URLError,e:
		ventana_error = xbmcgui.Dialog()
		# Agarra los errores surgidos localmente enviados por las librerias internas
		if hasattr(e, 'reason'):
			logger.info("Razon del error, codigo: %d , Razon: %s" %(e.reason[0],e.reason[1]))
			texto = config.getLocalizedString(30050) # "No se puede conectar con el sitio web"
			ok = ventana_error.ok ("pelisalacarta", texto)
		# Agarra los errores con codigo de respuesta del servidor externo solicitado 	
		elif hasattr(e,'code'):
			logger.info("codigo de error HTTP : %d" %e.code)
			texto = (config.getLocalizedString(30051) % e.code) # "El sitio web no funciona correctamente (error http %d)"
			ok = ventana_error.ok ("pelisalacarta", texto)	
		else:
			pass
Exemple #34
0
def main():
	#Initializing bot instance
	if isfile("Config.json"):
		configs = Utils.loadfile("Config.json")
		trigger = configs["Trigger"]
		name = configs["Name"]
		version = configs["Version"]
		debug = configs["Debug"]
		myBot = Bot(name,version,trigger,debug)
	else:
		myBot = Bot("Bot","0.1","!","False")

	#Startup prints
	os.system("title Varas Bot - 1.3")
	Utils.info()
	Utils.logaction("Attaching to skype.")
	try:
		if skype.Client.IsRunning == False:
			try:
				Utils.logaction("Skype instance not found, trying to start one.")
    				skype.Client.Start()
			except:
				Utils.errorquit("Couldn't start skype, quitting...")
		skype.Attach()
		Utils.action("Attached successfully.")
	except:
		Utils.errorquit("Couldn't attach to skype, quitting...")
	Utils.logaction("Loading "+Utils.Cafe+"plugins"+Utils.defcol)
	try:
		myBot.loadplugins()
		Utils.action("Successfully loaded "+Utils.Cafe + str(len(myBot.plugins))+Utils.defcol +" plugins.")
	except:
		Utils.alert("Couldn't load plugins.")
	Utils.logaction("Checking for updates...")
	try:
		if updater.check(ver)== True:
			Utils.action("Varas is up to date!")
		else:
			Utils.alert("Update found! Type 'update' in console to update the bot.")
	except:
		Utils.alert("Couldn't check for updates.")
	#Bot infos
	Utils.logaction("Current trigger is " + Utils.Cafe+myBot.gettrigger()+Utils.defcol)
	Utils.logaction("Current bot name is " + Utils.Cafe+myBot.getname()+Utils.defcol)
	Utils.logaction("Current bot version is " + Utils.Cafe+myBot.getversion()+Utils.defcol)
	Utils.logaction("Type '"+Utils.Cafe+"help"+Utils.defcol+"' in console to view a list of console commands.")
	skype.OnMessageStatus = myBot.process

	#Loop to keep the bot active
	while True:
		cmd = raw_input(Utils.red+'>'+Utils.defcol)
		if cmd.startswith("settrigger "):
			trg = cmd.split(" ")
			myBot.settrigger(trg[1])
			Utils.action("Changed trigger to "+Utils.Cafe+trg[1]+Utils.defcol)
		if cmd.startswith("setversion "):
			vrs = cmd.split(" ")
			myBot.setversion(vrs[1])
			Utils.action("Changed version to "+Utils.Cafe+vrs[1]+Utils.defcol)
		if cmd.startswith("setname "):
			nm = cmd.split(" ")
			myBot.setname(nm[1])
			Utils.action("Changed name to "+Utils.Cafe+nm[1]+Utils.defcol)
		if cmd.startswith("setdebug "):
			db = cmd.split(" ")
			if db[1] == "True" or db[1] == "False":
				myBot.setdebug(db[1])
				Utils.action("Changed Debug mode to "+Utils.Cafe+db[1]+Utils.defcol)
			else:
				Utils.alert("Debug mode must be True or False")
		if cmd=="gettrigger":
			Utils.action("Current trigger is: "+Utils.Cafe+myBot.gettrigger()+Utils.defcol)
		if cmd=="getname":
			Utils.action("Current name is: "+Utils.Cafe+myBot.getname()+Utils.defcol)
		if cmd=="getplugins":
			Utils.action("Loaded plugins are: "+Utils.Cafe+myBot.getplugins()+Utils.defcol)
		if cmd=="getversion":
			Utils.action("Current version is: "+Utils.Cafe+myBot.getversion()+Utils.defcol)
		if cmd=="getdebug":
			Utils.action("Current debug mode is: "+Utils.Cafe+myBot.getdebug()+Utils.defcol)
		if cmd=="reload":
			Utils.action("Reloading "+Utils.Cafe+"plugins."+Utils.defcol)
			myBot.plugins = []
			myBot.loadplugins()
			Utils.action("Done reloading.")
		if cmd=="update":
			Utils.action("Attempting to update, bot will close after update.")
			Utils.action("Bot will close after being updated.")
			if updater.check(ver)==True:
				Utils.action("Varas is up to date!")
			else:
				updater.update()
		if cmd=="help":
			Utils.action("Available console commands are: "+Utils.Cafe+"help,reload,setversion <version>,getversion,setname <name>,getname,settrigger <trigger>,gettrigger,setdebug <True/False>,getdebug,update,getplugins"+Utils.defcol)
def run():
	logger.info("[GreekTV.py] run")
	
	# Verifica si el path de usuario del plugin est� creado
	if not os.path.exists(config.DATA_PATH):
		logger.debug("[GreekTV.py] Path de usuario no existe, se crea: "+config.DATA_PATH)
		os.mkdir(config.DATA_PATH)

	# Imprime en el log los par�metros de entrada
	logger.info("[GreekTV.py] sys.argv=%s" % str(sys.argv))
	
	# Crea el diccionario de parametros
	params = dict()
	if len(sys.argv)>=2 and len(sys.argv[2])>0:
		params = dict(part.split('=') for part in sys.argv[ 2 ][ 1: ].split('&'))
	logger.info("[GreekTV.py] params=%s" % str(params))
	
	# Extrae la url de la p�gina
	if (params.has_key("url")):
		url = urllib.unquote_plus( params.get("url") )
	else:
		url=''

	# Extrae la accion
	if (params.has_key("action")):
		action = params.get("action")
	else:
		action = "selectchannel"

	# Extrae el server
	if (params.has_key("server")):
		server = params.get("server")
	else:
		server = ""

	# Extrae la categoria
	if (params.has_key("category")):
		category = urllib.unquote_plus( params.get("category") )
	else:
		if params.has_key("channel"):
			category = params.get("channel")
		else:
			category = ""


	try:
		# Accion por defecto - elegir canal
		if ( action=="selectchannel" ):
			import channelselector as plugin
			plugin.listchannels(params, url, category)
		# Actualizar version
		elif ( action=="update" ):
			import updater
			updater.update(params)
			import channelselector as plugin
			plugin.listchannels(params, url, category)
		# El resto de acciones vienen en el par�metro "action", y el canal en el par�metro "channel"
		else:
			exec "import "+params.get("channel")+" as channel"
			generico = False
			try:
				generico = channel.isGeneric()
			except:
				generico = False

			print "generico=" , generico 
			
			if not generico:
				exec "channel."+action+"(params, url, category)"
			else:
				if params.has_key("title"):
					title = urllib.unquote_plus( params.get("title") )
				else:
					title = ""
				if params.has_key("thumbnail"):
					thumbnail = urllib.unquote_plus( params.get("thumbnail") )
				else:
					thumbnail = ""
				if params.has_key("plot"):
					plot = urllib.unquote_plus( params.get("plot") )
				else:
					plot = ""
				if params.has_key("server"):
					server = urllib.unquote_plus( params.get("server") )
				else:
					server = "directo"
			
				import xbmctools
				if action=="play":
					xbmctools.playvideo(params.get("channel"),server,url,category,title,thumbnail,plot)
				else:
					from item import Item
					item = Item(channel=params.get("channel"), title=title , url=url, thumbnail=thumbnail , plot=plot , server=server)
		
					exec "itemlist = channel."+action+"(item)"
					xbmctools.renderItems(itemlist, params, url, category)

	except urllib2.URLError,e:
		ventana_error = xbmcgui.Dialog()
		# Agarra los errores surgidos localmente enviados por las librerias internas
		if hasattr(e, 'reason'):
			logger.info("Razon del error, codigo: %d , Razon: %s" %(e.reason[0],e.reason[1]))
			texto = config.getLocalizedString(30050) # "No se puede conectar con el sitio web"
			ok = ventana_error.ok ("pelisalacarta", texto)
		# Agarra los errores con codigo de respuesta del servidor externo solicitado 	
		elif hasattr(e,'code'):
			logger.info("codigo de error HTTP : %d" %e.code)
			texto = (config.getLocalizedString(30051) % e.code) # "El sitio web no funciona correctamente (error http %d)"
			ok = ventana_error.ok ("pelisalacarta", texto)	
		else:
			pass
import time
from musicplayer import Player
from song_sources import OnlineSource, OfflineSource
from gui import Interface
from updater import update

update()

gui = Interface()
vk_music = OnlineSource()

player = Player(vk_music.songs)


def logout(*args):
    player.stop()
    vk_music.logout()
    gui.show_login()
gui.logout = logout

        #or OfflineSource(os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), 'data')).songs
if vk_music.songs:
    gui.show_player(vk_music.songs, player)
    print('after show player')
else:
    gui.show_login()

    def on_credentials_entered(login, password):
        if vk_music.login(login, password):
            songs_list = vk_music.get_audios()
            player.set_songs(songs_list)
Exemple #37
0
import updater
import distributed

updater.update()

print(distributed.compute('config.json', 1))
Exemple #38
0
                        update_pos.add(new_block)
        else:
            #if not a block type block then only place a single block of the current type
            new_sand = place_blocks(mpos, block_type, the_grid, screen)
            if new_sand:
                update_pos.add(new_sand)
        #right mouse button is being held down
    if mouse_down2 == 1:
        for i in range(2):
            for j in range(2):
                point = (mpos[0] + i, mpos[1] + j)
                #Set these blocks for being removed
                update_blocks = remove_blocks(point, the_grid, screen)
                if update_blocks:
                    for block in update_blocks:
                        update_pos.add(block)
        #illegal mouse operation, reset left and right mouse button is down variables
        #note: without this placing blocks would become slower and slower
        #each time the operation is executed
    if mouse_down1==1 and mouse_down2 == 1:
        mouse_down1 = 0
        mouse_down2 = 0
    #update function
    update(the_grid, screen, update_pos)

    # Limit to 400 frames per second

    clock.tick(400)

pygame.quit
Exemple #39
0
def fetch_and_handle_task(worker_info, password, remote, lock_file,
                          current_state):
    # This function should normally not raise exceptions.
    # Unusual conditions are handled by returning False.
    # If an immediate exit is necessary then one can set
    # current_state["alive"] to False.

    # The following check can be triggered theoretically
    # but probably not in practice.
    if locked_by_others(lock_file):
        current_state["alive"] = False
        return False

    payload = {"worker_info": worker_info, "password": password}

    try:
        rate, near_api_limit = get_rate()
        if near_api_limit:
            print("Near API limit")
            return False

        worker_info["rate"] = rate

        print("Verify worker version...")
        req = send_api_post_request(remote + "/api/request_version", payload)

        if "error" in req:
            current_state["alive"] = False
            return False

        if req["version"] > WORKER_VERSION:
            print("Updating worker version to {}".format(req["version"]))
            backup_log()
            update()
        print("Current time is {} UTC (offset: {}) ".format(
            datetime.datetime.utcnow(), utcoffset()))
        print("Fetching task...")
        req = send_api_post_request(remote + "/api/request_task", payload)
    except Exception as e:
        print("Exception accessing host:\n", e, sep="", file=sys.stderr)
        return False

    if "error" in req:
        return False

    # No tasks ready for us yet, just wait...
    if "task_waiting" in req:
        print("No tasks available at this time, waiting...")
        return False

    run, task_id = req["run"], req["task_id"]
    current_state["run"] = run
    current_state["task_id"] = task_id

    print("Working on task {} from {}/tests/view/{}".format(
        task_id, remote, run["_id"]))
    if "sprt" in run["args"]:
        type = "sprt"
    elif "spsa" in run["args"]:
        type = "spsa"
    else:
        type = "num_games"
    log("run: {} task: {} size: {} tc: {} concurrency: {} threads: {} [ {} : {} ]"
        .format(
            run["_id"],
            task_id,
            run["my_task"]["num_games"],
            run["args"]["tc"],
            worker_info["concurrency"],
            run["args"]["threads"],
            type,
            run["args"]["num_games"],
        ))
    print("Running {} vs {}".format(run["args"]["new_tag"],
                                    run["args"]["base_tag"]))

    success = False
    message = ""
    server_message = ""
    api = remote + "/api/failed_task"
    pgn_file = [None]
    try:
        run_games(worker_info, password, remote, run, task_id, pgn_file)
        success = True
    except FatalException as e:
        message = str(e)
        server_message = message
        current_state["alive"] = False
    except RunException as e:
        message = str(e)
        server_message = message
        api = remote + "/api/stop_run"
    except WorkerException as e:
        message = str(e)
        server_message = message
    except Exception as e:
        server_message = get_exception(["worker.py", "games.py"])
        message = "{} ({})".format(server_message, str(e))
        current_state["alive"] = False

    current_state["task_id"] = None
    current_state["run"] = None

    payload = {
        "password": password,
        "run_id": str(run["_id"]),
        "task_id": task_id,
        "message": server_message,
        "worker_info": worker_info,
    }

    if not success:
        print("\nException running games:\n", message, sep="", file=sys.stderr)
        print("Informing the server")
        try:
            req = send_api_post_request(api, payload)
        except Exception as e:
            print("Exception posting failed_task:\n",
                  e,
                  sep="",
                  file=sys.stderr)
    # Upload PGN file.
    pgn_file = pgn_file[0]
    if pgn_file is not None and os.path.exists(
            pgn_file) and "spsa" not in run["args"]:
        try:
            with open(pgn_file, "r") as f:
                data = f.read()
            # Ignore non utf-8 characters in PGN file.
            data = bytes(data, "utf-8").decode("utf-8", "ignore")
            payload["pgn"] = base64.b64encode(
                zlib.compress(data.encode("utf-8"))).decode()
            print("Uploading compressed PGN of {} bytes".format(
                len(payload["pgn"])))
            req = send_api_post_request(remote + "/api/upload_pgn", payload)
        except Exception as e:
            print("\nException uploading PGN file:\n",
                  e,
                  sep="",
                  file=sys.stderr)

    if pgn_file is not None and os.path.exists(pgn_file):
        try:
            os.remove(pgn_file)
        except Exception as e:
            print("Exception deleting PGN file:\n", e, sep="", file=sys.stderr)

    print("Task exited")

    return success
def check_and_update(device, config, run_tests):
    priorities = common.config_get_list(config, "general", "priority")
    update_period = common.int_nothrow(config.get("general", "update_period"))
    now = int(time.time())

    tests_alive = check_tests(device.autotest)
    schedule = get_schedule(device, config)
    if (tests_alive and not schedule.allow_update):
        common.log("Schedule forbids updating %s right now" % device.name)
        return

    for priority in priorities:

        # If there are no newer images for this priority:
        # 1) If this image have been in use for the whole test
        #    duration, check lower priorities
        # 2) If the tests are still ongoing, abort here
        latest_list = config.get(device.image_type, priority)
        latest_onboard = device.config.get("latest_image", priority)
        last_update = common.int_nothrow(
            device.config.get("last_update", priority))
        enu = last_update + update_period

        update = check_new_images(latest_list, latest_onboard, now, enu,
                                  let_new_override_old(config, priority),
                                  tests_alive)
        if (update == None):
            if (now >= enu):
                common.log(" Could update %s to %s but no new images available" % \
                      (device.name, priority))
                continue
            else:
                common.log("%s will still run %s" % (device.name, priority))
                break

        last_update = now
        upload_results = schedule.upload_test_results or not tests_alive
        tests.stop_tests_and_report(device, upload_results)

        params = updater.UpdateParams()
        params.device = device
        params.update = update
        params.auth = common.get_auth("dav")
        params.config = config
        params.now = now

        new_image = updater.update(params)

        if (new_image):
            latest_onboard = new_image
            if (run_tests):
                testset = config.get(device.name, "testset")
                tests.start_tests(device, config, testset)

            device.config.set("last_update", priority, str(last_update))
            device.config.set("latest_image", priority, latest_onboard)
            device.config.set("general", "image_type", priority)
            common.write_config(device.config, device.config_fname)

            common.log("Updated %s to %s" % (device.name, priority))
        else:
            common.log("Failed to update %s to %s, skipping" % \
             (device.name, priority))
        break
    else:
        common.log("No updates for %s" % device.name)
Exemple #41
0
def run():
    logger.info("[pelisalacarta.py] run")

    # Verifica si el path de usuario del plugin está creado
    if not os.path.exists(config.DATA_PATH):
        logger.debug(
            "[pelisalacarta.py] Path de usuario no existe, se crea: " +
            config.DATA_PATH)
        os.mkdir(config.DATA_PATH)

    # Imprime en el log los parámetros de entrada
    logger.info("[pelisalacarta.py] sys.argv=%s" % str(sys.argv))

    # Crea el diccionario de parametros
    params = dict()
    if len(sys.argv) >= 2 and len(sys.argv[2]) > 0:
        params = dict(part.split('=') for part in sys.argv[2][1:].split('&'))
    logger.info("[pelisalacarta.py] params=%s" % str(params))

    # Extrae la url de la página
    if (params.has_key("url")):
        url = urllib.unquote_plus(params.get("url"))
    else:
        url = ''

    # Extrae la accion
    if (params.has_key("action")):
        action = params.get("action")
    else:
        action = "selectchannel"

    # Extrae el server
    if (params.has_key("server")):
        server = params.get("server")
    else:
        server = ""

    # Extrae la categoria
    if (params.has_key("category")):
        category = urllib.unquote_plus(params.get("category"))
    else:
        if params.has_key("channel"):
            category = params.get("channel")
        else:
            category = ""

    # Extrae la serie
    if (params.has_key("Serie")):
        serie = params.get("Serie")
    else:
        serie = ""
    logger.info("[pelisalacarta.py] url=" + url + ", action=" + action +
                ", server=" + server + ", category=" + category + ", serie=" +
                serie)

    #JUR - Gestión de Errores de Internet (Para que no casque el plugin
    #      si no hay internet (que queda feo)
    try:

        # Accion por defecto - elegir canal
        if (action == "selectchannel"):
            import channelselector as plugin
            plugin.mainlist(params, url, category)

        # Actualizar version
        elif (action == "update"):
            try:
                import updater
                updater.update(params)
            except ImportError:
                logger.info(
                    "[pelisalacarta.py] Actualizacion automática desactivada")

            import channelselector as plugin
            plugin.mainlist(params, url, category)

        # Reproducir un STRM
        elif (action == "strm"):
            import xbmctools
            xbmctools.playstrm(params, url, category)

        # El resto de acciones vienen en el parámetro "action", y el canal en el parámetro "channel"
        else:

            # Actualiza el canal si ha cambiado
            if action == "mainlist" and config.getSetting(
                    "updatechannels") == "true":
                try:
                    import updater
                    actualizado = updater.updatechannel(params.get("channel"))

                    if actualizado:
                        import xbmcgui
                        advertencia = xbmcgui.Dialog()
                        advertencia.ok("pelisalacarta", params.get("channel"),
                                       config.getLocalizedString(30063))
                except:
                    for line in sys.exc_info():
                        logger.error("%s" % line)
                    logger.info("Actualización de canales desactivada")

            # Ejecuta el canal
            exec "import " + params.get("channel") + " as channel"
            generico = False
            try:
                generico = channel.isGeneric()
            except:
                generico = False

            print "generico=", generico

            # Es un canal específico de xbmc
            if not generico:
                exec "channel." + action + "(params, url, category)"

            # Es un canal genérico
            else:
                if params.has_key("title"):
                    title = urllib.unquote_plus(params.get("title"))
                else:
                    title = ""
                if params.has_key("thumbnail"):
                    thumbnail = urllib.unquote_plus(params.get("thumbnail"))
                else:
                    thumbnail = ""
                if params.has_key("plot"):
                    plot = urllib.unquote_plus(params.get("plot"))
                else:
                    plot = ""
                if params.has_key("server"):
                    server = urllib.unquote_plus(params.get("server"))
                else:
                    server = "directo"
                if params.has_key("extradata"):
                    extradata = urllib.unquote_plus(params.get("extradata"))
                else:
                    extradata = ""
                if params.has_key("category"):
                    category = urllib.unquote_plus(params.get("category"))
                else:
                    category = ""
                if params.has_key("Serie"):
                    Serie = urllib.unquote_plus(params.get("Serie"))
                else:
                    Serie = ""

                import xbmctools
                if action == "play":
                    xbmctools.playvideo(params.get("channel"), server, url,
                                        category, title, thumbnail, plot)
                else:
                    from item import Item
                    item = Item(channel=params.get("channel"),
                                title=title,
                                url=url,
                                thumbnail=thumbnail,
                                plot=plot,
                                server=server,
                                category=category,
                                extra=extradata)

                    if action != "findvideos":
                        exec "itemlist = channel." + action + "(item)"
                    else:
                        # Intenta ejecutar una posible funcion "findvideos" del canal
                        try:
                            exec "itemlist = channel." + action + "(item)"
                        # Si no funciona, lanza el método genérico para detectar vídeos
                        except:
                            itemlist = findvideos(item)

                    xbmctools.renderItems(itemlist, params, url, category)

    except urllib2.URLError, e:
        for line in sys.exc_info():
            logger.error("%s" % line)
        import xbmcgui
        ventana_error = xbmcgui.Dialog()
        # Agarra los errores surgidos localmente enviados por las librerias internas
        if hasattr(e, 'reason'):
            logger.info("Razon del error, codigo: %d , Razon: %s" %
                        (e.reason[0], e.reason[1]))
            texto = config.getLocalizedString(
                30050)  # "No se puede conectar con el sitio web"
            ok = ventana_error.ok("pelisalacarta", texto)
        # Agarra los errores con codigo de respuesta del servidor externo solicitado
        elif hasattr(e, 'code'):
            logger.info("codigo de error HTTP : %d" % e.code)
            texto = (
                config.getLocalizedString(30051) % e.code
            )  # "El sitio web no funciona correctamente (error http %d)"
            ok = ventana_error.ok("pelisalacarta", texto)
        else:
            pass
Exemple #42
0
from updater import update
from vpn import start_vpn
"""
TODO:
    - Fix update holding back vpn start. Use threads and make threadsafe.
"""

if __name__ == "__main__":
    update()
    start_vpn()
Exemple #43
0
 gr3.add_argument('-u','--update', dest='update', action='store_true', help='update Load Balancer Finder')
 
 checkArgs()
 
 args = parser.parse_args()
       
 progOptions = utils.cParams()
 progOptions.set_normal_output(sys.stdout)
 progOptions.set_error_output(sys.stderr)
 progOptions.set_use_colours(args.colour)
 progOptions.verbose = args.verbose
 
 
 if args.update:
     utils.printMessage("[*] Going to update Load Balancer Finder", "info", progOptions)
     updater.update()
     sys.exit(1)
 
 
 if not os.geteuid()==0:
     utils.printMessage("[-] You have to be root (scapy packet injection)", "error", progOptions)
     sys.exit(0)
 
 
 # Configuration parsing
 cfg = ConfigParser.ConfigParser()
 try:
     cfg.read(args.configfile)
     nsyn = int(cfg.get("packets","ipid_syn"))
     nicmp_packets = int(cfg.get("packets","nicmp_packets"))
     tcp_timestamp = int(cfg.get("packets","tcp_timestamp"))
Exemple #44
0
def worker(worker_info, password, remote):
    global ALIVE, FLEET

    payload = {"worker_info": worker_info, "password": password}

    try:
        print("Fetch task...")
        if not get_rate():
            raise Exception("Near API limit")

        t0 = datetime.utcnow()
        req = requests.post(
            remote + "/api/request_version",
            data=json.dumps(payload),
            headers={"Content-type": "application/json"},
            timeout=HTTP_TIMEOUT,
        )
        req = json.loads(req.text)

        if "version" not in req:
            print("Incorrect username/password")
            time.sleep(5)
            worker_exit()

        if req["version"] > WORKER_VERSION:
            print("Updating worker version to {}".format(req["version"]))
            update()
        print("Worker version checked successfully in {}s".format(
            (datetime.utcnow() - t0).total_seconds()))

        t0 = datetime.utcnow()
        worker_info["rate"] = rate
        req = requests.post(
            remote + "/api/request_task",
            data=json.dumps(payload),
            headers={"Content-type": "application/json"},
            timeout=HTTP_TIMEOUT,
        )
        req = json.loads(req.text)
    except Exception as e:
        sys.stderr.write("Exception accessing host:\n")
        print(e, file=sys.stderr)
        #    traceback.print_exc()
        if FLEET:
            worker_exit()
        time.sleep(random.randint(10, 60))
        return

    print("Task requested in {}s".format(
        (datetime.utcnow() - t0).total_seconds()))
    if "error" in req:
        raise Exception("Error from remote: {}".format(req["error"]))

    # No tasks ready for us yet, just wait...
    if "task_waiting" in req:
        print("No tasks available at this time, waiting...\n")
        if FLEET:
            worker_exit()
        # Note that after this sleep we have another ALIVE HTTP_TIMEOUT...
        time.sleep(random.randint(1, 10))
        return

    success = True
    global RUN, TASK_ID
    RUN, TASK_ID = req["run"], req["task_id"]
    try:
        pgn_file = run_games(worker_info, password, remote, RUN, TASK_ID)
    except:
        sys.stderr.write("\nException running games:\n")
        traceback.print_exc()
        success = False
    finally:
        payload = {
            "username": worker_info["username"],
            "password": password,
            "run_id": str(RUN["_id"]),
            "task_id": TASK_ID,
            "unique_key": worker_info["unique_key"],
        }
        try:
            requests.post(
                remote + "/api/failed_task",
                data=json.dumps(payload),
                headers={"Content-type": "application/json"},
                timeout=HTTP_TIMEOUT,
            )
        except:
            pass

        TASK_ID = None
        if success and ALIVE:
            sleep = random.randint(1, 10)
            print("Wait {} seconds before upload of PGN...".format(sleep))
            time.sleep(sleep)
            if "spsa" not in RUN["args"]:
                try:
                    with open(pgn_file, "r") as f:
                        data = f.read()
                    # Ignore non utf-8 characters in PGN file
                    if sys.version_info[0] == 2:
                        data = data.decode("utf-8", "ignore").encode(
                            "utf-8")  # Python 2
                    else:
                        data = bytes(data,
                                     "utf-8").decode("utf-8",
                                                     "ignore")  # Python 3
                    payload["pgn"] = base64.b64encode(
                        zlib.compress(data.encode("utf-8"))).decode()
                    print("Uploading compressed PGN of {} bytes".format(
                        len(payload["pgn"])))
                    requests.post(
                        remote + "/api/upload_pgn",
                        data=json.dumps(payload),
                        headers={"Content-type": "application/json"},
                        timeout=HTTP_TIMEOUT,
                    )
                except Exception as e:
                    sys.stderr.write("\nException PGN upload:\n")
                    print(e, file=sys.stderr)
        #          traceback.print_exc()
        try:
            os.remove(pgn_file)
        except:
            pass
        sys.stderr.write("Task exited\n")

    return success
Exemple #45
0
def load():
        files = os.listdir()
        if DATA not in files:
                subprocess.call(['cp', 'data.empty', DATA])
        if PROJECT not in files:
                subprocess.call(['cp', 'project.empty', PROJECT])
        global data
        global project_persist
        data = yaml.load(open(DATA))
        project_persist = yaml.load(open(PROJECT))
        project.CURRENT_ID = project_persist['project_id']


def save():
        global project_persist
        project_persist['project_id'] = project.CURRENT_ID
        project_out = open(PROJECT, 'w')
        data_out = open(DATA, 'w')
        project_out.write(yaml.dump(project_persist))
        data_out.write(yaml.dump(data))
        project_out.close()
        data_out.close()


app = Flask(__name__)
app.secret_key = b"\xc5S\xbe\xfa\xdf\xd5\x80I\xdfi\xa5[h\xda\xb8\xacb\xd2\xe2\x83Kc\x89]\xb2\xed\xbd\x8cc pM1(YC\x96\xf2Y+\xfd\x16\x99A\xc6\x80\xa2\x08\xe6\xa3\xfb\x17|\xf9\x82H\xb6\xb41\x8d\x13\x12B\xa6\xef\xab\xe7'8\x973\xec\x964jr4\xe5U\xf7\xe4|J\x88\xf3K\x96\xa2E6\x94\x85\x85\xc9\xf8\x07\xb0\xc3\xc1\xb4"
load()

if update(project_persist, data):
        save()
Exemple #46
0
#!/usr/bin/python
VERSION="1.97"

import time, shelve, os, sys, random, string, MySQLdb, threading, socket, shutil
import ircbot, irclib, botconfig, updater, hashlib

print "\n*********************************************************************"
print "** ZooKeeper " + VERSION + " - Gazelle Server IRC Bot"
print "** http://tbsf.me/zookeeper - Written By: eXploytIT - April 2011" 
print "*********************************************************************"
print "** Options: --noupdate || -n : Don't check for updates"
print "*********************************************************************\n"

## Check for updates
if "--noupdate" not in sys.argv and "-n" not in sys.argv:
    updater.update(VERSION)

## Validate config file
config_response = botconfig.configure()
if config_response != "Error":
    print "*** Config read OK ***"
    conf = shelve.open(".config")
    for i,v in config_response.iteritems():
        conf[i] = v
    conf.close()
else:
    sys.exit()

## Make the config dictionary
config = shelve.open(".config")
Exemple #47
0
parser.add_argument('--rebuild', dest='rebuild', action='store_const',
                    const=True, default=False,
                    help='rebuild all the cached e_sets')

arg = parser.parse_args()

config = conf.EServiceConfiguration()

# Load the testing configuration
config.load(arg.config)

if len(config.e_set_configs) is 0:
    print "No enrichment sets are specified in the configuration"
    sys.exit()

for e_set_config in config.e_set_configs:

    updater.update(e_set_config, arg.rebuild)

print "Update complete"



# if not e_set_config_to_update:
#     print "No enrichment set in configuration file for name: " + arg.eset
#     print "The configured enrichment sets are:"
#     for e_set_config in config.e_set_configs:
#         print str(e_set_config)
#     sys.exit()