rpms/scim/FC-3 update-xinput-scim,NONE,1.1 scim.spec,1.10,1.11

Ryo Dairiki (ryo) fedora-extras-commits at redhat.com
Mon Aug 1 05:03:06 UTC 2005


Author: ryo

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

Modified Files:
	scim.spec 
Added Files:
	update-xinput-scim 
Log Message:
sync with FC-4 branch



--- NEW FILE update-xinput-scim ---
#!/usr/bin/python

# please someone put good comments on this script.

import os, sys, re

alternatives_bin = "/usr/sbin/alternatives"
locale_bin = "locale"
readlink_bin = "readlink"
rpm_bin = "rpm"

sysconf_dir = "/etc"
alternatives_dir = sysconf_dir + "/alternatives"
xinput_dir = sysconf_dir + "/X11/xinit/xinput.d"
xinput_scim = xinput_dir + "/scim"

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]$")
xinput_locale_pattern = re.compile("^xinput-[a-z][a-z]$|^xinput-[a-z][a-z]_[A-Z][A-Z]$")
xinput_current_link_pattern = re.compile("link\s+currently\s+points\s+to\s+(%s/\w+)" %xinput_dir)
xinput_link_pattern = re.compile("(%s/\w+)\s+-\s+priority\s\d+" %xinput_dir)

script_name = "update-xinput-scim"
white_space = "    "
usage_message = "Usage: \n\n" + \
				"  %s install LANG [PRIORITY]\n" %script_name + \
				"  %s to install xinput file for LANG with the PRIORITY.\n\n" %white_space + \
				"  %s remove LANG\n" %script_name + \
				"  %s to remove xinput file for LANG\n" %white_space + \
				"  %s  only if there is no other IMEngine for LANG in SCIM.\n" %white_space + \
				"  %s This will switch IM from SCIM\n" %white_space + \
				"  %s  if there is no more SCIM IMEngine for this LANG.\n\n" %white_space + \
				"  %s list\n" %script_name + \
				"  %s to list LANG which currently uses SCIM.\n\n" %white_space + \
				"  %s dump\n" %script_name + \
				"  %s to dump all locales with xinput entries for SCIM.\n\n" %white_space + \
				"  %s help\n" %script_name + \
				"  %s to show this instruction.\n" %white_space
read_help_message = "Try \'%s help\' for more information." %script_name
authorization_rejected_message = script_name + ": you must be root to run this script"
invalid_locale_message = script_name + ": invalid locale" + "\n" + read_help_message
too_few_arguments_message = script_name + ": too few arguments" + "\n" + read_help_message
too_much_arguments_message = script_name + ": too much arguments" + "\n" + read_help_message
unknown_command_message = script_name + ": unknown command"

# FIXME
authorization_rejected_returncode = 1
invalid_locale_returncode = 2
too_few_arguments_returncode = 3
unknown_command_returncode = 4

locales = []


def check_authorization():
	uid = os.getuid()
	if uid != 0:
		print authorization_rejected_message
		sys.exit(authorization_rejected_returncode)


def load_locales():
	(fi, fo) = os.popen2(locale_bin + " --all")
	for locale in fo:
		locale = locale.strip()
		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()


def check_locale(locale):
	if len(locales) == 0:
		load_locales()
	if not locale in locales:
		print invalid_locale_message + " :" + locale
		sys.exit(invalid_locale_returncode)


def readlink(xinput_locale):
	current_link = None
	(fi, fo) = os.popen2("LANG=C;" + alternatives_bin + " --display " + xinput_locale)
	for line in fo:
		current_links = xinput_current_link_pattern.findall(line)
		if len(current_links) > 0:
			current_link = current_links[0]
			break
	fi.close()
	fo.close()
	return current_link


def dumplinks(xinput_locale):
	links = []
	(fi, fo) = os.popen2("LANG=C;" + alternatives_bin + " --display " + xinput_locale)
	for line in fo:
		links_in_line = xinput_link_pattern.findall(line)
		links += links_in_line
	fi.close()
	fo.close()
	return links


def install(locale, priority):
	check_locale(locale)
	if priority == -1:
		priority = default_priority
	xinput_locale = "xinput-" + locale
	os.system(alternatives_bin + " --install %s/%s %s " %(xinput_dir, locale, xinput_locale) + xinput_scim + " %s" %priority)
	

def remove(locale):
	check_locale(locale)
	scim_locale = "scim-" + locale
	xinput_locale = "xinput-" + locale
	(fi, fo) = os.popen2(rpm_bin + " -q --whatprovides " + scim_locale + " 2>/dev/null | wc -l")
	input_method_count = int(fo.readline())
	fi.close()
	fo.close()
	if input_method_count <= 1:
		# there is no more input method for this locale
		os.system(alternatives_bin + " --remove " + xinput_locale + " " + xinput_scim)
		# check the current input method
		current_xinput = readlink(xinput_locale)
		if current_xinput == xinput_scim:
			# 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:
		current_xinput = readlink(xinput_locale)
		if current_xinput == xinput_scim:
			locale = xinput_locale[7:]
			print(locale)


def dump():
	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:
		links_for_locale = dumplinks(xinput_locale)
		for link in links_for_locale:
			if link == xinput_scim:
				locale = xinput_locale[7:]
				print(locale)


# FIXME
def main():
	args = sys.argv
	if len(args) == 1:
		print too_few_arguments_message
		sys.exit(too_few_arguments_returncode)
	command = args[1]
	if command.startswith("--"):
		command = command[2:]
	if command == "install":
		if len(args) < 3:
			print too_few_arguments_message
			sys.exit(too_few_arguments_returncode)
		locale = args[2]
		if len(args) == 4:
			priority = args[3]
		elif len(args) > 4:
			print too_much_arguments_message
			sys.exit(too_much_arguments_returncode)
		else:
			priority = -1
		install(locale, priority)
	elif command == "remove":
		if len(args) < 3:
			print too_few_arguments_message
			sys.exit(too_few_arguments_returncode)
		elif len(args) > 3:
			print too_much_arguments_message
			sys.exit(too_much_arguments_returncode)
		locale = args[2]
		remove(locale)
	elif command == "list":
		list()
	elif command == "dump":
		dump()
	elif command == "help":
		print usage_message
		sys.exit(0)
	else:
		print unknown_command_message + ": " + args[1]
		print read_help_message
		sys.exit(unknown_command_returncode)
	

# main
check_authorization()
main()


Index: scim.spec
===================================================================
RCS file: /cvs/extras/rpms/scim/FC-3/scim.spec,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- scim.spec	30 Jul 2005 06:13:06 -0000	1.10
+++ scim.spec	1 Aug 2005 05:03:04 -0000	1.11
@@ -1,7 +1,7 @@
 Name:      scim
 Version:   1.4.0
 # must be less than the release number of scim in Core
-Release:   2.2%{?dist}
+Release:   2.3%{?dist}
 Summary:   Smart Common Input Method platform
 
 License:   LGPL
@@ -9,6 +9,7 @@
 URL:       http://www.scim-im.org/
 Source0:   http://dl.sourceforge.net/sourceforge/scim/%{name}-%{version}.tar.gz
 Source1:   xinput-scim
+Source2:   update-xinput-scim
 BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
 
 PreReq:    %{_bindir}/update-gtk-immodules
@@ -72,6 +73,9 @@
 mkdir -pm 755 ${RPM_BUILD_ROOT}/%{_sysconfdir}/X11/xinit/xinput.d
 install -pm 644 %{SOURCE1} ${RPM_BUILD_ROOT}/%{_sysconfdir}/X11/xinit/xinput.d/scim
 
+# install update-xinput-scim script.
+install -pm 755 %{SOURCE2} ${RPM_BUILD_ROOT}/%{_libdir}/scim-1.0/update-xinput-scim
+
 %find_lang %{name}
 
 
@@ -118,6 +122,9 @@
 
 
 %changelog
+* Sat Jul 30 2005 Ryo Dairiki <ryo-dairiki at mbm.nifty.com> - 1.4.0-2.3
+- add update-xinput-scim
+
 * Sat Jul 30 2005 Ryo Dairiki <ryo-dairiki at mbm.nifty.com> - 1.4.0-2.2
 - disable ld-version-script, which used to enabled due to broken configure file
 




More information about the scm-commits mailing list