예제 #1
0
	def setup(self, solution_name, settings):
		log = Logger()
		# check if nvda is allready installed on the system, if not, install it
		standard_nvda_path = "C:\\Programme\\NVDA\\nvda.exe"
		nvda_path = helper.is_process_running("nvda.exe")
		if nvda_path == "":
			nvda_path = standard_nvda_path
		
		if os.path.exists(nvda_path) == False:
			# nvda download url
			url = "http://downloads.sourceforge.net/project/nvda/releases/2012.2.1/nvda_2012.2.1.exe"
			# download nvda installer
			nvda_installer = helper.download_file(url)
			if nvda_installer == "":
				return 200
			# install nvda
			rc = subprocess.call([nvda_installer, "--install"])
			if rc > 0:
				return 201
		# if nvda runs, exit it
		nvda_path = helper.is_process_running("nvda.exe")
		if nvda_path != "":
			rc = subprocess.call([nvda_path, "-q"])
			if rc > 0:
				return 202
		else:
			nvda_path = standard_nvda_path
		
		# configure the program and start it
		config_file = os.environ['APPDATA'] + "\\nvda\\nvda.ini"
		if os.path.exists(config_file) == False:
			return 203
	
		# parse the ini config file
		try:
			config = ConfigObj(config_file)
		except configobj.ParseError:
			return 204


		# apply the settings
		attrs_without_value = []
		for attr in self.get_solution_list()[solution_name]:
			if settings.has_key(attr) == True:
				value = self.convert_values(attr, settings[attr])
				if value == None:
					log.log_msg("NVDA: The attribute " + attr + " couldn't be converted into a NVDA specific format, skipped", "warning")
					continue
				if attr == "preferred-lang":
					try:
						config['speech']['espeak']['voice'] = value['voice']
					except:
						log.log_msg("NVDA: Error while changing the attribute " + attr + " in the NVDA settings file.", "warning")
				if attr == "speech-rate":
					try:
						config['speech']['espeak']['rate'] = value['rate']
						config['speech']['espeak']['rateBoost'] = value['rateBoost']
					except:
						log.log_msg("NVDA: Error while changing the attribute " + attr + " in the NVDA settings file.", "warning")
			else:
				attrs_without_value.append(attr)

		# list of attributes without a corresponding value
		if len(attrs_without_value) > 0:
			attr_str = ""
			for attr in attrs_without_value:
				attr_str.join(attr)
			log.log_msg("NVDA: The following supported attributes have no value in the user profile: " + attr_str, "warning")

		# write back the nvda settings file
		try:
			config.write()
		except:
			return 205

		# start configured nvda
		rc = os.popen(nvda_path)
#		rc = os.system(nvda_path + " &")
		print "start nvda, rc = ", rc
		return 0
예제 #2
0
	def setup(self, solution_name, settings):
		log = Logger()
		# first check if orca is installed
		orca_path = string.split(subprocess.check_output(["whereis", "orca"]), " ")
		if len(orca_path) <= 1:
			helper.speak_msg("Orca is not installed. I try to do this.  Please enter your sudo password in the following dialog.")
			print "Orca is not installed. I try to do this. Please enter your sudo password in the following dialog."
			while True:
				rc = subprocess.call(["sudo", "apt-get", "-y", "install", "gnome-orca", "speech-dispatcher"])
				if rc == 0:
					log.log_msg("Orca successfully installed.", "info", True)
					orca_path = string.split(subprocess.check_output(["whereis", "orca"]), " ")
					break
				if rc == 100:
					return 100
				if rc == 1:
					helper.speak_msg("Wrong password. Do you want to try again?	y/n")
					out = raw_input('Wrong password. Do you want to try again?	y/n: ')
					if out == "n":
						return 101
					else:
						continue
				return 102

		# next try to locate orca settings file		
		orca_settings_filename = os.environ['HOME'] + "/.local/share/orca/user-settings.conf"
		if os.path.exists(orca_settings_filename) == False:
			rc = subprocess.call([orca_path[1], "-t"])
			if rc > 0:
				return 103
			if os.path.exists(orca_settings_filename) == False:
				return 104
		orca_settings_file = open(orca_settings_filename,"r")
		orca_settings_string = orca_settings_file.read()
		try:
			orca_settings_json = json.loads(orca_settings_string, object_pairs_hook=collections.OrderedDict)
		except ValueError:
			return 105
		orca_settings_file.close()

		profile_name = "cloud4all"
		if orca_settings_json['profiles'].has_key(profile_name) == False:
			new_speech_profile = orca_settings_json['profiles']['default']
			orca_settings_json['profiles'][profile_name] = new_speech_profile
			orca_settings_file = open(orca_settings_filename,"w")
			orca_settings_file.write(json.dumps(orca_settings_json, sort_keys=False, indent=4))
			orca_settings_file.close()
			orca_settings_file = open(orca_settings_filename,"r")
			orca_settings_string = orca_settings_file.read()
			orca_settings_json = json.loads(orca_settings_string, object_pairs_hook=collections.OrderedDict)
			orca_settings_file.close()

		# general profile settings
		orca_settings_json['profiles'][profile_name]['profile'][0] = "Cloud4All"
		orca_settings_json['profiles'][profile_name]['profile'][1] = profile_name
		# make Cloud4All profile the active profile
		orca_settings_json['general']['startingProfile'][0] = "Cloud4All"
		orca_settings_json['general']['startingProfile'][1] = profile_name

		# apply user profile settings
		attrs_without_value = []
		for attr in self.get_solution_list()[solution_name]:
			if settings.has_key(attr) == True:
				value = self.convert_values(attr, settings[attr])
				if value == None:
					log.log_msg("Orca: The attribute " + attr + " couldn't be converted into a Orca specific format, skipped", "warning")
					continue
				if attr == "preferred-lang":
					try:
						orca_settings_json['profiles'][profile_name]['voices']['default']['family']['name'] = value['name']
						orca_settings_json['profiles'][profile_name]['voices']['default']['family']['locale'] = value['locale']
					except:
						log.log_msg("Orca: Error while changing the attribute " + attr + " in the Orca settings file.", "warning")
				if attr == "speech-rate":
					try:
						orca_settings_json['profiles'][profile_name]['voices']['default']['rate'] = value['rate']
					except:
						log.log_msg("Orca: Error while changing the attribute " + attr + " in the Orca settings file.", "warning")
			else:
				attrs_without_value.append(attr)

		# list of attributes without a corresponding value
		if len(attrs_without_value) > 0:
			attr_str = ""
			for attr in attrs_without_value:
				attr_str.join(attr)
			log.log_msg("Orca: The following supported attributes have no value in the user profile: " + attr_str, "warning")

		# write back the orca settings file
		try:
			orca_settings_file = open(orca_settings_filename,"w")
			orca_settings_file.write(json.dumps(orca_settings_json, sort_keys=False, indent=4))
			orca_settings_file.close()
		except:
			return 106


		if helper.is_process_running("orca") != "":
			rc = subprocess.call([orca_path[1], "-q"])
		os.system(orca_path[1] + " &")
		return 0