home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2006 November (DVD) / PCWELT_11_2006.ISO / casper / filesystem.squashfs / usr / bin / fontconfig-voodoo < prev    next >
Encoding:
Text File  |  2006-08-29  |  2.6 KB  |  86 lines

  1. #!/usr/bin/python
  2.  
  3. import os
  4. import sys
  5. from optparse import OptionParser
  6.  
  7. from LanguageSelector import FontConfig
  8. from gettext import gettext as _
  9.  
  10.  
  11. def main():
  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
  23.     parser = OptionParser(usage)
  24.     parser.add_option("-f", "--force", dest="force",
  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"))
  38.     parser.add_option("-c", "--current", dest="show_current",
  39.                       action="store_true",
  40.                       help=_("Show the current fontconfig-voodoo config"))
  41.     parser.add_option("-q", "--quiet",
  42.                       action="store_true", dest="silent", default=False)
  43.  
  44.     # check if we have arguments at all
  45.     if len(sys.argv[1:]) == 0:
  46.         parser.print_help()
  47.         sys.exit(0)
  48.  
  49.     # parse them
  50.     (options, args) = parser.parse_args()
  51.  
  52.     # do the work
  53.     fc = FontConfig.FontConfigHack()
  54.  
  55.     if options.show_current:
  56.         if options.silent:
  57.             print fc.getCurrentConfig()
  58.         else:
  59.             print "Current config: %s" % fc.getCurrentConfig()
  60.         sys.exit(0)
  61.  
  62.     if options.list:
  63.         print "\n".join(fc.getAvailableConfigs())
  64.         sys.exit(0)
  65.         
  66.     if os.path.exists(fc.configFile) and not options.force:
  67.         abort(_("A configuration exists already. Use '--force' to "
  68.                 "overwrite it. "))
  69.  
  70.     if options.auto:
  71.         try:
  72.             fc.setConfigBasedOnLocale()
  73.         except FontConfig.ExceptionNoConfigForLocale:
  74.             fc.setConfig("none")
  75.  
  76.     if options.lang:
  77.         try:
  78.             fc.setConfig(options.lang)
  79.         except FontConfig.ExceptionNoConfigForLocale:
  80.             abort(_("No fontconfig-voodoo configuration found for the "
  81.                     "selected locale"))
  82.     
  83.     
  84. if __name__ == "__main__":
  85.     main()
  86.