Beispiel #1
0
 def prepare(self):
     # Determine which Syncthing to use
     suffix, tag = StDownloader.determine_platform()
     # Report error on unsupported platforms
     if suffix is None or tag is None:
         pd = "%s %s %s" % (
             platform.uname()[0],
             platform.uname()[2],  # OS, version
             platform.uname()[4])  # architecture
         self.parent.error(
             self, _("Cannot download Syncthing daemon."),
             _("This platform (%s) is not supported") % (pd, ), False)
         return
     # Determine target file & directory
     self.target = os.path.join(
         os.path.expanduser(StDownloader.get_target_folder()),
         "syncthing%s" % (suffix, ))
     # Create downloader and connect events
     self.sd = StDownloader(self.target, tag)
     self.sd.connect("error", self.on_download_error)
     self.sd.connect("version", self.on_version)
     self.sd.connect("download-progress", self.on_progress)
     self.sd.connect("download-finished", self.on_extract_start)
     self.sd.connect("extraction-progress", self.on_progress)
     self.sd.connect("extraction-finished", self.on_extract_finished)
     # Start downloading
     self.sd.get_version()
Beispiel #2
0
	def prepare(self):
		# Determine which Syncthing to use
		suffix, tag = StDownloader.determine_platform()
		# Report error on unsupported platforms
		if suffix is None or tag is None:
			pd = "%s %s %s" % (
				platform.uname()[0], platform.uname()[2],	# OS, version
				platform.uname()[4])						# architecture
			self.parent.error(self,
				_("Cannot download Syncthing daemon."),
				_("This platform (%s) is not supported") % (pd,),
				False)
			return
		# Determine target file & directory
		self.target = os.path.join(
			os.path.expanduser(StDownloader.get_target_folder()),
			"syncthing%s" % (suffix,)
			)
		# Create downloader and connect events
		self.sd = StDownloader(self.target, tag)
		self.sd.connect("error", self.on_download_error)
		self.sd.connect("version", self.on_version)
		self.sd.connect("download-progress", self.on_progress)
		self.sd.connect("download-finished", self.on_extract_start)
		self.sd.connect("extraction-progress", self.on_progress)
		self.sd.connect("extraction-finished", self.on_extract_finished)
		# Start downloading
		self.sd.get_version()
Beispiel #3
0
 def prepare(self):
     self.paths = ["./"]
     self.paths += [
         os.path.expanduser("~/.local/bin"), self.parent.st_configdir
     ]
     if is_portable():
         self.paths += [".\\data"]
     if StDownloader is None:
         self.binaries = ["syncthing"]
     else:
         suffix, trash = StDownloader.determine_platform()
         self.binaries = ["syncthing", "syncthing%s" % (suffix, )]
         if suffix == "x64":
             # Allow 32bit binary on 64bit
             self.binaries += ["syncthing.x86"]
     if IS_WINDOWS:
         self.paths += [
             "c:/Program Files/syncthing",
             "c:/Program Files (x86)/syncthing", self.parent.st_configdir
         ]
         self.binaries = ("syncthing.exe", )
     if "PATH" in os.environ:
         self.paths += os.environ["PATH"].split(":")
     log.info("Searching for syncthing binary...")
     GLib.idle_add(self.search)
Beispiel #4
0
	def prepare(self):
		self.paths = [ "./" ]
		self.paths += [ os.path.expanduser("~/.local/bin"), self.parent.st_configdir ]
		suffix, trash = StDownloader.determine_platform()
		self.binaries = ["syncthing", "syncthing%s" % (suffix,)]
		if suffix == "x64":
			# Allow 32bit binary on 64bit
			self.binaries += ["syncthing.x86"]
		if IS_WINDOWS:
			self.paths += [ "c:/Program Files/syncthing",
				"c:/Program Files (x86)/syncthing",
				self.parent.st_configdir
				]
			self.binaries = ("syncthing.exe",)
		if "PATH" in os.environ:
			self.paths += os.environ["PATH"].split(":")
		log.info("Searching for syncthing binary...")
		GLib.idle_add(self.search)
	def cb_btDownload_clicked(self, *a):
		"""
		Disable half of dialog and start downloading syncthing package
		"""
		# Determine which syncthing to use
		suffix, tag = StDownloader.determine_platform()
		# Report error on unsupported platforms
		if suffix is None or tag is None:
			# Disable download button
			self["btDownload"].set_sensitive(False)
			# Set message
			pd = "%s %s" % (
				platform.uname()[0],	# OS
				platform.uname()[4])	# architecture
			self["lblDownloadProgress"].set_markup("%s %s" % (
					_("Cannot download Syncthing daemon."),
					_("This platform (%s) is not supported") % (pd,),
				))
			return
		# Determine target file & directory
		self.target = os.path.join(
			os.path.expanduser(StDownloader.get_target_folder()),
			"syncthing%s" % (suffix,)
			)
		# Create downloader and connect events
		sd = StDownloader(self.target, tag)
		sd.connect("error", self.cb_download_error)
		sd.connect("version", self.cb_version)
		sd.connect("download-progress", self.cb_progress)
		sd.connect("download-finished", self.cb_extract_start)
		sd.connect("extraction-progress", self.cb_progress)
		sd.connect("extraction-finished", self.cb_extract_finished)
		# Display message and start downloading
		self["lblDownloadProgress"].set_markup(_("Downloading..."))
		self["btDownload"].set_visible(False)
		self["pbDownload"].set_visible(True)
		self["vsyncthing_binary"].set_sensitive(False)
		self["btBrowse"].set_sensitive(False)
		self["btSave"].set_sensitive(False)
		sd.get_version()
Beispiel #6
0
class DownloadSTPage(Page):
    TYPE = Gtk.AssistantPageType.PROGRESS
    TITLE = _("Download Daemon")

    def init_page(self):
        """ Displayed while wizard downloads and extracts daemon """
        self.label = WrappedLabel(_("<b>Downloading Syncthing daemon.</b>"))
        self.version = WrappedLabel(_("Please wait..."))
        self.pb = Gtk.ProgressBar()
        self.label.props.margin_bottom = 15
        self.target = None
        self.attach(self.label, 0, 0, 1, 1)
        self.attach(self.version, 0, 1, 1, 1)
        self.attach(self.pb, 0, 2, 1, 1)

    def prepare(self):
        # Determine which Syncthing to use
        suffix, tag = StDownloader.determine_platform()
        # Report error on unsupported platforms
        if suffix is None or tag is None:
            pd = "%s %s %s" % (
                platform.uname()[0],
                platform.uname()[2],  # OS, version
                platform.uname()[4])  # architecture
            self.parent.error(
                self, _("Cannot download Syncthing daemon."),
                _("This platform (%s) is not supported") % (pd, ), False)
            return
        # Determine target file & directory
        self.target = os.path.join(
            os.path.expanduser(StDownloader.get_target_folder()),
            "syncthing%s" % (suffix, ))
        # Create downloader and connect events
        self.sd = StDownloader(self.target, tag)
        self.sd.connect("error", self.on_download_error)
        self.sd.connect("version", self.on_version)
        self.sd.connect("download-progress", self.on_progress)
        self.sd.connect("download-finished", self.on_extract_start)
        self.sd.connect("extraction-progress", self.on_progress)
        self.sd.connect("extraction-finished", self.on_extract_finished)
        # Start downloading
        self.sd.get_version()

    def on_download_error(self, downloader, error, message):
        """
		Called when download fails. This is fatal for now, user can
		only observe message, cry and quit program.
		"""
        message = "%s\n%s" % (str(error) if not error is None else "",
                              message if not message is None else "")
        self.parent.error(self,
                          _("Failed to download Syncthing daemon package."),
                          message, False)
        return

    def on_version(self, dowloader, version):
        self.version.set_markup("Downloading %s..." % (version, ))
        dowloader.download()

    def on_extract_start(self, *a):
        self.version.set_markup("Extracting...")

    def on_progress(self, dowloader, progress):
        self.pb.set_fraction(progress)

    def on_extract_finished(self, *a):
        """ Called after extraction is finished """
        # Everything done. Praise supernatural entities...
        self.label.set_markup(_("<b>Download finished.</b>"))
        self.parent.config["syncthing_binary"] = self.target
        self.version.set_markup(_("Binary path:") + " " + self.target)
        self.pb.set_visible(False)
        self.parent.set_page_complete(self, True)
Beispiel #7
0
    def search(self):
        """
		Called repeatedly through GLib.idle_add, until binary is found
		or all possible paths are tried.
		"""
        try:
            path, self.paths = self.paths[0], self.paths[1:]
        except IndexError:
            # Out of possible paths. Not found
            if IS_WINDOWS:
                # On Windows, don't say anything and download Syncthing
                # directly
                self.parent.insert_and_go(DownloadSTPage())
                return False
            else:
                # On Linux, generate and display error page
                from syncthing_gtk.app import MIN_ST_VERSION
                target_folder_link = '<a href="file://%s">%s</a>' % (
                    os.path.expanduser(StDownloader.get_target_folder()),
                    StDownloader.get_target_folder())
                dll_link = '<a href="https://github.com/syncthing/syncthing/releases">' + \
                  _('download latest binary') + '</a>'
                message, title = "", None
                if self.ignored_version == None:
                    # No binary was found
                    title = _("Syncthing daemon not found.")
                    message += _(
                        "Please, use package manager to install the Syncthing package"
                    ) + " "
                    message += _("or %s from Syncthing page and save it to your %s directory.") % \
                       (dll_link, target_folder_link)
                else:
                    # Binary was found, but it was too old to be ussable
                    title = _("Syncthing daemon is too old.")
                    message += _("Syncthing-GTK needs Syncthing daemon %s or newer, but only %s") % \
                      (MIN_ST_VERSION, self.ignored_version) + " "
                    message += _("were found.")
                    message += "\n"
                    message += _(
                        "Please, use package manager to install the Syncthing package"
                    ) + " "
                    message += _("or %s from Syncthing page and save it to your %s directory.") % \
                       (dll_link, target_folder_link)
                message += "\n\n"
                message += _(
                    "Alternatively, Syncthing-GTK can download Syncthing binary"
                ) + " "
                message += _("to %s and keep it up-to-date, but this option is meant as") % \
                   (target_folder_link,) + " "
                message += _("last resort and generally not suggested.")
                page = self.parent.error(self, title, message, False)
                # Attach [ ] Download Syncthing checkbox
                cb = Gtk.CheckButton(_("_Download Syncthing binary"),
                                     use_underline=True)
                cb.connect(
                    "toggled", lambda cb, *a: self.parent.set_page_complete(
                        page, cb.get_active()))
                page.attach(cb, 0, 2, 2, 1)
                # Attach [ ] Autoupdate checkbox
                cb = Gtk.CheckButton(_("Auto_update downloaded binary"),
                                     use_underline=True)
                cb.connect(
                    "toggled", lambda cb, *a: self.parent.config.set(
                        "st_autoupdate", cb.get_active()))
                page.attach(cb, 0, 3, 2, 1)
                page.show_all()
                # Add Download page
                self.parent.insert(DownloadSTPage())
                return

        for bin in self.binaries:
            bin_path = os.path.join(path, bin)
            log.info(" ... %s", bin_path)
            if os.path.isfile(bin_path):
                if os.access(bin_path, os.X_OK):
                    # File exists and is executable, run it and parse
                    # version string from output
                    log.info("Binary found in %s", bin_path)
                    if IS_WINDOWS: bin_path = bin_path.replace("/", "\\")
                    p = DaemonProcess([bin_path, '-version'])
                    p.connect('line', self.cb_process_output)
                    p.connect('exit', self.cb_process_exit)
                    p.connect('failed', self.cb_process_exit)
                    p.start()
                    return False
                else:
                    log.info("Binary in %s is not not executable", bin_path)
        return True
Beispiel #8
0
class DownloadSTPage(Page):
	TYPE = Gtk.AssistantPageType.PROGRESS
	TITLE = _("Download Daemon")
	
	def init_page(self):
		""" Displayed while wizard downloads and extracts daemon """
		self.label = WrappedLabel(_("<b>Downloading Syncthing daemon.</b>"))
		self.version = WrappedLabel(_("Please wait..."))
		self.pb = Gtk.ProgressBar()
		self.label.props.margin_bottom = 15
		self.target = None
		self.attach(self.label,		0, 0, 1, 1)
		self.attach(self.version,	0, 1, 1, 1)
		self.attach(self.pb,		0, 2, 1, 1)
	
	def prepare(self):
		# Determine which Syncthing to use
		suffix, tag = StDownloader.determine_platform()
		# Report error on unsupported platforms
		if suffix is None or tag is None:
			pd = "%s %s %s" % (
				platform.uname()[0], platform.uname()[2],	# OS, version
				platform.uname()[4])						# architecture
			self.parent.error(self,
				_("Cannot download Syncthing daemon."),
				_("This platform (%s) is not supported") % (pd,),
				False)
			return
		# Determine target file & directory
		self.target = os.path.join(
			os.path.expanduser(StDownloader.get_target_folder()),
			"syncthing%s" % (suffix,)
			)
		# Create downloader and connect events
		self.sd = StDownloader(self.target, tag)
		self.sd.connect("error", self.on_download_error)
		self.sd.connect("version", self.on_version)
		self.sd.connect("download-progress", self.on_progress)
		self.sd.connect("download-finished", self.on_extract_start)
		self.sd.connect("extraction-progress", self.on_progress)
		self.sd.connect("extraction-finished", self.on_extract_finished)
		# Start downloading
		self.sd.get_version()
	
	def on_download_error(self, downloader, error, message):
		"""
		Called when download fails. This is fatal for now, user can
		only observe message, cry and quit program.
		"""
		message = "%s\n%s" % (
			str(error) if not error is None else "",
			message if not message is None else ""
			)
		self.parent.error(self,
			_("Failed to download Syncthing daemon package."),
			message, False)
		return
	
	def on_version(self, dowloader, version):
		self.version.set_markup("Downloading %s..." % (version, ))
		dowloader.download()
	
	def on_extract_start(self, *a):
		self.version.set_markup("Extracting...")
	
	def on_progress(self, dowloader, progress):
		self.pb.set_fraction(progress)
	
	def on_extract_finished(self, *a):
		""" Called after extraction is finished """
		# Everything done. Praise supernatural entities...
		self.label.set_markup(_("<b>Download finished.</b>"))
		self.parent.config["syncthing_binary"] = self.target
		self.version.set_markup(_("Binary path:") +
				" " + self.target)
		self.pb.set_visible(False)
		self.parent.set_page_complete(self, True)
Beispiel #9
0
	def search(self):
		"""
		Called repeatedly through GLib.idle_add, until binary is found
		or all possible paths are tried.
		"""
		try:
			path, self.paths = self.paths[0], self.paths[1:]
		except IndexError:
			# Out of possible paths. Not found
			if IS_WINDOWS:
				# On Windows, don't say anything and download Syncthing
				# directly
				self.parent.insert_and_go(DownloadSTPage())
				return False
			elif StDownloader is None:
				# On Linux with updater disabled, generate and
				# display error page
				title = _("Syncthing daemon not found.")
				message = _("Please, use package manager to install the Syncthing package.")
				page = self.parent.error(self, title, message, False)
				page.show_all()
				return False
			else:
				# On Linux with updater generate similar display error
				# and offer download
				from syncthing_gtk.app import MIN_ST_VERSION
				target_folder_link = '<a href="file://%s">%s</a>' % (
						os.path.expanduser(StDownloader.get_target_folder()),
						StDownloader.get_target_folder())
				dll_link = '<a href="https://github.com/syncthing/syncthing/releases">' + \
						_('download latest binary') + '</a>'
				message, title = "", None
				if self.ignored_version == None:
					# No binary was found
					title = _("Syncthing daemon not found.")
					message += _("Please, use package manager to install the Syncthing package") + " "
					message += _("or %s from Syncthing page and save it to your %s directory.") % \
								(dll_link, target_folder_link)
				else:
					# Binary was found, but it was too old to be ussable
					title = _("Syncthing daemon is too old.")
					message += _("Syncthing-GTK needs Syncthing daemon %s or newer, but only %s") % \
							(MIN_ST_VERSION, self.ignored_version) + " "
					message += _("were found.")
					message += "\n"
					message += _("Please, use package manager to install the Syncthing package") + " "
					message += _("or %s from Syncthing page and save it to your %s directory.") % \
								(dll_link, target_folder_link)
				message += "\n\n"
				message += _("Alternatively, Syncthing-GTK can download Syncthing binary") + " "
				message += _("to %s and keep it up-to-date, but this option is meant as") % \
							(target_folder_link,) + " "
				message += _("last resort and generally not suggested.")
				page = self.parent.error(self, title, message, False)
				# Attach [ ] Download Syncthing checkbox
				cb = Gtk.CheckButton(_("_Download Syncthing binary"), use_underline=True)
				cb.connect("toggled", lambda cb, *a : self.parent.set_page_complete(page, cb.get_active()))
				page.attach(cb,	0, 2, 2, 1)
				# Attach [ ] Autoupdate checkbox
				cb = Gtk.CheckButton(_("Auto_update downloaded binary"), use_underline=True)
				cb.connect("toggled", lambda cb, *a : self.parent.config.set("st_autoupdate", cb.get_active()))
				page.attach(cb,	0, 3, 2, 1)
				page.show_all()
				# Add Download page
				self.parent.insert(DownloadSTPage())
				return False
		
		for bin in self.binaries:
			bin_path = os.path.join(path, bin)
			log.info(" ... %s", bin_path)
			if os.path.isfile(bin_path):
				if os.access(bin_path, os.X_OK):
					# File exists and is executable, run it and parse
					# version string from output
					log.info("Binary found in %s", bin_path)
					if IS_WINDOWS: bin_path = bin_path.replace("/", "\\")
					p = DaemonProcess([ bin_path, '-version' ])
					p.connect('line', self.cb_process_output)
					p.connect('exit', self.cb_process_exit)
					p.connect('failed', self.cb_process_exit)
					p.start()
					return False
				else:
					log.info("Binary in %s is not not executable", bin_path)
		return True
Beispiel #10
0
    def cb_btDownload_clicked(self, *a):
        """
		Disable half of dialog and start downloading syncthing package
		"""
        # Determine which syncthing to use
        suffix, tag = StDownloader.determine_platform()
        # Report error on unsupported platforms
        if suffix is None or tag is None:
            # Disable download button
            self["btDownload"].set_sensitive(False)
            # Set message
            pd = "%s %s" % (
                platform.uname()[0],  # OS
                platform.uname()[4])  # architecture
            self["lblDownloadProgress"].set_markup("%s %s" % (
                _("Cannot download Syncthing daemon."),
                _("This platform (%s) is not supported") % (pd, ),
            ))
            return
        # Determine target file & directory
        self.target = os.path.join(
            os.path.expanduser(StDownloader.get_target_folder()),
            "syncthing%s" % (suffix, ))
        # Create downloader and connect events
        sd = StDownloader(self.target, tag)
        sd.connect("error", self.cb_download_error)
        sd.connect("version", self.cb_version)
        sd.connect("download-progress", self.cb_progress)
        sd.connect("download-finished", self.cb_extract_start)
        sd.connect("extraction-progress", self.cb_progress)
        sd.connect("extraction-finished", self.cb_extract_finished)
        # Display message and start downloading
        self["lblDownloadProgress"].set_markup(_("Downloading..."))
        self["btDownload"].set_visible(False)
        self["pbDownload"].set_visible(True)
        self["vsyncthing_binary"].set_sensitive(False)
        self["btBrowse"].set_sensitive(False)
        self["btSave"].set_sensitive(False)
        sd.get_version()
Beispiel #11
0
	def search(self, paths):
		"""
		Called repeatedly through GLib.idle_add, until binary is found
		or all possible paths are tried.
		"""
		try:
			path, paths = paths[0], paths[1:]
		except IndexError:
			# Out of possible paths. Not found
			if IS_WINDOWS:
				# On Windows, don't say anything and download Syncthing
				# directly
				self.parent.insert_and_go(DownloadSTPage())
				return False
			else:
				# On Linux, generate and display error page
				target_folder_link = '<a href="file://%s">%s</a>' % (
						os.path.expanduser(StDownloader.get_target_folder()),
						StDownloader.get_target_folder())
				dll_link = '<a href="https://github.com/syncthing/syncthing/releases">' + \
						_('download latest binary') + '</a>'
				page = self.parent.error(self,
						_("Syncthing daemon not found."),
						(_("Please, use package manager to install the Syncthing package") + " " +
						 _("or %s from Syncthing page and save it to your %s directory.") +
						 "\n\n" +
						 _("Alternatively, Syncthing-GTK can download Syncthing binary "
						   "to %s and keep it up-to-date, but this option is meant as "
						   "last resort and generally not suggested.")
						 ) % (dll_link, target_folder_link, target_folder_link), +
						False)
				# Attach [ ] Download Syncthing checkbox
				cb = Gtk.CheckButton(_("_Download Syncthing binary"), use_underline=True)
				cb.connect("toggled", lambda cb, *a : self.parent.set_page_complete(page, cb.get_active()))
				page.attach(cb,	0, 2, 2, 1)
				# Attach [ ] Autoupdate checkbox
				cb = Gtk.CheckButton(_("Auto_update downloaded binary"), use_underline=True)
				cb.connect("toggled", lambda cb, *a : self.parent.config.set("st_autoupdate", cb.get_active()))
				page.attach(cb,	0, 3, 2, 1)
				page.show_all()
				# Add Download page
				self.parent.insert(DownloadSTPage())
				return
		
		for bin in self.binaries:
			bin_path = os.path.join(path, bin)
			print " ...", bin_path,
			if os.path.isfile(bin_path):
				if os.access(bin_path, os.X_OK):
					# File exists and is executable
					print "FOUND"
					if IS_WINDOWS: bin_path = bin_path.replace("/", "\\")
					self.parent.config["syncthing_binary"] = bin_path
					if not can_upgrade_binary(bin_path):
						# Don't try enable auto-update if binary is in
						# non-writable location (auto-update is enabled
						# by default on Windows only)
						self.parent.config["st_autoupdate"] = False
					self.parent.set_page_complete(self, True)
					self.label.set_markup(
							_("<b>Syncthing daemon binary found.</b>") +
							"\n\n" +
							_("Binary path:") +
							" " +
							bin_path
						)
					return
				else:
					print "not executable"
			else:
				print "not found"
		GLib.idle_add(self.search, paths)