Example #1
0
def version_0_x_0_to_0_7_0():
    """
    First version to upgrade configuration. This is the version where
    multiple device support was introduced, pushing configuration into 
    sub-directories
    """
    macros_dir = os.path.join(g15globals.user_config_dir, "macro_profiles")
    if os.path.exists(os.path.join(macros_dir,  "0.macros")):
        logger.info("Upgrading macros and configuration to 0.7.x format")
        
        """
        If the default macro profile exists at the root of the macro_profiles directory,
        then conversion hasn't yet occurred. So, copy all profiles into all device
        sub-directories
        """
        devices = g15devices.find_all_devices()
        for file in os.listdir(macros_dir):
            if file.endswith(".macros"):
                profile_file = os.path.join(macros_dir, file)
                for device in devices:
                    device_dir = os.path.join(macros_dir, device.uid)
                    if not os.path.exists(device_dir):
                        logger.info("Creating macro_profile directory for %s", device.uid)
                        os.mkdir(device_dir)
                    logger.info("Copying macro_profile %s to %s ", file, device.uid)
                    shutil.copyfile(profile_file, os.path.join(device_dir, file))
                os.remove(profile_file)
                
        """
        Copy the GConf folders. 
        """
        gconf_dir = os.path.expanduser("~/.gconf/apps/gnome15")
        gconf_file = os.path.join(gconf_dir, "%gconf.xml")
        gconf_plugins_dir = os.path.join(gconf_dir, "plugins")
        for device in devices:
            device_dir = os.path.join(gconf_dir, device.uid)
            if not os.path.exists(device_dir):
                logger.info("Creating GConf directory for %s", device.uid)
                os.mkdir(device_dir)
            logger.info("Copying settings %s to %s", gconf_file, device.uid)
            shutil.copyfile(gconf_file, os.path.join(device_dir, "%gconf.xml"))
            logger.info("Copying plugin settings %s to %s", gconf_plugins_dir, device.uid)
            target_plugins_path = os.path.join(device_dir, "plugins")
            if not os.path.exists(target_plugins_path):
                shutil.copytree(gconf_plugins_dir, target_plugins_path )
        logger.info("Clearing current settings root")
        shutil.rmtree(gconf_plugins_dir)
        f = open(gconf_file, 'w')
        try:
            f.write('<?xml version="1.0">\n')
            f.write('<gconf>\n')
            f.write('</gconf>\n')
        finally:
            f.close()
        
            
        """
        Tell GConf to reload it caches by finding it's process ID and sending it
        SIGHUP
        """
        if sys.version_info > (2, 6):
            process_info = subprocess.check_output(["sh", "-c", "ps -U %d|grep gconfd|head -1" % os.getuid()])
        else:
            import commands
            process_info = commands.getstatusoutput("sh -c \"ps -U %d|grep gconfd|head -1\"" % os.getuid()) 
        if process_info:
            pid = g15pythonlang.split_args(process_info)[0]
            logger.info("Sending process %s SIGHUP", pid)
            subprocess.check_call([ "kill", "-SIGHUP", pid ])
Example #2
0
def split_args(args):
    return g15pythonlang.split_args(args)