Пример #1
0
	def _cb_read_latest(self, f, result, buffer, *a):
		# Extract release version from response
		from syncthing_gtk.app import MIN_ST_VERSION
		latest_ver = None
		try:
			success, data, etag = f.load_contents_finish(result)
			if not success: raise Exception("Gio download failed")
			# Go over all available versions until compatibile one
			# is found
			data = json.loads(data)
			for release in data:
				version = release["tag_name"]
				if latest_ver is None:
					latest_ver = version
				if compare_version(self.latest_compat, version) and (self.forced or compare_version(version, MIN_ST_VERSION)):
					# Compatibile
					log.verbose("STDownloader: Found compatibile Syncthing version: %s", version)
					self.version = version
					for asset in release["assets"]:
						if self.platform in asset["name"]:
							self.dll_url = asset["browser_download_url"]
							self.dll_size = int(asset["size"])
							log.debug("STDownloader: URL: %s", self.dll_url)
							break
					break
				else:
					log.verbose("STDownloader: Ignoring too new Syncthing version: %s", version)
			del f
			if self.dll_url is None:
				raise Exception("No release to download")
		except Exception, e:
			log.exception(e)
			self.emit("error", e,
				_("Failed to determine latest Syncthing version."))
			return
Пример #2
0
    def _cb_read_compatibility(self, f, result, buffer, *a):
        # Extract compatibility info from version tags in response
        from syncthing_gtk.app import INTERNAL_VERSION
        try:
            success, data, etag = f.load_contents_finish(result)
            if not success: raise Exception("Gio download failed")
            data = json.loads(data)
            tags_by_commit = {}
            commits_by_version = {}
            # Go over all tags and store them in form that is
            # easier to work with
            for tag in data:
                name = tag["ref"].split("/")[-1]
                sha = tag["object"]["sha"]
                if name.startswith("v"):
                    commits_by_version[name] = sha
                if not sha in tags_by_commit:
                    tags_by_commit[sha] = []
                tags_by_commit[sha].append(name)

            # Determine last Syncthing-GTK version that is not newer
            # than INTERNAL_VERSION and last Syncthing release supported
            # by it
            for version in sorted(commits_by_version.keys()):
                if not compare_version(INTERNAL_VERSION, version):
                    # Newer than internal
                    log.verbose(
                        "STDownloader: Ignoring newer Syncthing-GTK version %s",
                        version)
                else:
                    for tag in tags_by_commit[commits_by_version[version]]:
                        if tag.startswith("Syncthing_"):
                            # ST-GTK version has ST version attached.
                            # Check if this is newer than last known
                            # compatible version
                            st_ver = tag.split("_")[-1]
                            if compare_version(st_ver, self.latest_compat):
                                log.verbose(
                                    "STDownloader: Got newer compatible Syncthing version %s",
                                    st_ver)
                                self.latest_compat = st_ver

            log.verbose(
                "STDownloader: Latest compatible Syncthing version: %s",
                self.latest_compat)

        except Exception as e:
            log.exception(e)
            self.emit("error", e,
                      _("Failed to determine latest Syncthing version."))
            return

        # After latest compatible ST version is determined, determine
        # latest actually existing version. This should be usually same,
        # but checking is better than downloading non-existant file.
        uri = StDownloader.ST_URL
        f = Gio.File.new_for_uri(uri)
        f.load_contents_async(None, self._cb_read_latest, None)
Пример #3
0
	def _cb_read_compatibility(self, f, result, buffer, *a):
		# Extract compatibility info from version tags in response
		from syncthing_gtk.app import INTERNAL_VERSION
		try:
			success, data, etag = f.load_contents_finish(result)
			if not success: raise Exception("Gio download failed")
			data = json.loads(data)
			tags_by_commit = {}
			commits_by_version = {}
			# Go over all tags and store them in form that is
			# easier to work with
			for tag in data:
				name = tag["ref"].split("/")[-1]
				sha = tag["object"]["sha"]
				if name.startswith("v"):
					commits_by_version[name] = sha
				if not sha in tags_by_commit:
					tags_by_commit[sha] = []
				tags_by_commit[sha].append(name)

			# Determine last Syncthing-GTK version that is not newer
			# than INTERNAL_VERSION and last Syncthing release supported
			# by it
			for version in sorted(commits_by_version.keys()):
				if not compare_version(INTERNAL_VERSION, version):
					# Newer than internal
					log.verbose("STDownloader: Ignoring newer Syncthing-GTK version %s", version)
				else:
					for tag in tags_by_commit[commits_by_version[version]]:
						if tag.startswith("Syncthing_"):
							# ST-GTK version has ST version attached.
							# Check if this is newer than last known
							# compatible version
							st_ver = tag.split("_")[-1]
							if compare_version(st_ver, self.latest_compat):
								log.verbose("STDownloader: Got newer compatible Syncthing version %s", st_ver)
								self.latest_compat = st_ver

			log.verbose("STDownloader: Latest compatible Syncthing version: %s", self.latest_compat)

		except Exception as e:
			log.exception(e)
			self.emit("error", e,
				_("Failed to determine latest Syncthing version."))
			return

		# After latest compatible ST version is determined, determine
		# latest actually existing version. This should be usually same,
		# but checking is better than downloading non-existant file.
		uri = StDownloader.ST_URL
		f = Gio.File.new_for_uri(uri)
		f.load_contents_async(None, self._cb_read_latest, None)
Пример #4
0
 def _cb_read_latest(self, f, result, buffer, *a):
     # Extract release version from response
     from syncthing_gtk.app import MIN_ST_VERSION
     latest_ver = None
     try:
         success, data, etag = f.load_contents_finish(result)
         if not success: raise Exception("Gio download failed")
         # Go over all available versions until compatible one
         # is found
         data = json.loads(data)
         for release in data:
             version = release["tag_name"]
             if latest_ver is None:
                 latest_ver = version
             if compare_version(self.latest_compat, version) and (
                     self.forced
                     or compare_version(version, MIN_ST_VERSION)):
                 # compatible
                 log.verbose(
                     "STDownloader: Found compatible Syncthing version: %s",
                     version)
                 self.version = version
                 for asset in release["assets"]:
                     if self.platform in asset["name"]:
                         self.dll_url = asset["browser_download_url"]
                         self.dll_size = int(asset["size"])
                         log.debug("STDownloader: URL: %s", self.dll_url)
                         break
                 break
             else:
                 log.verbose(
                     "STDownloader: Ignoring too new Syncthing version: %s",
                     version)
         del f
         if self.dll_url is None:
             raise Exception("No release to download")
     except Exception as e:
         log.exception(e)
         self.emit("error", e,
                   _("Failed to determine latest Syncthing version."))
         return
     # Check if latest version is not larger than latest supported
     if latest_ver != self.version:
         log.info(
             "Not using latest, unsupported Syncthing version %s; Using %s instead",
             latest_ver, self.version)
     # Everything is done, emit version signal
     self.emit("version", self.version)
Пример #5
0
	def _syncthing_cb_config_error(self, exception, command):
		self.cancel_all()
		if isinstance(exception, GLib.GError):
			if exception.code in (0, 39, 34, 45):	# Connection Refused / Cannot connect to destination
				# It usualy means that daemon is not yet fully started or not running at all.
				epoch = self._epoch
				self.emit("connection-error", Daemon.REFUSED, exception.message, exception)
				if epoch == self._epoch:
					self.timer("config", self._refresh_interval, self._rest_request, "system/config", self._syncthing_cb_config, self._syncthing_cb_config_error)
				return
		elif isinstance(exception, HTTPAuthException):
			self.emit("connection-error", Daemon.NOT_AUTHORIZED, exception.message, exception)
			return
		elif isinstance(exception, HTTPCode):
			# HTTP 404 may acually mean old daemon version
			version = get_header(exception.headers, "X-Syncthing-Version")
			if version != None and not compare_version(version, MIN_VERSION):
				self._epoch += 1
				msg = "daemon is too old"
				self.emit("connection-error", Daemon.OLD_VERSION, msg, Exception(msg))
			else:
				self.emit("connection-error", Daemon.UNKNOWN, exception.message, exception)
			return
		elif isinstance(exception, TLSUnsupportedException):
			self.emit("connection-error", Daemon.TLS_UNSUPPORTED, exception.message, exception)
			return
		elif isinstance(exception, ConnectionRestarted):
			# Happens on Windows. Just try again.
			GLib.idle_add(self._request_config)
			return
		elif isinstance(exception, TLSUnsupportedException):
			self.emit("connection-error", Daemon.TLS_UNSUPPORTED, exception.message, exception)
			return
		self.emit("connection-error", Daemon.UNKNOWN, exception.message, exception)
Пример #6
0
	def cb_process_exit(self, process, *a):
		""" Called after daemon binary outputs version and exits """
		from syncthing_gtk.app import MIN_ST_VERSION
		bin_path = process.get_commandline()[0]
		if compare_version(self.version_string, MIN_ST_VERSION):
			# Daemon binary exists, is executable and meets
			# version requirements. That's good, btw.
			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 + "\n" +
					_("Version:") + " " + self.version_string
				)
		else:
			# Found daemon binary too old to be ussable.
			# Just ignore it and try to find better one.
			log.info("Binary in %s is too old", bin_path)
			self.ignored_version = self.version_string
			GLib.idle_add(self.search)
Пример #7
0
	def _syncthing_cb_config_error(self, exception, command):
		self.cancel_all()
		if isinstance(exception, GLib.GError):
			if exception.code in (0, 39, 34):	# Connection Refused / Cannot connect to destination
				# It usualy means that daemon is not yet fully started or not running at all.
				epoch = self._epoch
				self.emit("connection-error", Daemon.REFUSED, exception.message, exception)
				if epoch == self._epoch:
					self.timer("config", self._refresh_interval, self._rest_request, "system/config", self._syncthing_cb_config, self._syncthing_cb_config_error)
				return
		elif isinstance(exception, HTTPAuthException):
			self.emit("connection-error", Daemon.NOT_AUTHORIZED, exception.message, exception)
			return
		elif isinstance(exception, HTTPCode):
			# HTTP 404 may acually mean old daemon version
			version = get_header(exception.headers, "X-Syncthing-Version")
			if version != None and not compare_version(version, MIN_VERSION):
				self._epoch += 1
				msg = "daemon is too old"
				self.emit("connection-error", Daemon.OLD_VERSION, msg, Exception(msg))
			else:
				self.emit("connection-error", Daemon.UNKNOWN, exception.message, exception)
			return
		elif isinstance(exception, TLSUnsupportedException):
			self.emit("connection-error", Daemon.TLS_UNSUPPORTED, exception.message, exception)
			return
		elif isinstance(exception, ConnectionRestarted):
			# Happens on Windows. Just try again.
			GLib.idle_add(self._request_config)
			return
		elif isinstance(exception, TLSUnsupportedException):
			self.emit("connection-error", Daemon.TLS_UNSUPPORTED, exception.message, exception)
			return
		self.emit("connection-error", Daemon.UNKNOWN, exception.message, exception)
Пример #8
0
	def _cb_read_latest(self, f, result, buffer, *a):
		# Extract release version from response
		latest_ver = None
		try:
			success, data, etag = f.load_contents_finish(result)
			if not success: raise Exception("Gio download failed")
			# Go over all available versions until compatibile one
			# is found
			data = json.loads(data)
			for release in data:
				version = release["tag_name"]
				if latest_ver is None:
					latest_ver = version
				if compare_version(self.latest_compat, version):
					# Compatibile
					log.verbose("STDownloader: Found compatibile Syncthing version: %s", version)
					self.version = version
					for asset in release["assets"]:
						if self.platform in asset["name"]:
							self.dll_url = asset["browser_download_url"]
							self.dll_size = int(asset["size"])
							log.debug("STDownloader: URL: %s", self.dll_url)
							break
					break
				else:
					log.verbose("STDownloader: Ignoring too new Syncthing version: %s", version)
			del f
			if self.dll_url is None:
				raise Exception("No release to download")
		except Exception, e:
			log.exception(e)
			self.emit("error", e,
				_("Failed to determine latest Syncthing version."))
			return
Пример #9
0
	def cb_process_exit(self, process, *a):
		""" Called after daemon binary outputs version and exits """
		from syncthing_gtk.app import MIN_ST_VERSION
		bin_path = process.get_commandline()[0]
		if compare_version(self.version_string, MIN_ST_VERSION):
			# Daemon binary exists, is executable and meets
			# version requirements. That's good, btw.
			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 + "\n" +
					_("Version:") + " " + self.version_string
				)
		else:
			# Found daemon binary too old to be ussable.
			# Just ignore it and try to find better one.
			log.info("Binary in %s is too old", bin_path)
			self.ignored_version = self.version_string
			GLib.idle_add(self.search)
Пример #10
0
	def _cb_read_latest(self, f, result, buffer, *a):
		# Extract release version from response
		latest_ver = None
		try:
			success, data, etag = f.load_contents_finish(result)
			if not success: raise Exception("Gio download failed")
			# Go over all available versions until compatibile one
			# is found
			data = json.loads(data)
			for release in data:
				version = release["tag_name"]
				if latest_ver is None:
					latest_ver = version
				if compare_version(self.latest_compat, version):
					# Compatibile
					if DEBUG: print "STDownloader: Found compatibile Syncthing version:", version
					self.version = version
					for asset in release["assets"]:
						if self.platform in asset["name"]:
							self.dll_url = asset["browser_download_url"]
							self.dll_size = int(asset["size"])
							break
					break
				else:
					if DEBUG: print "STDownloader: Ignoring too new Syncthing version:", version
			del f
			if self.dll_url is None:
				raise Exception("No release to download")
		except Exception, e:
			print >>sys.stderr, traceback.format_exc()
			self.emit("error", e,
				_("Failed to determine latest Syncthing version."))
			return
Пример #11
0
	def _cb_read_compatibility(self, f, result, buffer, *a):
		# Extract compatibility info from version tags in response
		from syncthing_gtk.app import INTERNAL_VERSION
		try:
			success, data, etag = f.load_contents_finish(result)
			if not success: raise Exception("Gio download failed")
			data = json.loads(data)
			tags_by_commit = {}
			commits_by_version = {}
			# Go over all tags and store them in form that is
			# easier to work with
			for tag in data:
				name = tag["name"]
				sha = tag["commit"]["sha"]
				if name.startswith("v"):
					commits_by_version[name] = sha
				if not sha in tags_by_commit:
					tags_by_commit[sha] = []
				tags_by_commit[sha].append(name)
			
			# Determine last Syncthing-GTK version that is not newer
			# than INTERNAL_VERSION and last Syncthing release supported
			# by it
			for version in sorted(commits_by_version.keys()):
				if not compare_version(INTERNAL_VERSION, version):
					# Newer than internal
					if DEBUG:
						print "STDownloader: Ignoring newer Syncthing-GTK version", version
				else:
					for tag in tags_by_commit[commits_by_version[version]]:
						if tag.startswith("Syncthing_"):
							# ST-GTK version has ST version attached.
							# Check if this is newer than last known
							# compatibile version
							st_ver = tag.split("_")[-1]
							if compare_version(st_ver, self.latest_compat):
								if DEBUG:
									print "STDownloader: Got newer compatibile Syncthing version", st_ver
								self.latest_compat = st_ver
			
			if DEBUG: print "STDownloader: Latest compatibile Syncthing version:", self.latest_compat
		
		except Exception, e:
			print >>sys.stderr, traceback.format_exc()
			self.emit("error", e,
				_("Failed to determine latest Syncthing version."))
			return
Пример #12
0
	def _syncthing_cb_version_known(self, version):
		"""
		Called when version is recieved from daemon, either by
		calling /rest/version or from X-Syncthing-Version header.
		"""
		if not compare_version(version, MIN_VERSION):
			# Syncting version too low. Cancel everything and report error
			self.cancel_all()
			self._epoch += 1
			self.emit("connection-error", Daemon.OLD_VERSION, "", None)
			return
		if self._my_id != None:
			device = self._get_device_data(self._my_id)
			if version != device["ClientVersion"]:
				device["ClientVersion"] = version
				self.emit("device-data-changed", self._my_id, 
					None,
					device["ClientVersion"],
					device["inbps"], device["outbps"],
					device["InBytesTotal"], device["OutBytesTotal"])
Пример #13
0
	def _syncthing_cb_version_known(self, version):
		"""
		Called when version is recieved from daemon, either by
		calling /rest/version or from X-Syncthing-Version header.
		"""
		if not compare_version(version, MIN_VERSION):
			# Syncting version too low. Cancel everything and report error
			self.cancel_all()
			self._epoch += 1
			msg = "daemon is too old"
			self.emit("connection-error", Daemon.OLD_VERSION, msg, Exception(msg))
			return
		if self._my_id != None:
			device = self._get_device_data(self._my_id)
			if version != device["clientVersion"]:
				device["clientVersion"] = version
				self.emit("device-data-changed", self._my_id, 
					None,
					device["clientVersion"],
					device["inbps"], device["outbps"],
					device["inBytesTotal"], device["outBytesTotal"])