def uninstall_kmp_shared(packageID): """ Uninstall a kmp from /usr/local/share/keyman Args: packageID (str): Keyboard package ID """ kbdir = os.path.join('/usr/local/share/keyman', packageID) if not os.path.isdir(kbdir): logging.error("Keyboard directory for %s does not exist. Aborting", packageID) exit(3) kbdocdir = os.path.join('/usr/local/share/doc/keyman', packageID) kbfontdir = os.path.join('/usr/local/share/fonts/keyman', packageID) logging.info("Uninstalling shared keyboard: %s", packageID) if not os.access( kbdir, os.X_OK | os.W_OK): # Check for write access of keyman dir logging.error( "You do not have permissions to uninstall the keyboard files. You need to run this with `sudo`" ) exit(3) if os.path.isdir(kbdocdir): if not os.access( kbdocdir, os.X_OK | os.W_OK): # Check for write access of keyman doc dir logging.error( "You do not have permissions to uninstall the documentation. You need to run this with `sudo`" ) exit(3) rmtree(kbdocdir) logging.info("Removed documentation directory: %s", kbdocdir) else: logging.info("No documentation directory") if os.path.isdir(kbfontdir): if not os.access(kbfontdir, os.X_OK | os.W_OK): # Check for write access of keyman fonts logging.error( "You do not have permissions to uninstall the font files. You need to run this with `sudo`" ) exit(3) rmtree(kbfontdir) logging.info("Removed font directory: %s", kbfontdir) else: logging.info("No font directory") # need to uninstall from ibus for all lang and all kmx in kmp info, system, options, keyboards, files = get_metadata(kbdir) if keyboards: if is_gnome_shell(): uninstall_keyboards_from_gnome(keyboards, kbdir) else: uninstall_keyboards_from_ibus(keyboards, kbdir) else: logging.warning("could not uninstall keyboards") rmtree(kbdir) logging.info("Removed keyman directory: %s", kbdir) logging.info("Finished uninstalling shared keyboard: %s", packageID)
def uninstall_kmp_user(packageID): """ Uninstall a kmp from ~/.local/share/keyman Args: packageID (str): Keyboard package ID """ kbdir = user_keyboard_dir(packageID) if not os.path.isdir(kbdir): logging.error("Keyboard directory for %s does not exist. Aborting", packageID) exit(3) logging.info("Uninstalling local keyboard: %s", packageID) info, system, options, keyboards, files = get_metadata(kbdir) if keyboards: if is_gnome_shell(): uninstall_keyboards_from_gnome(keyboards, kbdir) else: uninstall_keyboards_from_ibus(keyboards, kbdir) else: logging.warning("could not uninstall keyboards") rmtree(kbdir) logging.info("Removed user keyman directory: %s", kbdir) fontdir = os.path.join(user_keyman_font_dir(), packageID) if os.path.isdir(fontdir): rmtree(fontdir) logging.info("Removed user keyman font directory: %s", fontdir) logging.info("Finished uninstalling local keyboard: %s", packageID)
def install_kmp_user(inputfile, online=False): packageID = extract_package_id(inputfile) packageDir=user_keyboard_dir(packageID) if not os.path.isdir(packageDir): os.makedirs(packageDir) extract_kmp(inputfile, packageDir) #restart IBus so it knows about the keyboards being installed restart_ibus() info, system, options, keyboards, files = get_metadata(packageDir) if keyboards: logging.info("Installing %s", info['name']['description']) if online: process_keyboard_data(packageID, packageDir) if len(keyboards) > 1: for kb in keyboards: if kb['id'] != packageID: process_keyboard_data(kb['id'], packageDir) for f in files: fpath = os.path.join(packageDir, f['name']) ftype = f['type'] if ftype == KMFileTypes.KM_FONT: #Special handling of font to hard link it into font dir fontsdir = os.path.join(user_keyman_font_dir(), packageID) if not os.path.isdir(fontsdir): os.makedirs(fontsdir) os.link(fpath, os.path.join(fontsdir, f['name'])) logging.info("Installing %s as font", f['name']) elif ftype == KMFileTypes.KM_OSK: # Special handling to convert kvk into LDML logging.info("Converting %s to LDML and installing both as as keyman file", f['name']) ldml = convert_kvk_to_ldml(fpath) name, ext = os.path.splitext(f['name']) ldmlfile = os.path.join(packageDir, name+".ldml") output_ldml(ldmlfile, ldml) elif ftype == KMFileTypes.KM_ICON: # Special handling of icon to convert to PNG logging.info("Converting %s to PNG and installing both as keyman files", f['name']) checkandsaveico(fpath) elif ftype == KMFileTypes.KM_SOURCE: #TODO for the moment just leave it for ibus-kmfl to ignore if it doesn't load pass elif ftype == KMFileTypes.KM_KMX: # Sanitize keyboard filename if not lower case kmx_id, ext = os.path.splitext(os.path.basename(f['name'])) for kb in keyboards: if kmx_id.lower() == kb['id'] and kmx_id != kb['id']: os.rename(os.path.join(packageDir, f['name']), os.path.join(packageDir, kb['id']+'.kmx')) install_keyboards_to_ibus(keyboards, packageDir) else: logging.error("install_kmp.py: error: No kmp.json or kmp.inf found in %s", inputfile) logging.info("Contents of %s:", inputfile) for o in os.listdir(packageDir): logging.info(o) rmtree(packageDir) message = "install_kmp.py: error: No kmp.json or kmp.inf found in %s" % (inputfile) raise InstallError(InstallStatus.Abort, message)
def uninstall_kmp_shared(packageID): """ Uninstall a kmp from /usr/local/share/keyman Args: packageID (str): Keyboard package ID """ kbdir = os.path.join('/usr/local/share/keyman', packageID) if not os.path.isdir(kbdir): logging.error("Keyboard directory for %s does not exist. Aborting", packageID) exit(3) kbdocdir = os.path.join('/usr/local/share/doc/keyman', packageID) kbfontdir = os.path.join('/usr/local/share/fonts/keyman', packageID) logging.info("Uninstalling shared keyboard: %s", packageID) if not os.access(kbdir, os.X_OK | os.W_OK): # Check for write access of keyman dir logging.error("You do not have permissions to uninstall the keyboard files. You need to run this with `sudo`") exit(3) if os.path.isdir(kbdocdir): if not os.access(kbdocdir, os.X_OK | os.W_OK): # Check for write access of keyman doc dir logging.error("You do not have permissions to uninstall the documentation. You need to run this with `sudo`") exit(3) rmtree(kbdocdir) logging.info("Removed documentation directory: %s", kbdocdir) else: logging.info("No documentation directory") if os.path.isdir(kbfontdir): if not os.access(kbfontdir, os.X_OK | os.W_OK): # Check for write access of keyman fonts logging.error("You do not have permissions to uninstall the font files. You need to run this with `sudo`") exit(3) rmtree(kbfontdir) logging.info("Removed font directory: %s", kbfontdir) else: logging.info("No font directory") # need to uninstall from ibus for all lang and all kmx in kmp info, system, options, keyboards, files = get_metadata(kbdir) if keyboards: uninstall_keyboards_from_ibus(keyboards, kbdir) else: logging.warning("could not uninstall keyboards from IBus") rmtree(kbdir) logging.info("Removed keyman directory: %s", kbdir) logging.info("Finished uninstalling shared keyboard: %s", packageID)
def uninstall_kmp_user(packageID): """ Uninstall a kmp from ~/.local/share/keyman Args: packageID (str): Keyboard package ID """ kbdir=user_keyboard_dir(packageID) if not os.path.isdir(kbdir): logging.error("Keyboard directory for %s does not exist. Aborting", packageID) exit(3) logging.info("Uninstalling local keyboard: %s", packageID) info, system, options, keyboards, files = get_metadata(kbdir) if keyboards: uninstall_keyboards_from_ibus(keyboards, kbdir) else: logging.warning("could not uninstall keyboards from IBus") rmtree(kbdir) logging.info("Removed user keyman directory: %s", kbdir) fontdir=os.path.join(user_keyman_font_dir(), packageID) if os.path.isdir(fontdir): rmtree(fontdir) logging.info("Removed user keyman font directory: %s", fontdir) logging.info("Finished uninstalling local keyboard: %s", packageID)
def install_kmp_shared(inputfile, online=False, language=None): """ Install a kmp file to /usr/local/share/keyman Args: inputfile (str): path to kmp file online (bool, default=False): whether to attempt to get online keyboard data """ check_keyman_dir( '/usr/local/share', _("You do not have permissions to install the keyboard files to the shared area " "/usr/local/share/keyman")) check_keyman_dir( '/usr/local/share/doc', _("You do not have permissions to install the documentation to the shared " "documentation area /usr/local/share/doc/keyman")) check_keyman_dir( '/usr/local/share/fonts', _("You do not have permissions to install the font files to the shared font area " "/usr/local/share/fonts")) packageID = extract_package_id(inputfile) packageDir = os.path.join('/usr/local/share/keyman', packageID) kmpdocdir = os.path.join('/usr/local/share/doc/keyman', packageID) kmpfontdir = os.path.join('/usr/local/share/fonts/keyman', packageID) if not os.path.isdir(packageDir): os.makedirs(packageDir) extract_kmp(inputfile, packageDir) # restart IBus so it knows about the keyboards being installed logging.debug("restarting IBus") restart_ibus() info, system, options, keyboards, files = get_metadata(packageDir) if keyboards: logging.info("Installing %s", info['name']['description']) if online: process_keyboard_data(packageID, packageDir) if len(keyboards) > 1: for kb in keyboards: if kb['id'] != packageID: process_keyboard_data(kb['id'], packageDir) for f in files: fpath = os.path.join(packageDir, f['name']) ftype = f['type'] if ftype == KMFileTypes.KM_DOC or ftype == KMFileTypes.KM_IMAGE: # Special handling of doc and images to hard link them into doc dir logging.info("Installing %s as documentation", f['name']) if not os.path.isdir(kmpdocdir): os.makedirs(kmpdocdir) os.link(fpath, os.path.join(kmpdocdir, f['name'])) elif ftype == KMFileTypes.KM_FONT: # Special handling of font to hard link it into font dir logging.info("Installing %s as font", f['name']) if not os.path.isdir(kmpfontdir): os.makedirs(kmpfontdir) os.link(fpath, os.path.join(kmpfontdir, f['name'])) elif ftype == KMFileTypes.KM_SOURCE: # TODO for the moment just leave it for ibus-kmfl to ignore if it doesn't load logging.info("Installing %s as keyman file", f['name']) elif ftype == KMFileTypes.KM_OSK: # Special handling to convert kvk into LDML logging.info( "Converting %s to LDML and installing both as as keyman file", f['name']) ldml = convert_kvk_to_ldml(fpath) name, ext = os.path.splitext(f['name']) ldmlfile = os.path.join(packageDir, name + ".ldml") output_ldml(ldmlfile, ldml) elif ftype == KMFileTypes.KM_ICON: # Special handling of icon to convert to PNG logging.info( "Converting %s to PNG and installing both as keyman files", f['name']) checkandsaveico(fpath) elif ftype == KMFileTypes.KM_KMX: # Sanitize keyboard filename if not lower case kmx_id, ext = os.path.splitext(os.path.basename(f['name'])) for kb in keyboards: if kmx_id.lower() == kb['id'] and kmx_id != kb['id']: os.rename(os.path.join(packageDir, f['name']), os.path.join(packageDir, kb['id'] + '.kmx')) fpath = os.path.join(packageDir, kb['id'] + '.kmx') extractico(fpath) install_keyboards_to_ibus(keyboards, packageDir, language) else: logging.error( "install_kmp.py: error: No kmp.json or kmp.inf found in %s", inputfile) logging.info("Contents of %s:", inputfile) for o in os.listdir(packageDir): logging.info(o) rmtree(packageDir) message = _( "install_kmp.py: error: No kmp.json or kmp.inf found in {package}" ).format(package=inputfile) raise InstallError(InstallStatus.Abort, message)
def install_kmp_user(inputfile, online=False, language=None): packageID = extract_package_id(inputfile) packageDir = user_keyboard_dir(packageID) if not os.path.isdir(packageDir): os.makedirs(packageDir) extract_kmp(inputfile, packageDir) restart_ibus() info, system, options, keyboards, files = get_metadata(packageDir) if keyboards: logging.info("Installing %s", info['name']['description']) if online: process_keyboard_data(packageID, packageDir) if len(keyboards) > 1: for kb in keyboards: if kb['id'] != packageID: process_keyboard_data(kb['id'], packageDir) for f in files: fpath = os.path.join(packageDir, f['name']) ftype = f['type'] if ftype == KMFileTypes.KM_FONT: # Special handling of font to hard link it into font dir fontsdir = os.path.join(user_keyman_font_dir(), packageID) if not os.path.isdir(fontsdir): os.makedirs(fontsdir) os.link(fpath, os.path.join(fontsdir, f['name'])) logging.info("Installing %s as font", f['name']) elif ftype == KMFileTypes.KM_OSK: # Special handling to convert kvk into LDML logging.info( "Converting %s to LDML and installing both as as keyman file", f['name']) ldml = convert_kvk_to_ldml(fpath) name, ext = os.path.splitext(f['name']) ldmlfile = os.path.join(packageDir, name + ".ldml") output_ldml(ldmlfile, ldml) elif ftype == KMFileTypes.KM_ICON: # Special handling of icon to convert to PNG logging.info( "Converting %s to PNG and installing both as keyman files", f['name']) checkandsaveico(fpath) elif ftype == KMFileTypes.KM_SOURCE: # TODO for the moment just leave it for ibus-kmfl to ignore if it doesn't load pass elif ftype == KMFileTypes.KM_KMX: # Sanitize keyboard filename if not lower case kmx_id, ext = os.path.splitext(os.path.basename(f['name'])) for kb in keyboards: if kmx_id.lower() == kb['id'] and kmx_id != kb['id']: os.rename(os.path.join(packageDir, f['name']), os.path.join(packageDir, kb['id'] + '.kmx')) fpath = os.path.join(packageDir, kb['id'] + '.kmx') extractico(fpath) install_keyboards(keyboards, packageDir, language) else: logging.error( "install_kmp.py: error: No kmp.json or kmp.inf found in %s", inputfile) logging.info("Contents of %s:", inputfile) for o in os.listdir(packageDir): logging.info(o) rmtree(packageDir) message = _( "install_kmp.py: error: No kmp.json or kmp.inf found in {packageFile}" ).format(packageFile=inputfile) raise InstallError(InstallStatus.Abort, message)
def install_kmp_shared(inputfile, online=False): """ Install a kmp file to /usr/local/share/keyman Args: inputfile (str): path to kmp file online(bool, default=False): whether to attempt to get a source kmn and ico for the keyboard """ check_keyman_dir('/usr/local/share', "You do not have permissions to install the keyboard files to the shared area /usr/local/share/keyman") check_keyman_dir('/usr/local/share/doc', "You do not have permissions to install the documentation to the shared documentation area /usr/local/share/doc/keyman") check_keyman_dir('/usr/local/share/fonts', "You do not have permissions to install the font files to the shared font area /usr/local/share/fonts") packageID = extract_package_id(inputfile) packageDir = os.path.join('/usr/local/share/keyman', packageID) kmpdocdir = os.path.join('/usr/local/share/doc/keyman', packageID) kmpfontdir = os.path.join('/usr/local/share/fonts/keyman', packageID) if not os.path.isdir(packageDir): os.makedirs(packageDir) extract_kmp(inputfile, packageDir) #restart IBus so it knows about the keyboards being installed logging.debug("restarting IBus") restart_ibus() info, system, options, keyboards, files = get_metadata(packageDir) if keyboards: logging.info("Installing %s", info['name']['description']) if online: process_keyboard_data(packageID, packageDir) if len(keyboards) > 1: for kb in keyboards: if kb['id'] != packageID: process_keyboard_data(kb['id'], packageDir) for f in files: fpath = os.path.join(packageDir, f['name']) ftype = f['type'] if ftype == KMFileTypes.KM_DOC or ftype == KMFileTypes.KM_IMAGE: #Special handling of doc and images to hard link them into doc dir logging.info("Installing %s as documentation", f['name']) if not os.path.isdir(kmpdocdir): os.makedirs(kmpdocdir) os.link(fpath, os.path.join(kmpdocdir, f['name'])) elif ftype == KMFileTypes.KM_FONT: #Special handling of font to hard link it into font dir logging.info("Installing %s as font", f['name']) if not os.path.isdir(kmpfontdir): os.makedirs(kmpfontdir) os.link(fpath, os.path.join(kmpfontdir, f['name'])) elif ftype == KMFileTypes.KM_SOURCE: #TODO for the moment just leave it for ibus-kmfl to ignore if it doesn't load logging.info("Installing %s as keyman file", f['name']) elif ftype == KMFileTypes.KM_OSK: # Special handling to convert kvk into LDML logging.info("Converting %s to LDML and installing both as as keyman file", f['name']) ldml = convert_kvk_to_ldml(fpath) name, ext = os.path.splitext(f['name']) ldmlfile = os.path.join(packageDir, name+".ldml") output_ldml(ldmlfile, ldml) elif ftype == KMFileTypes.KM_ICON: # Special handling of icon to convert to PNG logging.info("Converting %s to PNG and installing both as keyman files", f['name']) checkandsaveico(fpath) elif ftype == KMFileTypes.KM_KMX: # Sanitize keyboard filename if not lower case kmx_id, ext = os.path.splitext(os.path.basename(f['name'])) for kb in keyboards: if kmx_id.lower() == kb['id'] and kmx_id != kb['id']: os.rename(os.path.join(packageDir, f['name']), os.path.join(packageDir, kb['id']+'.kmx')) for kb in keyboards: # install all kmx for first lang not just packageID kmx_file = os.path.join(packageDir, kb['id'] + ".kmx") install_to_ibus(lang, kmx_file) else: logging.error("install_kmp.py: error: No kmp.json or kmp.inf found in %s", inputfile) logging.info("Contents of %s:", inputfile) for o in os.listdir(packageDir): logging.info(o) rmtree(packageDir) message = "install_kmp.py: error: No kmp.json or kmp.inf found in %s" % (inputfile) raise InstallError(InstallStatus.Abort, message)