home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Linux / Linux Mint 3.0 Light / LinuxMint-3.0-Light.iso / casper / filesystem.squashfs / usr / sbin / gconf-schemas < prev    next >
Encoding:
Text File  |  2007-03-06  |  1.9 KB  |  72 lines

  1. #! /usr/bin/python
  2. #
  3. # copyright (c) 2006 Josselin Mouette <joss@debian.org>
  4. # Licensed under the GNU Lesser General Public License, version 2.1
  5. # See COPYING for details
  6.  
  7. from optparse import OptionParser
  8. import sys,os,os.path,shutil,tempfile
  9.  
  10. parser = OptionParser(usage="usage: %prog --[un]register file1.schemas [file2.schemas [...]]")
  11.  
  12. parser.add_option("--register", action="store_true", dest="register",
  13.                   help="register schemas to the GConf database",
  14.           default=None)
  15. parser.add_option("--unregister", action="store_false", dest="register",
  16.                   help="unregister schemas from the GConf database",
  17.           default=None)
  18.  
  19. (options, args) = parser.parse_args()
  20.  
  21. if options.register==None:
  22.   parser.error("You need to specify --register or --unregister.")
  23.  
  24. schema_location="/usr/share/gconf/schemas"
  25.  
  26. schemas = [ ]
  27. for schema in args:
  28.   if not os.path.isabs(schema):
  29.     schema=os.path.join(schema_location,schema)
  30.   if os.path.isfile(schema):
  31.     schemas.append(schema)
  32.   else:
  33.     sys.stderr.write('Warning: %s could not be found.\n'%schema)
  34.  
  35. if len(schemas)<1:
  36.   parser.error("You need to give at least a file to (un)register.")
  37.  
  38. if os.geteuid():
  39.   parser.error("You must be root to launch this program.")
  40.  
  41. tmp_home=tempfile.mkdtemp(prefix='gconf-')
  42. env={'HOME': tmp_home,
  43.      'GCONF_CONFIG_SOURCE': 'xml:readwrite:/var/lib/gconf/defaults'}
  44. if options.register:
  45.   arg='--makefile-install-rule'
  46. else:
  47.   arg='--makefile-uninstall-rule'
  48.  
  49. save_stdout=os.dup(1)
  50. os.close(1)
  51. res=os.spawnvpe(os.P_WAIT,'gconftool-2',['gconftool-2',arg]+schemas,env)
  52. os.dup2(save_stdout,1)
  53. os.close(save_stdout)
  54.  
  55. shutil.rmtree(tmp_home)
  56.  
  57. if(res):
  58.   sys.exit(res)
  59.  
  60. if options.register:
  61.   # tell running processes to re-read the GConf database
  62.   import signal
  63.   try:
  64.     pids=os.popen('pidof gconfd-2').readlines()[0].split()
  65.     for pid in pids:
  66.       try:
  67.         os.kill(int(pid),signal.SIGHUP)
  68.       except OSError:
  69.         pass
  70.   except IndexError:
  71.     pass
  72.