コード例 #1
0
 def test_start(self):
     machine_id = "machine1"
     t.provision(__cloudify_id=machine_id)
     t.start(__cloudify_id=machine_id)
     machines = t.get_machines()
     self.assertEqual(1, len(machines))
     self.assertTrue(machine_id in machines)
     self.assertEqual(t.RUNNING, machines[machine_id])
コード例 #2
0
def test_start(monkeypatch, capsys):
    def mock_serve(*args, **kwargs):
        print(*args, kwargs)

    monkeypatch.setattr(tasks, '_serve', mock_serve)
    monkeypatch.setattr(MockContext, '__str__', lambda x: 'MockContext')
    c = MockContext()
    tasks.start(c, 'name')
    assert capsys.readouterr().out == "MockContext name {'start': True}\n"
    tasks.start(c)
    assert capsys.readouterr().out == "MockContext None {'start': True}\n"
コード例 #3
0
def start_app():
  # verify if folder already exists
  if os.path.exists( os.path.expanduser('~/.mercenary/tasks.json') ):
    args = sys.argv
    
    if "stop" in args:
      print(t.stop())
    
    elif "on" in args:
      # Only start task if the task is informed
      try:
        print(t.start(args[2]))
      except IndexError:
        print("Invalid usage. use -h for help")
    
    elif "list" in args:
      print(t.resume())

    else:
      print(t.status())
  else :
    # create the folder if it not exists
    os.system('mkdir %s' % os.path.expanduser('~/.mercenary'))
    os.system('echo \'{"tasks": []}\' > %s' % os.path.expanduser('~/.mercenary/tasks.json'))
    # Let's try again, right?
    start_app()
コード例 #4
0
ファイル: server.py プロジェクト: mscalora/motioneye
def run():
    import cleanup
    import mjpgclient
    import motionctl
    import motioneye
    import smbctl
    import tasks
    import wsswitch

    configure_signals()
    logging.info('hello! this is motionEye server %s' % motioneye.VERSION)

    test_requirements()
    make_media_folders()

    if settings.SMB_SHARES:
        stop, start = smbctl.update_mounts()  # @UnusedVariable
        if start:
            start_motion()

    else:
        start_motion()

    if settings.CLEANUP_INTERVAL:
        cleanup.start()
        logging.info('cleanup started')

    wsswitch.start()
    logging.info('wsswitch started')

    tasks.start()
    logging.info('tasks started')

    if settings.MJPG_CLIENT_TIMEOUT:
        mjpgclient.start()
        logging.info('mjpg client garbage collector started')

    if settings.SMB_SHARES:
        smbctl.start()
        logging.info('smb mounts started')

    template.add_context('static_path', settings.BASE_PATH + '/static/')

    application = Application(handler_mapping,
                              debug=False,
                              log_function=_log_request,
                              static_path=settings.STATIC_PATH,
                              static_url_prefix='/static/')

    application.listen(settings.PORT, settings.LISTEN)
    logging.info('server started')

    io_loop = IOLoop.instance()
    io_loop.start()

    logging.info('server stopped')

    tasks.stop()
    logging.info('tasks stopped')

    if cleanup.running():
        cleanup.stop()
        logging.info('cleanup stopped')

    if motionctl.running():
        motionctl.stop()
        logging.info('motion stopped')

    if settings.SMB_SHARES:
        smbctl.stop()
        logging.info('smb mounts stopped')

    logging.info('bye!')
コード例 #5
0
ファイル: server.py プロジェクト: algestam/motioneye
def run():
    import cleanup
    import mjpgclient
    import motionctl
    import motioneye
    import smbctl
    import tasks
    import wsswitch

    configure_signals()
    logging.info('hello! this is motionEye server %s' % motioneye.VERSION)

    test_requirements()
    make_media_folders()

    if settings.SMB_SHARES:
        stop, start = smbctl.update_mounts()  # @UnusedVariable
        if start:
            start_motion()

    else:
        start_motion()

    if settings.CLEANUP_INTERVAL:
        cleanup.start()
        logging.info('cleanup started')
        
    wsswitch.start()
    logging.info('wsswitch started')

    tasks.start()
    logging.info('tasks started')

    if settings.MJPG_CLIENT_TIMEOUT:
        mjpgclient.start()
        logging.info('mjpg client garbage collector started')

    if settings.SMB_SHARES:
        smbctl.start()
        logging.info('smb mounts started')

    template.add_context('static_path', settings.BASE_PATH + '/static/')
    
    application = Application(handler_mapping, debug=False, log_function=_log_request,
            static_path=settings.STATIC_PATH, static_url_prefix='/static/')
    
    application.listen(settings.PORT, settings.LISTEN)
    logging.info('server started')
    
    io_loop = IOLoop.instance()
    io_loop.start()

    logging.info('server stopped')
    
    tasks.stop()
    logging.info('tasks stopped')

    if cleanup.running():
        cleanup.stop()
        logging.info('cleanup stopped')

    if motionctl.running():
        motionctl.stop()
        logging.info('motion stopped')
    
    if settings.SMB_SHARES:
        smbctl.stop()
        logging.info('smb mounts stopped')

    logging.info('bye!')
コード例 #6
0
def run():
    import cleanup
    import mjpgclient
    import motionctl
    import motioneye
    import smbctl
    import tasks
    import wsswitch

    configure_signals()
    logging.info('hello! this is motionEye server %s' % motioneye.VERSION)

    test_requirements()
    make_media_folders()

    if settings.SMB_SHARES:
        stop, start = smbctl.update_mounts()  # @UnusedVariable
        if start:
            start_motion()

    else:
        start_motion()

    if settings.CLEANUP_INTERVAL:
        cleanup.start()
        logging.info('cleanup started')

    wsswitch.start()
    logging.info('wsswitch started')

    tasks.start()
    logging.info('tasks started')

    if settings.MJPG_CLIENT_TIMEOUT:
        mjpgclient.start()
        logging.info('mjpg client garbage collector started')

    if settings.SMB_SHARES:
        smbctl.start()
        logging.info('smb mounts started')

    template.add_context('static_path', 'static/')

    application = Application(handler_mapping,
                              debug=False,
                              log_function=_log_request,
                              static_path=settings.STATIC_PATH,
                              static_url_prefix='/static/')

    if settings.SSL_PORT > 0:
        application.listen(settings.SSL_PORT,
                           settings.LISTEN,
                           ssl_options={
                               "certfile": settings.SSL_CERT,
                               "keyfile": settings.SSL_KEY,
                           })
        logging.info('https server started on port: %s' % settings.SSL_PORT)

    application.listen(settings.PORT, settings.LISTEN)
    logging.info('http server started ono port: %s' % settings.PORT)

    io_loop = IOLoop.instance()
    # we need to reset the loop's PID to fix PID checks when running in daemon mode
    io_loop._pid = os.getpid()
    io_loop.start()

    logging.info('server stopped')

    tasks.stop()
    logging.info('tasks stopped')

    if cleanup.running():
        cleanup.stop()
        logging.info('cleanup stopped')

    if motionctl.running():
        motionctl.stop()
        logging.info('motion stopped')

    if settings.SMB_SHARES:
        smbctl.stop()
        logging.info('smb mounts stopped')

    logging.info('bye!')
コード例 #7
0
async def on_message(m):
    if m.author.id == bot.user:
        return
    if m.guild is not None:
        if m.guild.id not in WHITELISTED_GUILDS:
            logger.warn(f'bad guild: {m.guild.id!r}')
            return

    if m.content.startswith(config.PREFIX):
        cmd = m.content[len(config.PREFIX):].split(" ")[0]
        try:
            await run_cmd(cmd, m)
        except Exception as e:
            if isinstance(e, APIError):
                logger.exception("API error in cmd {cmd}: ")
                await m.channel.send("Enriching Students API error: " + str(e))
            else:
                e = traceback.format_exc()
                logger.exception("Error in cmd {cmd}: {e}")
                await m.channel.send(f"```\n{e}\n```")


if __name__ == '__main__':
    print("Running...")
    logger.info("\n\n-----RESTART-----\n\n")
    logger.info(f"Schedule bot {version} starting...")
    loop = asyncio.get_event_loop()
    loop.create_task(web.run())
    tasks.start(loop)
    bot.run(config.getenv('TOKEN') or input("token: "))