~ubuntu-branches/ubuntu/oneiric/language-selector/oneiric

8 by Michael Vogt
* po/fi.po: added Finnish translation (thanks to Timo Jyrinki)
1
#!/usr/bin/python
2
3
import os
9 by Michael Vogt
* fontconfig/ko_KR: new version from the ubuntu-ko team (thanks!)
4
import sys
8 by Michael Vogt
* po/fi.po: added Finnish translation (thanks to Timo Jyrinki)
5
from optparse import OptionParser
6
7
from LanguageSelector import FontConfig
9 by Michael Vogt
* fontconfig/ko_KR: new version from the ubuntu-ko team (thanks!)
8
from gettext import gettext as _
8 by Michael Vogt
* po/fi.po: added Finnish translation (thanks to Timo Jyrinki)
9
10
11
def main():
9 by Michael Vogt
* fontconfig/ko_KR: new version from the ubuntu-ko team (thanks!)
12
    
13
    def abort(msg=None):
14
        " helper for a clean abort "
15
        if not options.silent:
16
            if msg:
17
                print msg
18
            print _("Aborting")
19
        sys.exit(1)
20
21
    usage = "usage: %prog [options]"
22
    # init the option parser
8 by Michael Vogt
* po/fi.po: added Finnish translation (thanks to Timo Jyrinki)
23
    parser = OptionParser(usage)
24
    parser.add_option("-f", "--force", dest="force",
9 by Michael Vogt
* fontconfig/ko_KR: new version from the ubuntu-ko team (thanks!)
25
                      action="store_true",
26
                      help=_("Force even when a configuration exists"))
27
    parser.add_option("-s", "--set", dest="lang",
28
                      help=_("Set fontconfig voodoo for the selected "
29
                             "language"))
30
    parser.add_option("-a", "--auto", dest="auto",
31
                      action="store_true",
32
                      help=_("Guess a configuration based on the "
33
                             "LANGUAGE environment. Sets the config to "
34
                             "'none' if nothing suitable was found"))
35
    parser.add_option("-l", "--list", dest="list",
36
                      action="store_true",
37
                      help=_("List the available fontconfig-voodoo configs"))
13 by Michael Vogt
* fontconfig/ja_JP: updated to the latest version from Jun Kobayashi
38
    parser.add_option("-c", "--current", dest="show_current",
39
                      action="store_true",
40
                      help=_("Show the current fontconfig-voodoo config"))
39 by Michael Vogt, Michael Vogt, Arne Goetje
[ Michael Vogt ]
41
    parser.add_option("-r", "--remove-current", dest="remove_current",
42
                      action="store_true",
43
                      help=_("Remove the current fontconfig-voodoo config"))
9 by Michael Vogt
* fontconfig/ko_KR: new version from the ubuntu-ko team (thanks!)
44
    parser.add_option("-q", "--quiet",
45
                      action="store_true", dest="silent", default=False)
46
13 by Michael Vogt
* fontconfig/ja_JP: updated to the latest version from Jun Kobayashi
47
    # check if we have arguments at all
48
    if len(sys.argv[1:]) == 0:
49
        parser.print_help()
50
        sys.exit(0)
51
52
    # parse them
8 by Michael Vogt
* po/fi.po: added Finnish translation (thanks to Timo Jyrinki)
53
    (options, args) = parser.parse_args()
9 by Michael Vogt
* fontconfig/ko_KR: new version from the ubuntu-ko team (thanks!)
54
55
    # do the work
8 by Michael Vogt
* po/fi.po: added Finnish translation (thanks to Timo Jyrinki)
56
    fc = FontConfig.FontConfigHack()
9 by Michael Vogt
* fontconfig/ko_KR: new version from the ubuntu-ko team (thanks!)
57
13 by Michael Vogt
* fontconfig/ja_JP: updated to the latest version from Jun Kobayashi
58
    if options.show_current:
25 by Michael Vogt
* LanguageSelector/LangCache.py:
59
        try:
60
            if options.silent:
61
                print fc.getCurrentConfig()
62
            else:
63
                print "Current config: %s" % fc.getCurrentConfig()
64
        except FontConfig.ExceptionUnconfigured:
65
            print _("Unconfigured")
13 by Michael Vogt
* fontconfig/ja_JP: updated to the latest version from Jun Kobayashi
66
        sys.exit(0)
67
9 by Michael Vogt
* fontconfig/ko_KR: new version from the ubuntu-ko team (thanks!)
68
    if options.list:
69
        print "\n".join(fc.getAvailableConfigs())
70
        sys.exit(0)
71
        
121 by Martin Pitt, Gunnar Hjalmarsson, Martin Pitt
[ Gunnar Hjalmarsson ]
72
    if options.remove_current:
73
        fc.removeConfig()
74
        sys.exit(0)
75
39 by Michael Vogt, Michael Vogt, Arne Goetje
[ Michael Vogt ]
76
    if not options.force:
77
        try:
78
            fc.getCurrentConfig()
79
            # if this does not raise a "Unconfigured" exception, we
80
            # abort here
81
            abort(_("A configuration exists already. Use '--force' to "
82
                    "overwrite it. "))
83
        except FontConfig.ExceptionUnconfigured:
84
            pass
9 by Michael Vogt
* fontconfig/ko_KR: new version from the ubuntu-ko team (thanks!)
85
86
    if options.auto:
87
        try:
88
            fc.setConfigBasedOnLocale()
89
        except FontConfig.ExceptionNoConfigForLocale:
121 by Martin Pitt, Gunnar Hjalmarsson, Martin Pitt
[ Gunnar Hjalmarsson ]
90
            abort(_("No fontconfig-voodoo configuration found for the "
91
                    "current LANGUAGE"))
39 by Michael Vogt, Michael Vogt, Arne Goetje
[ Michael Vogt ]
92
9 by Michael Vogt
* fontconfig/ko_KR: new version from the ubuntu-ko team (thanks!)
93
    if options.lang:
94
        try:
95
            fc.setConfig(options.lang)
96
        except FontConfig.ExceptionNoConfigForLocale:
97
            abort(_("No fontconfig-voodoo configuration found for the "
98
                    "selected locale"))
39 by Michael Vogt, Michael Vogt, Arne Goetje
[ Michael Vogt ]
99
8 by Michael Vogt
* po/fi.po: added Finnish translation (thanks to Timo Jyrinki)
100
    
101
if __name__ == "__main__":
102
    main()