def download_update(self, version):
     link = self.get_download_link(version)
     log.info(link)
     with TqdmUpTo(unit='B',
                   unit_scale=True,
                   miniters=1,
                   desc=link.split('/')[-1]) as t:
         self._temp_update = request.urlretrieve(
             link, reporthook=t.download_progress)[0]
 def apply_update(self):
     if self._temp_update:
         commands = [
             self.executable.as_posix(), '--apply-update', self._temp_update
         ]
         p = Popen(commands, stdout=PIPE, stderr=PIPE)
         log.info(p.communicate())
         p.terminate()
     self.set_version_info()
     self.update_available = False
Exemple #3
0
 def stop():
     if hasattr(cherrypy.engine, 'factorio_ws_handler'):
         cherrypy.engine.factorio_ws_handler.close()
     if hasattr(cherrypy.engine, 'log_ws_handler'):
         cherrypy.engine.log_ws_handler.close()
     for process in instances.values():
         try:
             process.stop()
         finally:
             pass
     log.info('FSM server stopped')
 def create_save_file(self,
                      map_gen_file_path=None,
                      map_settings_path=None,
                      preset=None,
                      map_preview_path=None):
     if not self.save_file.is_file():
         if not (self.save_file / '..').resolve().is_dir():
             (self.save_file / '..').resolve().mkdir()
         commands = [
             self.executable.as_posix(), '--create',
             self.save_file.as_posix()
         ]
         # TODO: Add the optional arguments to commands
         p = Popen(commands, stdout=PIPE, stderr=PIPE)
         log.info(p.communicate())
 def start(self):
     log.info(f'Starting Factorio instance {self.name}')
     if self.name in app_settings.factorio_instances:
         if isinstance(self.process, Popen):
             # TODO: need to do more here to actually check if it is running
             log.warn(f'{self.name} factorio instance is already running')
             return
     if self.name not in app_settings.factorio_instances:
         log.warn(f'{self.name} factorio instance does not exist')
         return
     commands = [
         self.executable.as_posix(), '--start-server', self.save_file,
         '--port',
         str(self.port)
     ]
     log.debug(f'Starting {self.name}')
     self.process = Popen(commands, stdin=PIPE, stdout=PIPE, stderr=PIPE)
     self.output_log()
 def set_version_info(self):
     log.info(f'Getting the version info for {self.name}')
     commands = [self.executable.as_posix(), '--version']
     p = Popen(commands, stdout=PIPE, stderr=PIPE)
     std_out, std_err = p.communicate()
     self._version_info = std_out.decode().splitlines()
     self._version_info = {
         l.split(':')[0].lower(): l.split(':')[1]
         for l in self._version_info
     }
     self._version_info['build'] = self._version_info['version'].split(
         '(')[1]
     self._version_info['build'] = self._version_info['build'].replace(
         ')', '').split(', ')
     self._version_info['build'] = {
         'number': self._version_info['build'][0].replace('build', ''),
         'platform': self._version_info['build'][1],
         'mode': self._version_info['build'][2]
     }
     self._version_info['version'] = self._version_info['version'].split(
         '(')[0].strip()
Exemple #7
0
def main(args):
    with open('fsm.pid', 'w+') as pid_file:
        pid_file.write(str(os.getpid()))

    if args.debug:
        log.handlers[-1].setLevel(logging.DEBUG)
        log.setLevel(logging.DEBUG)

    log.debug('Setting app users')
    app_settings.web_admin_users = current_settings['web_admin_users']

    log.debug('Setting app port')
    app_settings.web_admin_port = args.web_admin_port

    for name, instance in current_settings['factorio_instances'].items():
        app_settings.factorio_instances[name] = FactorioManager(
            name, instance['port'], instance['root_path'])
        update = app_settings.factorio_instances[name].check_for_update()
        if update:
            log.info(
                f'Update Available: ver. {update}\tCurrent: {app_settings.factorio_instances[name].version}'
            )

    global_conf = {
        'global': {
            'engine.autoreload.on': False,
            'server.socket_host': '0.0.0.0',
            'server.socket_port': args.web_admin_port,
            'log.screen': False,
            'server.ssl_module': 'builtin',
            'server.ssl_certificate': f'{APP_DIR}/certs/fsm_cert.pem',
            'server.ssl_private_key': f'{APP_DIR}/certs/fsm_key.pem',
        },
    }
    conf = {
        '/': {
            'tools.sessions.on': True,
            'tools.auth.on': True,
            'tools.log_tracebacks.on': True,
            'tools.staticdir.on': True,
            'tools.staticdir.dir': f'{APP_DIR}/root',
            'log.access_file': f'{APP_DIR}/logs/cherrypy_access.log',
            'log.error_file': f'{APP_DIR}/logs/cherrypy_error.log',
        },
        '/css': {
            'tools.staticdir.on': True,
            'tools.staticdir.dir': f'{APP_DIR}/css',
        },
        '/js': {
            'tools.staticdir.on': True,
            'tools.staticdir.dir': f'{APP_DIR}/js',
        },
    }

    if args.debug_cherrypy:
        global_conf['global']['log.screen'] = True

    if args.launch_factorios:
        names = args.launch_factorios.split(',')
        for name in names:
            if name in app_settings.factorio_instances:
                app_settings.factorio_instances[name].start()

    log.info(f'Starting web server on https://0.0.0.0:{args.web_admin_port}')
    cherrypy.config.update(global_conf)

    WebSocketPlugin(cherrypy.engine).subscribe()
    cherrypy.tools.websocket = WebSocketTool()

    cherrypy.tree.mount(root=WebAdmin(), config=conf)
    cherrypy.engine.start()
    cherrypy.engine.block()
Exemple #8
0
 def on_logout(username):
     log.info(f'User {username} logged out')
Exemple #9
0
 def on_login(username):
     log.info(f'User {username} logged in')
Exemple #10
0
 def start():
     log.info('FSM server started')
Exemple #11
0
 def update(self, name, version):
     log.info(version)
     instances[name].download_update(version)
     instances[name].apply_update()
Exemple #12
0
 def stop(self, name):
     log.info(f'Trying to stop {name}')
     instances[name].stop()
Exemple #13
0
 def received_message(self, message):
     log.info(message)