def _read_config(self): # Read syncthing config to get connection url if not self._configxml: self._configxml = os.path.join(get_config_dir(), "syncthing", "config.xml") if not os.path.exists(self._configxml) and os.path.exists(os.path.expanduser("~/snap/syncthing/common/syncthing")): # Special case for syncthing in snap package self._configxml = os.path.expanduser("~/snap/syncthing/common/syncthing/config.xml") try: log.debug("Reading syncthing config %s", self._configxml) with open(self._configxml, "r") as f: config = f.read() except Exception as e: raise InvalidConfigurationException("Failed to read daemon configuration: %s" % e) try: xml = minidom.parseString(config) except Exception as e: raise InvalidConfigurationException("Failed to parse daemon configuration: %s" % e) tls = "false" try: tls = xml.getElementsByTagName("configuration")[0] \ .getElementsByTagName("gui")[0].getAttribute("tls") except Exception as e: pass self._tls = False self._cert = None if tls.lower() == "true": self._tls = True try: self._cert = Gio.TlsCertificate.new_from_file( os.path.join(get_config_dir(), "syncthing", "https-cert.pem")) except Exception as e: log.exception(e) raise TLSErrorException("Failed to load daemon certificate") try: self._address = xml.getElementsByTagName("configuration")[0] \ .getElementsByTagName("gui")[0] \ .getElementsByTagName("address")[0] \ .firstChild.nodeValue if self._address.startswith("0.0.0.0"): addr, port = self._address.split(":", 1) self._address = "127.0.0.1:%s" % (port,) log.debug("WebUI listens on 0.0.0.0, connecting to 127.0.0.1 instead") except Exception as e: log.exception(e) raise InvalidConfigurationException("Required configuration node not found in daemon config file") try: self._api_key = xml.getElementsByTagName("configuration")[0] \ .getElementsByTagName("gui")[0] \ .getElementsByTagName("apikey")[0] \ .firstChild.nodeValue except Exception as e: # API key can be none pass
def _read_config(self): # Read syncthing config to get connection url configxml = os.path.join(get_config_dir(), "syncthing", "config.xml") try: config = file(configxml, "r").read() except Exception, e: raise InvalidConfigurationException("Failed to read daemon configuration: %s" % e)
def __init__(self, gladepath="/usr/share/syncthing-gtk", iconpath="/usr/share/syncthing-gtk/icons", config=None): # Init Gtk.Assistant.__init__(self) if not config is None: self.config = config else: self.config = Configuration() self.gladepath = gladepath self.iconpath = iconpath self.syncthing_options = {} self.lines = [] # Daemon and wizard output, # maybe for error reports self.finished = False self.connect("prepare", self.prepare_page) # Find syncthing configuration directory self.st_configdir = os.path.join(get_config_dir(), "syncthing") self.st_configfile = os.path.join(get_config_dir(), "syncthing", "config.xml") # Window setup self.set_position(Gtk.WindowPosition.CENTER) self.set_size_request(720, -1) self.set_default_size(720, 300) self.set_deletable(True) if IS_WINDOWS: self.set_icon_list([ GdkPixbuf.Pixbuf.new_from_file( "icons/32x32/apps/syncthing-gtk.png") ]) else: self.set_icon_name("syncthing-gtk") self.set_title("%s %s" % (_("Syncthing-GTK"), _("First run wizard"))) # Add "Quit" button self.quit_button = Gtk.Button.new_from_stock("gtk-quit") self.add_action_widget(self.quit_button) self.quit_button.set_visible(True) self.quit_button.connect("clicked", lambda *a: self.emit("cancel")) # Pages self.add_page(IntroPage(self)) self.add_page(FindDaemonPage()) self.add_page(GenerateKeysPage()) self.add_page(HttpSettingsPage()) self.add_page(SaveSettingsPage()) self.add_page(LastPage())
def start(self): if not self.proc is None: self.proc.kill() if len(self.watched_ids) > 0: self.proc = DaemonProcess( [exe, "-home", os.path.join(get_config_dir(), "syncthing"), "-folders", ",".join(self.watched_ids)] ) self.proc.connect("exit", self._on_exit) self.proc.connect("failed", self._on_failed) log.info("Starting syncthing-inotify for %s" % (",".join(self.watched_ids))) self.proc.start()
def _read_config(self): # Read syncthing config to get connection url if not self._configxml: self._configxml = os.path.join(get_config_dir(), "syncthing", "config.xml") if not os.path.exists(self._configxml) and os.path.exists(os.path.expanduser("~/snap/syncthing/common/syncthing")): # Special case for syncthing in snap package self._configxml = os.path.expanduser("~/snap/syncthing/common/syncthing/config.xml") try: log.debug("Reading syncthing config %s", self._configxml) config = file(self._configxml, "r").read() except Exception, e: raise InvalidConfigurationException("Failed to read daemon configuration: %s" % e)
def __init__(self, gladepath="/usr/share/syncthing-gtk", iconpath="/usr/share/syncthing-gtk/icons", config=None): # Init Gtk.Assistant.__init__(self) if not config is None: self.config = config else: self.config = Configuration() self.gladepath = gladepath self.iconpath = iconpath self.syncthing_options = {} self.lines = [] # Daemon and wizard output, # maybe for error reports self.finished = False self.connect("prepare", self.prepare_page) # Find syncthing configuration directory self.st_configdir = os.path.join(get_config_dir(), "syncthing") self.st_configfile = os.path.join(get_config_dir(), "syncthing", "config.xml") # Window setup self.set_position(Gtk.WindowPosition.CENTER) self.set_size_request(720, -1) self.set_default_size(720, 300) self.set_deletable(True) if IS_WINDOWS: self.set_icon_list([GdkPixbuf.Pixbuf.new_from_file("icons/32x32/apps/syncthing-gtk.png")]) else: self.set_icon_name("syncthing-gtk") self.set_title("%s %s" % (_("Syncthing-GTK"), _("First run wizard"))) # Add "Quit" button self.quit_button = Gtk.Button.new_from_stock("gtk-quit") self.add_action_widget(self.quit_button) self.quit_button.set_visible(True) self.quit_button.connect("clicked", lambda *a : self.emit("cancel")) # Pages self.add_page(IntroPage()) self.add_page(FindDaemonPage()) self.add_page(GenerateKeysPage()) self.add_page(HttpSettingsPage()) self.add_page(SaveSettingsPage()) self.add_page(LastPage())
def start(self): if not self.proc is None: self.proc.kill() if len(self.watched_ids) > 0: self.proc = DaemonProcess([ exe, "-home", os.path.join(get_config_dir(), "syncthing"), "-folders", ",".join(self.watched_ids) ]) self.proc.connect("exit", self._on_exit) self.proc.connect("failed", self._on_failed) log.info("Starting syncthing-inotify for %s" % (",".join(self.watched_ids))) self.proc.start()
def get_target_folder(*a): """ Returns target directory where Syncthing binary will be downloaded. That's %APPDATA%/syncthing on Windows or one of ~/bin, ~/.bin or ~/.local/bin, whatever already exists. If none of folders are existing on Linux, ~/.local/bin will be created. Path will contain ~ on Linux and needs to be expanded. """ if IS_WINDOWS: return os.path.join(get_config_dir(), "syncthing") for p in ("~/bin", "~/.bin"): if os.path.exists(os.path.expanduser(p)): return p return "~/.local/bin"
def browse_for_binary(parent_window, settings_dialog, value): """ Display file browser dialog to browse for syncthing binary. Used here and by FindDaemonDialog as well. """ # Prepare dialog d = Gtk.FileChooserDialog( _("Browse for Syncthing binary"), parent_window, Gtk.FileChooserAction.OPEN, (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_OK, Gtk.ResponseType.OK)) # Prepare filter f = Gtk.FileFilter() if IS_WINDOWS: f.set_name("Executables") f.add_pattern("*.exe") else: f.set_name("Binaries") f.add_mime_type("application/x-executable") f.add_mime_type("application/x-shellscript") d.add_filter(f) # Set default path confdir = os.path.join(get_config_dir(), "syncthing") prevvalue = str(settings_dialog[value].get_text()).strip() if prevvalue and os.path.exists(os.path.split(prevvalue)[0]): d.set_current_folder(os.path.split(prevvalue)[0]) elif os.path.exists(confdir): d.set_current_folder(confdir) elif IS_WINDOWS: if "CommonProgramFiles" in os.environ: d.set_current_folder(os.environ["CommonProgramFiles"]) elif os.path.exists("C:\\Program Files"): d.set_current_folder("C:\\Program Files") # Else nothing, just start whatever you like else: d.set_current_folder("/usr/bin") # Get response if d.run() == Gtk.ResponseType.OK: settings_dialog[value].set_text(d.get_filename()) d.destroy()
def browse_for_binary(parent_window, settings_dialog, value): """ Display file browser dialog to browse for syncthing binary. Used here and by FindDaemonDialog as well. """ # Prepare dialog d = Gtk.FileChooserDialog(_("Browse for Syncthing binary"), parent_window, Gtk.FileChooserAction.OPEN, (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_OK, Gtk.ResponseType.OK)) # Prepare filter f = Gtk.FileFilter() if IS_WINDOWS: f.set_name("Executables") f.add_pattern("*.exe") else: f.set_name("Binaries") f.add_mime_type("application/x-executable") f.add_mime_type("application/x-shellscript") d.add_filter(f) # Set default path confdir = os.path.join(get_config_dir(), "syncthing") prevvalue = str(settings_dialog[value].get_text()).strip() if prevvalue and os.path.exists(os.path.split(prevvalue)[0]): d.set_current_folder(os.path.split(prevvalue)[0]) elif os.path.exists(confdir): d.set_current_folder(confdir) elif IS_WINDOWS: if "CommonProgramFiles" in os.environ: d.set_current_folder(os.environ["CommonProgramFiles"]) elif os.path.exists("C:\\Program Files"): d.set_current_folder("C:\\Program Files") # Else nothing, just start whatever you like else: d.set_current_folder("/usr/bin") # Get response if d.run() == Gtk.ResponseType.OK: settings_dialog[value].set_text(d.get_filename()) d.destroy()
xml = minidom.parseString(config) except Exception, e: raise InvalidConfigurationException("Failed to parse daemon configuration: %s" % e) tls = "false" try: tls = xml.getElementsByTagName("configuration")[0] \ .getElementsByTagName("gui")[0].getAttribute("tls") except Exception, e: pass self._tls = False self._cert = None if tls.lower() == "true": self._tls = True try: self._cert = Gio.TlsCertificate.new_from_file( os.path.join(get_config_dir(), "syncthing", "https-cert.pem")) except Exception, e: log.exception(e) raise TLSErrorException("Failed to load daemon certificate") try: self._address = xml.getElementsByTagName("configuration")[0] \ .getElementsByTagName("gui")[0] \ .getElementsByTagName("address")[0] \ .firstChild.nodeValue if self._address.startswith("0.0.0.0"): addr, port = self._address.split(":", 1) self._address = "127.0.0.1:%s" % (port,) log.debug("WebUI listens on 0.0.0.0, connecting to 127.0.0.1 instead") except Exception, e: log.exception(e) raise InvalidConfigurationException("Required configuration node not found in daemon config file")
def get_config_dir(self): return os.path.join(get_config_dir(), "syncthing-gtk")