def addlistitems(self, installed_kmp, store, install_area): for kmp in sorted(installed_kmp): kmpdata = installed_kmp[kmp] if install_area == InstallArea.IA_USER: welcome_file = os.path.join(user_keyboard_dir(kmpdata['packageID']), "welcome.htm") icofile = os.path.join(user_keyboard_dir(kmpdata['packageID']), kmpdata['packageID'] + ".ico.png") if not os.path.isfile(icofile): icofile = os.path.join(user_keyboard_dir(kmpdata['packageID']), kmpdata['keyboardID'] + ".ico.png") elif install_area == InstallArea.IA_SHARED: welcome_file = os.path.join("/usr/local/share/keyman", kmpdata['packageID'], "welcome.htm") icofile = os.path.join("/usr/local/share/keyman", kmpdata['packageID'], kmpdata['packageID'] + ".ico.png") if not os.path.isfile(icofile): icofile = os.path.join("/usr/local/share/keyman", kmpdata['packageID'], kmpdata['keyboardID'] + ".ico.png") else: welcome_file = os.path.join("/usr/share/keyman", kmpdata['packageID'], "welcome.htm") icofile = os.path.join("/usr/share/keyman", kmpdata['packageID'], kmpdata['packageID'] + ".ico.png") if not os.path.isfile(icofile): icofile = os.path.join("/usr/share/keyman", kmpdata['packageID'], kmpdata['keyboardID'] + ".ico.png") if not os.path.isfile(icofile): icofile = find_keyman_image("icon_kmp.png") if not os.path.isfile(welcome_file): welcome_file = None treeiter = store.append([GdkPixbuf.Pixbuf.new_from_file_at_size(icofile, 16, 16), \ kmpdata['name'], \ kmpdata['version'], \ kmpdata['packageID'], \ install_area, \ welcome_file])
def addlistitems(self, installed_kmp, store, install_area): for kmp in sorted(installed_kmp): kmpdata = installed_kmp[kmp] bmppng = ".bmp.png" # Icon file extension if install_area == InstallArea.IA_USER: welcome_file = os.path.join( user_keyboard_dir(kmpdata['packageID']), "welcome.htm") options_file = os.path.join( user_keyboard_dir(kmpdata['packageID']), "options.htm") icofile = os.path.join(user_keyboard_dir(kmpdata['packageID']), kmpdata['packageID'] + bmppng) if not os.path.isfile(icofile): icofile = os.path.join( user_keyboard_dir(kmpdata['packageID']), kmpdata['keyboardID'] + bmppng) elif install_area == InstallArea.IA_SHARED: welcome_file = os.path.join("/usr/local/share/keyman", kmpdata['packageID'], "welcome.htm") options_file = os.path.join("/usr/local/share/keyman", kmpdata['packageID'], "options.htm") icofile = os.path.join("/usr/local/share/keyman", kmpdata['packageID'], kmpdata['packageID'] + bmppng) if not os.path.isfile(icofile): icofile = os.path.join("/usr/local/share/keyman", kmpdata['packageID'], kmpdata['keyboardID'] + bmppng) else: welcome_file = os.path.join("/usr/share/keyman", kmpdata['packageID'], "welcome.htm") options_file = os.path.join("/usr/share/keyman", kmpdata['packageID'], "options.htm") icofile = os.path.join("/usr/share/keyman", kmpdata['packageID'], kmpdata['packageID'] + bmppng) if not os.path.isfile(icofile): icofile = os.path.join("/usr/share/keyman", kmpdata['packageID'], kmpdata['keyboardID'] + bmppng) if not os.path.isfile(icofile): icofile = find_keyman_image("icon_kmp.png") if not os.path.isfile(welcome_file): welcome_file = None if not os.path.isfile(options_file): options_file = None treeiter = store.append([GdkPixbuf.Pixbuf.new_from_file_at_size(icofile, 16, 16), \ kmpdata['name'], \ kmpdata['version'], \ kmpdata['packageID'], \ install_area, \ welcome_file, \ options_file])
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 on_install_clicked(self, button): logging.info("Installing keyboard") try: install_kmp(self.kmpfile, self.online, language=self.language) if self.viewwindow: self.viewwindow.refresh_installed_kmp() keyboardid = os.path.basename(os.path.splitext(self.kmpfile)[0]) welcome_file = os.path.join(user_keyboard_dir(keyboardid), "welcome.htm") if os.path.isfile(welcome_file): uri_path = pathlib.Path(welcome_file).as_uri() logging.debug(uri_path) w = WelcomeView(self, uri_path, self.kbname, True) w.run() w.destroy() else: dialog = Gtk.MessageDialog( self, 0, Gtk.MessageType.INFO, Gtk.ButtonsType.OK, _("Keyboard {name} installed").format(name=self.kbname)) dialog.run() dialog.destroy() except InstallError as e: if e.status == InstallStatus.Abort: message = _("Keyboard {name} could not be installed.").format(name=self.kbname) \ + "\n\n" + _("Error Message:") + "\n %s" % (e.message) logging.error(message) message_type = Gtk.MessageType.ERROR else: message = _("Keyboard {name} could not be installed.").format(name=self.kbname) \ + "\n\n" + _("Warning Message:") + "\n %s" % (e.message) logging.warning(message) message_type = Gtk.MessageType.WARNING dialog = Gtk.MessageDialog(self, 0, message_type, Gtk.ButtonsType.OK, message) dialog.run() dialog.destroy() self.close()
def on_install_clicked(self, button): logging.info("Installing keyboard") try: install_kmp(self.kmpfile, self.online) if self.viewwindow: self.viewwindow.refresh_installed_kmp() if self.download: self.download.close() keyboardid = os.path.basename(os.path.splitext(self.kmpfile)[0]) welcome_file = os.path.join(user_keyboard_dir(keyboardid), "welcome.htm") if os.path.isfile(welcome_file): uri_path = pathlib.Path(welcome_file).as_uri() logging.debug(uri_path) w = WelcomeView(uri_path, self.kbname) w.resize(800, 600) w.show_all() else: dialog = Gtk.MessageDialog(self, 0, Gtk.MessageType.INFO, Gtk.ButtonsType.OK, "Keyboard " + self.kbname + " installed") dialog.run() dialog.destroy() except InstallError as e: if e.status == InstallStatus.Abort: message = "Keyboard " + self.kbname + " could not be installed.\n\nError Message:\n%s" % (e.message) logging.error(message) message_type = Gtk.MessageType.ERROR else: message = "Keyboard " + self.kbname + " could not be installed fully.\n\nWarning Message:\n%s" % (e.message) logging.warning(message) message_type = Gtk.MessageType.WARNING dialog = Gtk.MessageDialog(self, 0, message_type, Gtk.ButtonsType.OK, message) dialog.run() dialog.destroy() if not self.endonclose: self.close()
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_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)