示例#1
0
文件: gtk.py 项目: fabianod/obozrenie
    def on_startup(self, app):
        """
        Startup function.
        Loads the GtkBuilder resources, settings and start the main loop.
        """

        try:
            # Load settings
            helpers.debug_msg([GTK_MSG, i18n._("Obozrenie is starting")])
            guiactions = self.guiactions

            self.status = "starting"
            guiactions.fill_game_store()

            self.settings.load(
                callback_postgenload=self.guiactions.cb_post_settings_genload)

            # Connect signals
            self.builder.connect_signals(self.guiactions)
            guiactions.gtk_widgets["server-list-filter"].set_visible_func(
                guiactions.server_filter_func)

            gtk_helpers.set_widget_value(
                self.guiactions.gtk_widgets["game-combobox"],
                self.settings.settings_table["common"]
                ["selected-game-browser"])
            for entry in self.guiactions.filter_secure_list:
                guiactions.gtk_widgets["filter-secure"].append(
                    entry["id"], entry["text"])
            guiactions.cb_game_treeview_togglebutton_clicked()
            guiactions.cb_server_filters_changed()
            try:
                guiactions.cb_server_connect_data_changed()
            except ValueError:
                pass

            # Add main window
            main_window = self.guiactions.gtk_widgets["main-window"]
            self.add_window(main_window)

            # Create menu actions
            about_action = Gio.SimpleAction.new("about", None)
            quit_action = Gio.SimpleAction.new("quit", None)

            about_action.connect("activate", self.guiactions.cb_about,
                                 main_window)
            quit_action.connect("activate", self.guiactions.cb_quit, self)

            self.add_action(about_action)
            self.add_action(quit_action)

            self.set_app_menu(self.builder.get_object("app-menu"))

            gtk_helpers.set_object_properties(self.guiactions.gtk_widgets,
                                              GTK_STRING_TABLE)

            self.status = "up"
        except Exception as e:
            app.quit()
            raise e
示例#2
0
文件: gtk.py 项目: skybon/obozrenie
 def on_shutdown(self, app):
     if self.status == "up":
         self.settings.save()
         self.status = "shutting down"
         helpers.debug_msg([GTK_MSG, i18n._("Shutting down")])
     else:
         self.status = "start failed"
         helpers.debug_msg([GTK_MSG, i18n._("Initialization failed. Aborting.")])
示例#3
0
文件: gtk.py 项目: fabianod/obozrenie
 def on_shutdown(self, app):
     if self.status == "up":
         self.settings.save()
         self.status = "shutting down"
         helpers.debug_msg([GTK_MSG, i18n._("Shutting down")])
     else:
         self.status = "start failed"
         helpers.debug_msg(
             [GTK_MSG, i18n._("Initialization failed. Aborting.")])
示例#4
0
def do_launch(launch_cmd: list) -> Exception:
    try:
        # Launch
        helpers.debug_msg([LAUNCHER_MSG, i18n._("Launching '%(launch_cmd)s'") % {'launch_cmd': " ".join(launch_cmd)}])
        env_dict = dict(os.environ)
        pid = subprocess.Popen(launch_cmd, cwd=env_dict['PWD'], env=env_dict, start_new_session=True)
        return None
    except OSError as e:
        helpers.debug_msg([LAUNCHER_MSG, e])
        return e
示例#5
0
文件: gtk.py 项目: skybon/obozrenie
    def on_startup(self, app):
        """
        Startup function.
        Loads the GtkBuilder resources, settings and start the main loop.
        """

        try:
            # Load settings
            helpers.debug_msg([GTK_MSG, i18n._("Obozrenie is starting")])
            guiactions = self.guiactions

            self.status = "starting"
            guiactions.fill_game_store()

            self.settings.load(callback_postgenload=self.guiactions.cb_post_settings_genload)

            # Connect signals
            self.builder.connect_signals(self.guiactions)
            guiactions.gtk_widgets["server-list-filter"].set_visible_func(guiactions.server_filter_func)

            gtk_helpers.set_widget_value(self.guiactions.gtk_widgets["game-combobox"], self.settings.settings_table["common"]["selected-game-browser"])
            for entry in self.guiactions.filter_secure_list:
                guiactions.gtk_widgets["filter-secure"].append(entry["id"], entry["text"])
            guiactions.cb_game_treeview_togglebutton_clicked()
            guiactions.cb_server_filters_changed()
            try:
                guiactions.cb_server_connect_data_changed()
            except ValueError:
                pass

            # Add main window
            main_window = self.guiactions.gtk_widgets["main-window"]
            self.add_window(main_window)

            # Create menu actions
            about_action = Gio.SimpleAction.new("about", None)
            quit_action = Gio.SimpleAction.new("quit", None)

            about_action.connect("activate", self.guiactions.cb_about, main_window)
            quit_action.connect("activate", self.guiactions.cb_quit, self)

            self.add_action(about_action)
            self.add_action(quit_action)

            self.set_app_menu(self.builder.get_object("app-menu"))

            gtk_helpers.set_object_properties(self.guiactions.gtk_widgets, GTK_STRING_TABLE)

            self.status = "up"
        except Exception as e:
            app.quit()
            raise e
示例#6
0
def do_launch(launch_cmd: list) -> Exception:
    try:
        # Launch
        helpers.debug_msg([
            LAUNCHER_MSG,
            i18n._("Launching '%(launch_cmd)s'") % {
                'launch_cmd': " ".join(launch_cmd)
            }
        ])
        env_dict = dict(os.environ)
        pid = subprocess.Popen(launch_cmd,
                               cwd=env_dict['PWD'],
                               env=env_dict,
                               start_new_session=True)
        return None
    except OSError as e:
        helpers.debug_msg([LAUNCHER_MSG, e])
        return e
示例#7
0
    def __init__(self):
        self.game_table = GameTable(helpers.load_table(GAME_CONFIG_FILE))

        try:
            import pygeoip
            try:
                open(GEOIP_DATA_FILE)
                helpers.debug_msg([
                    CORE_MSG,
                    i18n.
                    _("GeoIP data file %(geoip_data_file)s opened successfully."
                      ) % {
                          'geoip_data_file': GEOIP_DATA_FILE
                      }
                ])
                self.geolocation = pygeoip
            except FileNotFoundError:
                helpers.debug_msg([
                    CORE_MSG,
                    i18n._("GeoIP data file not found. Disabling geolocation.")
                ])
                self.geolocation = None
        except ImportError:
            helpers.debug_msg([
                CORE_MSG,
                i18n._("PyGeoIP not found. Disabling geolocation.")
            ])
            self.geolocation = None
示例#8
0
文件: core.py 项目: skybon/obozrenie
    def stat_master_target(self, game: str, callback=None) -> None:
        """Separate update thread. Strictly per-game."""
        game_info = self.game_table.get_game_info(game)
        game_settings = self.game_table.get_game_settings(game)
        game_name = game_info["name"]
        master_list = list(game_settings["master_uri"])
        adapter = game_info["adapter"]

        # Start query if it's not up already
        if self.game_table.get_query_status(game) != self.game_table.QUERY_STATUS.WORKING:
            self.game_table.set_query_status(game, self.game_table.QUERY_STATUS.WORKING)
            helpers.debug_msg([CORE_MSG, i18n._("Refreshing server list for %(game)s.") % {"game": game_name}])
            stat_master_cmd = adapters.adapter_table[adapter].stat_master
            temp_list = None

            try:
                temp_list = stat_master_cmd(game, game_info, master_list)
            except Exception as e:
                helpers.debug_msg([CORE_MSG, e])
                helpers.debug_msg(
                    [CORE_MSG, i18n._("Internal backend error for %(game)s.") % {"game": game_name}, ERROR_MSG]
                )
                self.game_table.set_query_status(game, self.game_table.QUERY_STATUS.ERROR)
            else:
                self.game_table.set_servers_data(game, temp_list)

                for entry in temp_list:
                    entry["country"] = "unknown"
                    if self.geolocation is not None:
                        host = entry["host"].split(":")[0]
                        try:
                            entry["country"] = self.geolocation.GeoIP(GEOIP_DATA_FILE).country_code_by_addr(host)
                        except OSError:
                            try:
                                entry["country"] = self.geolocation.GeoIP(GEOIP_DATA_FILE).country_code_by_name(host)
                            except:
                                entry["country"] = ""
                        except:
                            pass

                self.game_table.set_servers_data(game, temp_list)

                self.game_table.set_query_status(game, self.game_table.QUERY_STATUS.READY)

        # Call post-stat callback
        if callback is not None:
            callback(game)
示例#9
0
文件: core.py 项目: skybon/obozrenie
    def __init__(self):
        self.game_table = GameTable(helpers.load_table(GAME_CONFIG_FILE))

        try:
            import pygeoip

            try:
                open(GEOIP_DATA_FILE)
                helpers.debug_msg(
                    [
                        CORE_MSG,
                        i18n._("GeoIP data file %(geoip_data_file)s opened successfully.")
                        % {"geoip_data_file": GEOIP_DATA_FILE},
                    ]
                )
                self.geolocation = pygeoip
            except FileNotFoundError:
                helpers.debug_msg([CORE_MSG, i18n._("GeoIP data file not found. Disabling geolocation.")])
                self.geolocation = None
        except ImportError:
            helpers.debug_msg([CORE_MSG, i18n._("PyGeoIP not found. Disabling geolocation.")])
            self.geolocation = None
示例#10
0
文件: core.py 项目: skybon/obozrenie
            for option in self.core.game_table.get_game_settings(game):
                value = default_game_settings_table[game][option]
                try:
                    value = user_game_settings_table[game][option]
                except (ValueError, KeyError, TypeError):
                    pass

                self.core.game_table.set_game_setting(game, option, value)

    def save(self) -> None:
        """Saves configuration."""
        # Save common settings table
        helpers.save_table(self.user_common_settings_path, self.settings_table)

        # Compile game settings table
        user_game_settings_table = {}
        for game in self.core.game_table.get_game_set():
            user_game_settings_table[game] = self.core.game_table.get_game_settings(game)

        # Save game settings
        helpers.save_table(self.user_game_settings_path, user_game_settings_table)


if __name__ == "__main__":
    helpers.debug_msg(
        [
            CORE_MSG,
            i18n._("This is the core module of Obozrenie Game Server Browser. Please run an appropriate UI instead."),
        ]
    )
示例#11
0
def debug_msg(game_name, msg=None):
    if msg is not None:
        helpers.debug_msg([QSTAT_MSG, game_name, msg])
示例#12
0
# it under the terms of the GNU General Public License version 3, as
# published by the Free Software Foundation.

# Obozrenie is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with Obozrenie.  If not, see <http://www.gnu.org/licenses/>.

from typing import *

import obozrenie.helpers as helpers

from obozrenie.global_settings import *
from obozrenie.global_strings import *

from . import rigsofrods
from . import qstat
from . import minetest

adapter_table = {}

adapter_list = ('rigsofrods', 'qstat', 'minetest')

for adapter in adapter_list:
    adapter_table[adapter] = globals()[adapter]

helpers.debug_msg([CORE_MSG, i18n._("%(adapter_num)i adapters loaded successfully") % {'adapter_num': len(adapter_list)}])
示例#13
0
def debug_msg(game_name, msg=None):
    if msg is not None:
        helpers.debug_msg([QSTAT_MSG, game_name, msg])
示例#14
0
    def stat_master_target(self, game: str, callback: Optional[Callable] = None) -> None:
        """Separate update thread. Strictly per-game."""
        game_info = self.game_table.get_game_info(game)
        game_settings = self.game_table.get_game_settings(game)
        game_name = game_info["name"]
        master_list = list(game_settings["master_uri"])
        adapter = game_info["adapter"]

        # Start query if it's not up already
        if self.game_table.get_query_status(game) != self.game_table.QUERY_STATUS.WORKING:
            self.game_table.set_query_status(game, self.game_table.QUERY_STATUS.WORKING)
            helpers.debug_msg([CORE_MSG, i18n._("Refreshing server list for %(game)s.") % {"game": game_name}])
            server_list_proxy = None
            stat_master_cmd = adapters.adapter_table[adapter].stat_master
            try:
                mgr = multiprocessing.Manager()
                server_list_proxy = mgr.list()
                backend_process = multiprocessing.Process(
                    target=stat_master_cmd, args=(game, game_info, master_list, server_list_proxy)
                )
                backend_process.daemon = True
                backend_process.start()
                backend_process.join()
                if len(server_list_proxy) > 0 and issubclass(type(server_list_proxy[0]), Exception):
                    e = server_list_proxy[0]
                    raise e
            except Exception as e:
                helpers.debug_msg([CORE_MSG, e])
                helpers.debug_msg(
                    [CORE_MSG, i18n._("Internal backend error for %(game)s.") % {"game": game_name}, ERROR_MSG]
                )
                self.game_table.set_query_status(game, self.game_table.QUERY_STATUS.ERROR)

            # ListProxy -> list
            if self.game_table.get_query_status(game) != self.game_table.QUERY_STATUS.ERROR:
                self.game_table.set_servers_data(game, server_list_proxy)
                temp_list = []  # type: List[dict]
                for entry in server_list_proxy:
                    temp_list.append(entry)

                for entry in temp_list:
                    entry["country"] = "unknown"
                    if self.geolocation is not None:
                        host = entry["host"].split(":")[0]
                        try:
                            entry["country"] = self.geolocation.GeoIP(GEOIP_DATA_FILE).country_code_by_addr(host)
                        except OSError:
                            try:
                                entry["country"] = self.geolocation.GeoIP(GEOIP_DATA_FILE).country_code_by_name(host)
                            except:
                                entry["country"] = ""
                        except:
                            pass

                self.game_table.set_servers_data(game, temp_list)

                self.game_table.set_query_status(game, self.game_table.QUERY_STATUS.READY)

        # Call post-stat callback
        if callback is not None:
            callback(game)
示例#15
0
# Obozrenie is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 3, as
# published by the Free Software Foundation.

# Obozrenie is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with Obozrenie.  If not, see <http://www.gnu.org/licenses/>.

import obozrenie.helpers as helpers

from obozrenie.global_settings import *
from obozrenie.global_strings import *

from . import rigsofrods
from . import qstat
from . import minetest

adapter_table = {}

adapter_list = ('rigsofrods', 'qstat', 'minetest')

for adapter in adapter_list:
    adapter_table[adapter] = globals()[adapter]

helpers.debug_msg([CORE_MSG, i18n._("%(adapter_num)i adapters loaded successfully") % {'adapter_num': len(adapter_list)}])
示例#16
0
# Obozrenie is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with Obozrenie.  If not, see <http://www.gnu.org/licenses/>.

import obozrenie.helpers as helpers

from obozrenie.global_settings import *
from obozrenie.global_strings import *

from . import qstat_process
from . import requests_http

proxy_table = {}

proxy_list = ('qstat_process', 'requests_http')

for proxy in proxy_list:
    proxy_table[proxy] = globals()[proxy]

helpers.debug_msg([
    CORE_MSG,
    "%(proxy_num)i proxies loaded successfully" % {
        'proxy_num': len(proxy_list)
    }
])
示例#17
0
                try:
                    value = user_game_settings_table[game][option]
                except (ValueError, KeyError, TypeError):
                    pass

                self.core.game_table.set_game_setting(game, option, value)

    def save(self) -> None:
        """Saves configuration."""
        # Save common settings table
        helpers.save_table(self.user_common_settings_path, self.settings_table)

        # Compile game settings table
        user_game_settings_table = {}
        for game in self.core.game_table.get_game_set():
            user_game_settings_table[
                game] = self.core.game_table.get_game_settings(game)

        # Save game settings
        helpers.save_table(self.user_game_settings_path,
                           user_game_settings_table)


if __name__ == "__main__":
    helpers.debug_msg([
        CORE_MSG,
        i18n.
        _("This is the core module of Obozrenie Game Server Browser. Please run an appropriate UI instead."
          )
    ])
示例#18
0
    def stat_master_target(self, game: str, callback=None) -> None:
        """Separate update thread. Strictly per-game."""
        game_info = self.game_table.get_game_info(game)
        game_settings = self.game_table.get_game_settings(game)
        game_name = game_info["name"]
        master_list = list(game_settings["master_uri"])
        adapter = game_info["adapter"]

        # Start query if it's not up already
        if self.game_table.get_query_status(
                game) != self.game_table.QUERY_STATUS.WORKING:
            self.game_table.set_query_status(
                game, self.game_table.QUERY_STATUS.WORKING)
            helpers.debug_msg([
                CORE_MSG,
                i18n._("Refreshing server list for %(game)s.") % {
                    'game': game_name
                }
            ])
            stat_master_cmd = adapters.adapter_table[adapter].stat_master
            temp_list = None

            try:
                temp_list = stat_master_cmd(game, game_info, master_list)
            except Exception as e:
                helpers.debug_msg([CORE_MSG, e])
                helpers.debug_msg([
                    CORE_MSG,
                    i18n._("Internal backend error for %(game)s.") % {
                        'game': game_name
                    }
                ])
                self.game_table.set_query_status(
                    game, self.game_table.QUERY_STATUS.ERROR)
            else:
                self.game_table.set_servers_data(game, temp_list)

                for entry in temp_list:
                    entry['country'] = "unknown"
                    if self.geolocation is not None:
                        host = entry["host"].split(':')[0]
                        try:
                            entry['country'] = self.geolocation.GeoIP(
                                GEOIP_DATA_FILE).country_code_by_addr(host)
                        except OSError:
                            try:
                                entry['country'] = self.geolocation.GeoIP(
                                    GEOIP_DATA_FILE).country_code_by_name(host)
                            except:
                                entry['country'] = ""
                        except:
                            pass

                self.game_table.set_servers_data(game, temp_list)

                self.game_table.set_query_status(
                    game, self.game_table.QUERY_STATUS.READY)

        # Call post-stat callback
        if callback is not None:
            callback(game)
示例#19
0
# For more information, see https://github.com/obozrenie/obozrenie

# Obozrenie is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 3, as
# published by the Free Software Foundation.

# Obozrenie is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with Obozrenie.  If not, see <http://www.gnu.org/licenses/>.

import obozrenie.helpers as helpers

from obozrenie.global_settings import *
from obozrenie.global_strings import *

from . import qstat_process
from . import requests_http

proxy_table = {}

proxy_list = ('qstat_process', 'requests_http')

for proxy in proxy_list:
    proxy_table[proxy] = globals()[proxy]

helpers.debug_msg([CORE_MSG, "%(proxy_num)i proxies loaded successfully" % {'proxy_num': len(proxy_list)}])