rpms/scim/FC-4 update-xinput-scim,1.1,1.2

Ryo Dairiki (ryo) fedora-extras-commits at redhat.com
Sun Jul 31 04:23:23 UTC 2005


Author: ryo

Update of /cvs/extras/rpms/scim/FC-4
In directory cvs-int.fedora.redhat.com:/tmp/cvs-serv16839

Modified Files:
	update-xinput-scim 
Log Message:
fix some bug of update-xinput-scim script



Index: update-xinput-scim
===================================================================
RCS file: /cvs/extras/rpms/scim/FC-4/update-xinput-scim,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- update-xinput-scim	30 Jul 2005 14:28:59 -0000	1.1
+++ update-xinput-scim	31 Jul 2005 04:23:21 -0000	1.2
@@ -17,19 +17,20 @@
 default_priority = 85
 
 # FIXME I'm not sure if this is correct
-valid_locale_pattern = re.compile("^[a-z][a-z]_[A-Z][A-Z]$")
+valid_locale_pattern = re.compile("^([a-z][a-z])_[A-Z][A-Z]$")
+xinput_locale_pattern = re.compile("^xinput-[a-z][a-z]$|^xinput-[a-z][a-z]_[A-Z][A-Z]$")
 
 script_name = "update-scim-locale"
 authorization_rejected_message = script_name + ": you must be root to run this script"
 invalid_locale_message = script_name + ": invalid locale"
 too_few_arguments_message = script_name + ": too few arguments"
-unknwon_command_message = script_name + ": unknown command"
+unknown_command_message = script_name + ": unknown command"
 
 # FIXME
 authorization_rejected_returncode = 1
 invalid_locale_returncode = 2
 too_few_arguments_returncode = 3
-unknwon_command_returncode = 4
+unknown_command_returncode = 4
 
 locales = []
 
@@ -44,9 +45,15 @@
 	(fi, fo) = os.popen2(locale_bin + " --all")
 	for locale in fo:
 		locale = locale.strip()
-		if valid_locale_pattern.match(locale) and not locale in locales:
-			locales.append(locale)
-
+		matches = valid_locale_pattern.match(locale)
+		if matches:
+			lang_group = matches.group(1)
+			if lang_group in locales:
+				if not locale in locales:
+					locales.append(locale)
+			else:
+				locales.append(lang_group)
+				locales.append(locale)
 	fi.close()
 	fo.close()
 
@@ -59,7 +66,7 @@
 		sys.exit(invalid_locale_returncode)
 
 
-def install_alternative(locale, priority):
+def install(locale, priority):
 	check_locale(locale)
 	if priority == -1:
 		priority = default_priority
@@ -67,7 +74,7 @@
 	os.system(alternatives_bin + " --install %s/%s %s " %(xinput_dir, locale, xinput_locale) + xinput_scim + " %s" %priority)
 	
 
-def remove_alternative(locale):
+def remove(locale):
 	check_locale(locale)
 	scim_locale = "scim-" + locale
 	xinput_locale = "xinput-" + locale
@@ -80,14 +87,30 @@
 		os.system(alternatives_bin + " --remove " + xinput_locale + " " + xinput_scim)
 		# check the current input method
 		(fi, fo) = os.popen2(readlink_bin + " %s/%s" %(alternatives_dir, xinput_locale))
-		current_xinput = fo.readline()
+		current_xinput = fo.readline().strip()
 		fi.close()
 		fo.close()
 		if current_xinput == xinput_scim:
-			# change the input method, as scim won't support this locale anymore.
+			# change the input method, as scim won't support this locale anymore
 			os.system(alternatives_bin + " --auto " + xinput_locale)
 
 
+def list():
+	xinput_locales = []
+	alternatives = os.listdir(alternatives_dir)
+	for alternative in alternatives:
+		if xinput_locale_pattern.match(alternative):
+			xinput_locales.append(alternative)
+	for xinput_locale in xinput_locales:
+		(fi, fo) = os.popen2(readlink_bin + " %s/%s" %(alternatives_dir, xinput_locale))
+		current_xinput = fo.readline().strip()
+		fi.close()
+		fo.close()
+		if current_xinput == xinput_scim:
+			locale = xinput_locale[7:]
+			print(locale)
+
+
 # FIXME
 def main():
 	args = sys.argv
@@ -103,16 +126,18 @@
 			priority = args[3]
 		else:
 			priority = -1
-		install_alternative(locale, priority)
+		install(locale, priority)
 	elif args[1] == "remove":
 		if len(args) < 3:
 			print too_few_arguments_message
 			sys.exit(too_few_arguments_returncode)
 		locale = args[2]
-		remove_alternative(locale)
+		remove(locale)
+	elif args[1] == "list":
+		list()
 	else:
 		print unknown_command_message + ": " + args[1]
-		sys.exit(unknwon_command_returncode)
+		sys.exit(unknown_command_returncode)
 	
 
 # main




More information about the fedora-extras-commits mailing list