rpms/scim/FC-4 update-xinput-scim,NONE,1.1 scim.spec,1.12,1.13

Ryo Dairiki (ryo) fedora-extras-commits at redhat.com
Sat Jul 30 14:29:02 UTC 2005


Author: ryo

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

Modified Files:
	scim.spec 
Added Files:
	update-xinput-scim 
Log Message:
Import update-xinput-scim



--- 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]$")

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"

# FIXME
authorization_rejected_returncode = 1
invalid_locale_returncode = 2
too_few_arguments_returncode = 3
unknwon_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()
		if valid_locale_pattern.match(locale) and not locale in locales:
			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 install_alternative(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_alternative(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
		(fi, fo) = os.popen2(readlink_bin + " %s/%s" %(alternatives_dir, xinput_locale))
		current_xinput = fo.readline()
		fi.close()
		fo.close()
		if current_xinput == xinput_scim:
			# change the input method, as scim won't support this locale anymore.
			os.system(alternatives_bin + " --auto " + xinput_locale)


# FIXME
def main():
	args = sys.argv
	if len(args) == 1:
		print too_few_arguments_message
		sys.exit(too_few_arguments_returncode)
	if args[1] == "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]
		else:
			priority = -1
		install_alternative(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)
	else:
		print unknown_command_message + ": " + args[1]
		sys.exit(unknwon_command_returncode)
	

# main
check_authorization()
main()


Index: scim.spec
===================================================================
RCS file: /cvs/extras/rpms/scim/FC-4/scim.spec,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- scim.spec	30 Jul 2005 06:12:22 -0000	1.12
+++ scim.spec	30 Jul 2005 14:28:59 -0000	1.13
@@ -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 644 ${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