示例#1
0
def get_settings_to_apply(attribute_list, user_profile):
	"""
	This function searches for the coresponding attribute values in the
	user profile
	the solution and the appropriate module are allready found 
	attribute_list: is a set and contains the attributes which the choosen
	module holds for configuration
	user_profile: the json style user profile
	returns a dict of the attributes with thair values, extracted from the
	user profile. This dictionary later can be transfered to the setup
	method of the chosen module
	"""
	attr_value_dict = {}
	attr_entry_dict = {}
	log = Logger()
	for attr in attribute_list:
		attr_entry_dict[attr] = []

	# collect all user profile entries which correspond to the attributes
	# in the given list
		for entry in user_profile:
			if attr in entry['name']:
				attr_entry_dict[attr].append(entry)

	# set the values for all attributes, which only have one entry in the
	# user profile
	for attr,entry_list in zip(attr_entry_dict.keys(),attr_entry_dict.values()):
		if len(entry_list) == 0:
			log.log_msg("SettingsToApply: The option " + attr + " was not found in the user profile, no value attached.", "warning")
		elif len(entry_list) == 1:
			attr_value_dict[attr] = entry_list[0]['value']

	entry_without_condition = None
	for attr,entry_list in zip(attr_entry_dict.keys(),attr_entry_dict.values()):
		if len(entry_list) > 1:
			for e in entry_list:
				if e['condition'] == "":
					entry_without_condition = e
				else:
					depents_on = resolve_up_setting_dependencies(e)
					if len(depents_on) == 0:
						continue
					if attr_value_dict.has_key(depents_on[1]) == True:
#						print attr_value_dict[depents_on], " = ", e['value']
						if attr_value_dict[depents_on[1]] == e['condition'][depents_on[0]]:
							attr_value_dict[attr] = e['value']
							break
# if the dependencies couldn't be resolved, use the standard
			# entry without conditions
			if attr_value_dict.has_key(attr) == False:
				if entry_without_condition == None:
					log.log_msg("GetSettingsForAttributeList: Dependencies couldn't be solved and there is no general entry for the " + attr + " option", "warning")
				else:
					attr_value_dict[attr] = entry_without_condition['value']
	return attr_value_dict
示例#2
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
示例#3
0
def print_by_error_code(rc):
	log = Logger()

	### helper class errors
	# 20 - 39
	# speak_msg:
	if rc == 21:
			log.log_msg("SpeakMSG: Audio output of messages currently not available for this os.", "warning")
	elif rc == 22:
		log.log_msg("SpeakMSG: Server for speech production not	available.", "warning")

	###### plugins
	# all error codes above 100
	### orca plugin
	# 100 - 199
	elif rc == 100:
		log.log_msg("Orca: The Orca package could not be found, maybe not available in this distibution", "error", True)
	elif rc == 101:
			log.log_msg("Orca: No admin previleges on this machine, Orca could not be installed.", "error", True)
	elif rc == 102:
		log.log_msg("Orca: Unknown error during Orca installation", "error", True)
	elif rc == 103:
		log.log_msg("Orca: Start of the Orca settings dialog was not successful", "error", True)
	elif rc == 104:
		log.log_msg("Orca: Although the Orca settings dialog ended successfully, there is still no settings file available", "error", True)
	elif rc == 105:
		log.log_msg("Orca: Json File is malformed.", "error", True)
	elif rc == 106:
		log.log_msg("Orca: Settings file couldn't be written", "error", True)

		### NVDA plugin
	# 200 - 299
	elif rc == 200:
		log.log_msg("NVDA: Downloader couldn't be loaded.", "error", True)
	elif rc == 201:
		log.log_msg("NVDA: Installation failed, maybe no admin privileges.", "error", True)
	elif rc == 202:
		log.log_msg("NVDA: Could not exit NVDA", "error", True)
	elif rc == 203:
		log = log_msg("NVDA: Config file not found." "error", True)
	elif rc == 204:
		log.log_msg("NVDA: settings file is malformed.", "error", True)
	elif rc == 205:
		log.log_msg("NVDA: Settings file couldn't be written", "error", True)
	else:
		log.log_msg("Unknown error code: ", "error")
示例#4
0
		print imported_modules[i]()
	print"\n"

	while(1):
		# fetch json profile from server
		# download the profile file
		# the following if statement only belongs to my vm settings, if I
		# start the program under the host, the url is the localhost,
		# otherwise it's the given ip address
		file_name = ""
		if platform.node() == "scimitar":
			file_name =	helper.download_file("http://localhost/cloud4all/profile_json.txt",	True)
		else:
			file_name =	helper.download_file("http://10.0.2.2/cloud4all/profile_json.txt",	True)
		if os.path.exists(file_name) == False:
			log.log_msg("Error: Download of the profile file failed.", "error")
			sys.exit(1)
		f = open(file_name, "r")
		json_string = f.read()
		# parse the string
		try:
			user_profile = json.loads(json_string)
		except ValueError:
			log.log_msg("Error: Parsing of the user profile failed.", "error")
			sys.exit(2)

		dev_profile = DeviceProfile()
		compatible_modules = get_compatible_modules(dev_profile.get_device_profile(), imported_modules)
		c_modules = "compatible: ", compatible_modules
		log.log_msg(c_modules, "debug", False)
		solution_list = get_solutions(user_profile, compatible_modules)
示例#5
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