Esempio n. 1
0
def main(argv):
    """Main."""

    if len(argv) < 3:
        print "USAGE: %s MODE HOST:PORT" % argv[0]
    else:
        mode = argv[1]
        uri = argv[2]
        if mode == "server":
            app = app_factory()
            # app.initialise(os.path.abspath(os.path.join(os.getcwdu(), ".mnemosyne")))
            app.initialise(os.path.abspath(os.path.join(os.getcwdu(), "testdb")))
            database = app.database()
            server = Server(uri, database, app.config(), app.log())
            server.start()
            app.finalise()
        elif mode == "client":
            app = app_factory()
            # app.initialise(os.path.abspath(os.path.join(os.getcwdu(), "testdb")))
            app.initialise(os.path.abspath(os.path.join(os.getcwdu(), ".mnemosyne")))
            database = app.database()
            client = Client(uri, database, app.controller(), app.config(), app.log())
            client.start()
            app.finalise()
        else:
            print "unknown mode"
Esempio n. 2
0
    def start_server_sync_cb(self, widget):
        """Starts syncing as Server."""

        if not widget.get_active():
            try:
                port = int(self.get_widget(\
                    "sync_mode_server_port_entry").get_text())
            except ValueError:
                self.main_widget().error_box("Wrong port number!")
            else:
                host = self.get_widget(\
                    "sync_mode_server_address_entry").get_text()
                self.show_or_hide_containers(False, "server")
                try:
                    messenger = UIMessenger(self.show_message, \
                    self.complete_events, self.update_server_status, \
                    self.server_progressbar.show, \
                    self.update_server_progressbar, \
                    self.server_progressbar.hide)
                    self.server = Server("%s:%s" % (host, port), \
                    self.database(), self.config(), self.log(), messenger)
                except socket.error, error:
                    self.show_message(str(error))
                else:
                    self.server.set_user(\
                        self.get_widget("sync_mode_server_login_entry"). \
                            get_text(), 
                        self.get_widget("sync_mode_server_passwd_entry"). \
                            get_text())
                    self.server.start()
                self.show_or_hide_containers(True, "server")
                self.get_widget(\
                    "sync_mode_server_start_button").set_active(False)
Esempio n. 3
0
class SyncWidget(UiComponent):
    """Sync Widget."""

    def __init__(self, component_manager):
        UiComponent.__init__(self, component_manager)
        self.client = None
        self.server = None
        self.db_path = None
        self.server_thread = None
        self.w_tree = self.main_widget().w_tree
        self.w_tree.signal_autoconnect(\
            dict([(sig, getattr(self, sig + "_cb")) for sig in \
                ("sync_to_main_menu", "activate_client_mode", \
                "activate_server_mode", "start_client_sync", \
                "start_server_sync")]))
        self.conf = self.config()
        self.get_widget = get_widget = self.w_tree.get_widget
        self.client_progressbar = get_widget("sync_mode_client_progressbar")
        self.server_progressbar = get_widget("sync_mode_server_progressbar")

        widgets_dict = {'sync_mode_client_login_entry': 'client_login', \
            'sync_mode_client_passwd_entry': 'client_passwd', \
            'sync_mode_client_address_entry': 'client_sync_address', \
            'sync_mode_client_port_entry': 'client_sync_port', \
            'sync_mode_server_login_entry': 'server_login', \
            'sync_mode_server_passwd_entry': 'server_passwd', \
            'sync_mode_server_port_entry': 'server_sync_port', \
            'sync_mode_server_address_entry': 'server_sync_address'}
        # Mandatory color setup for GtkEntry
        for widget_name, param_name in widgets_dict.items():
            get_widget(widget_name).set_text(self.conf[param_name])
            widget = get_widget(widget_name)
            widget.modify_base(gtk.STATE_NORMAL, gtk.gdk.color_parse("#FFFFFF"))
            widget.modify_text(gtk.STATE_NORMAL, gtk.gdk.color_parse("#000000"))

    def complete_events(self):
        """Defreeze GTK UI."""

        while gtk.events_pending():
            gtk.main_iteration(False)

    def activate(self):
        """Activate sync mode."""

        self.get_widget("sync_mode_role_switcher").set_current_page(0)
        self.get_widget("sync_toolbar_client_mode_button").set_active(False)
        self.get_widget("sync_toolbar_server_mode_button").set_active(False)

    def activate_client_mode_cb(self, widget):
        """Switches to Client mode."""

        self.get_widget("sync_toolbar_server_mode_button").set_active(False)
        self.get_widget("sync_mode_role_switcher").set_current_page(1)

    def activate_server_mode_cb(self, widget):
        """Switches to Server mode."""

        self.get_widget("sync_toolbar_client_mode_button").set_active(False)
        self.get_widget("sync_mode_role_switcher").set_current_page(2)

    def update_client_progressbar(self, fraction):
        """Updates client progress bar indicator."""

        self.client_progressbar.set_fraction(fraction)
        self.complete_events()

    def update_server_progressbar(self, fraction):
        """Updates server progress bar indicator."""

        self.server_progressbar.set_fraction(fraction)
        self.complete_events()

    def show_message(self, message):
        """Show message from Client or Server."""

        self.main_widget().information_box(message)
        self.complete_events()

    def update_client_status(self, text):
        """Set client status text."""

        status_label = self.get_widget("sync_mode_client_status_label")
        status_label.set_text(text)
        status_label.show()
        self.complete_events()
   
    def update_server_status(self, text):
        """Set server status text."""

        status_label = self.get_widget("sync_mode_server_status_label")
        status_label.set_text(text)
        status_label.show()
        self.complete_events()

    def start_client_sync_cb(self, widget):
        """Starts syncing as Client."""

        if not widget.get_active():
            self.show_or_hide_containers(False, "client")
            login = self.get_widget("sync_mode_client_login_entry").get_text()
            passwd = self.get_widget("sync_mode_client_passwd_entry").get_text()
            host = self.get_widget(\
                "sync_mode_client_address_entry").get_text()
            port = self.get_widget("sync_mode_client_port_entry").get_text()
            uri = host + ':' + port
            if not uri.startswith("http://"):
                uri = "http://" + uri
            messenger = UIMessenger(self.show_message, self.complete_events, \
                self.update_client_status, self.client_progressbar.show, \
                self.update_client_progressbar, self.client_progressbar.hide)
            self.client = Client(host, port, uri, self.database(), \
                self.controller(), self.config(), self.log(), messenger)
            self.client.set_user(login, passwd)
            self.complete_events()
            self.client.start()
            self.show_or_hide_containers(True, "client")
            self.get_widget(\
                "sync_mode_client_start_button").set_active(False)
        else:
            self.show_or_hide_containers(True, "client")
            self.client.stop()
            self.client = None

    def start_server_sync_cb(self, widget):
        """Starts syncing as Server."""

        if not widget.get_active():
            try:
                port = int(self.get_widget(\
                    "sync_mode_server_port_entry").get_text())
            except ValueError:
                self.main_widget().error_box("Wrong port number!")
            else:
                host = self.get_widget(\
                    "sync_mode_server_address_entry").get_text()
                self.show_or_hide_containers(False, "server")
                try:
                    messenger = UIMessenger(self.show_message, \
                    self.complete_events, self.update_server_status, \
                    self.server_progressbar.show, \
                    self.update_server_progressbar, \
                    self.server_progressbar.hide)
                    self.server = Server("%s:%s" % (host, port), \
                    self.database(), self.config(), self.log(), messenger)
                except socket.error, error:
                    self.show_message(str(error))
                else:
                    self.server.set_user(\
                        self.get_widget("sync_mode_server_login_entry"). \
                            get_text(), 
                        self.get_widget("sync_mode_server_passwd_entry"). \
                            get_text())
                    self.server.start()
                self.show_or_hide_containers(True, "server")
                self.get_widget(\
                    "sync_mode_server_start_button").set_active(False)