Author: ryo
Update of /cvs/extras/rpms/scim/FC-4
In directory cvs-int.fedora.redhat.com:/tmp/cvs-serv18163
Modified Files:
update-xinput-scim
Log Message:
few more fixes on the script, and add the instruction
Index: update-xinput-scim
===================================================================
RCS file: /cvs/extras/rpms/scim/FC-4/update-xinput-scim,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- update-xinput-scim 31 Jul 2005 04:23:21 -0000 1.2
+++ update-xinput-scim 31 Jul 2005 05:45:36 -0000 1.3
@@ -19,11 +19,30 @@
# 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-scim-locale"
+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"
-too_few_arguments_message = script_name + ": too few arguments"
+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
@@ -34,6 +53,7 @@
locales = []
+
def check_authorization():
uid = os.getuid()
if uid != 0:
@@ -66,6 +86,30 @@
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:
@@ -86,10 +130,7 @@
# 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().strip()
- fi.close()
- fo.close()
+ 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)
@@ -102,41 +143,67 @@
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()
+ 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)
- if args[1] == "install":
+ 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:
+ 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 args[1] == "remove":
+ 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 args[1] == "list":
+ 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)
Show replies by date