def main(): logging.basicConfig(level=logging.INFO, format='%(levelname)s:%(message)s') km_cache=keyman_cache_dir() logging.info("looking for KM_UNKNOWN files in cached kmps") keyboarddata = list_keyboards() if keyboarddata: with open('./unknownfiles.txt', 'wt') as unknownfiles: print("files found in cached kmps of type KM_UNKNOWN", file=unknownfiles) for kbid in keyboarddata: kmpfile = os.path.join(km_cache, kbid+".kmp") if os.path.exists(kmpfile): with tempfile.TemporaryDirectory() as tmpdirname: extract_kmp(kmpfile, tmpdirname) try: info, system, options, keyboards, files = get_metadata(tmpdirname) if files: for kbfile in files: if kbfile['type'] == KMFileTypes.KM_UNKNOWN: print(kbfile['name'], file=unknownfiles) except Exception as e: print(type(e)) # the exception instance print(e.args) # arguments stored in .args print(e) # __str__ allows args to be printed directly, pass pass
def main(): logging.basicConfig(level=logging.DEBUG, format='%(levelname)s:%(message)s') keyboarddata = list_keyboards() if keyboarddata: with open('./nokmp.txt', 'wt') as nokmp, \ open('./infnokeyboard.txt', 'wt') as infnokeyboard, \ open('./goodjsonkmpkmn.txt', 'wt') as goodjsonkmpkmn, \ open('./jsonkmpnokmn.txt', 'wt') as jsonkmpnokmn, \ open('./jsonkmpbadkmn.txt', 'wt') as jsonkmpbadkmn, \ open('./jsonkmpmissingkmn.txt', 'wt') as jsonkmpmissingkmn, \ open('./brokeninf.txt', 'wt') as brokeninf, \ open('./nodata.txt', 'wt') as nodata, \ open('./goodinfkmp.txt', 'wt') as goodinfkmp: print("Keyboard: will work in kmfl :)", file=goodjsonkmpkmn) # goodjsonkmpkmn print("Keyboard: has uncompilable kmn", file=jsonkmpbadkmn) # jsonkmpbadkmn print("Keyboard: has json in kmp but can't find the kmn on github", file=jsonkmpmissingkmn) # jsonkmpmissingkmn print("Keyboard: has json in kmp but has no sourcePath to look for kmn on github", file=jsonkmpnokmn) # jsonkmpnokmn print("Keyboard: has kmp with kmp.inf", file=goodinfkmp) print("Keyboard: has kmp with kmp.inf but it has no Keyboard", file=infnokeyboard) print("Keyboard: has kmp but no kmp.json and no or broken kmp.inf", file=brokeninf) print("Keyboard: does not have kmp so mobile/web only", file=nokmp) print("Keyboard: has no data", file=nodata) for kbid in keyboarddata: kbdata = get_keyboard_data(kbid, True) print(kbid) if kbdata: if 'packageFilename' in kbdata: kmpfile = get_kmp_file(kbdata, True) with tempfile.TemporaryDirectory() as tmpdirname: extract_kmp(kmpfile, tmpdirname) try: info, system, options, keyboards, files = get_metadata(tmpdirname) if keyboards: if 'sourcePath' in kbdata: response = get_kmn(kbid, kbdata['sourcePath']) if response.status_code == 200: kmndownloadfile = os.path.join(tmpdirname, kbid + ".kmn") with open(kmndownloadfile, 'wb') as f: f.write(response.content) subprocess.run(["kmflcomp", kmndownloadfile], stdout=subprocess.PIPE, stderr= subprocess.STDOUT) kmfl_file = os.path.join(tmpdirname, kbid + ".kmfl") if os.path.isfile(kmfl_file): logging.debug("goodjsonkmpkmn") print(kbid, file=goodjsonkmpkmn) # goodjsonkmpkmn else: logging.debug("jsonkmpbadkmn") print(kbid, file=jsonkmpbadkmn) # jsonkmpbadkmn else: logging.debug("jsonkmpmissingkmn") print(kbid, file=jsonkmpmissingkmn) # jsonkmpmissingkmn else: logging.debug("jsonkmpnokmn") print(kbid, file=jsonkmpnokmn) # jsonkmpnokmn else: info, system, options, keyboards, files = get_infdata(tmpdirname) if keyboards: logging.debug("infnokeyboard") print(kbid, file=goodinfkmp) elif files: logging.debug("goodinfkmp") print(kbid, file=infnokeyboard) else: print(kbid, file=brokeninf) except KeyError: logging.debug("brokeninf") print(kbid, file=brokeninf) else: logging.debug("nokmp") print(kbid, file=nokmp) else: logging.debug("nodata") print(kbid, file=nodata)
def __init__(self, kmpfile, online=False, viewkmp=None, downloadwindow=None): logging.debug("InstallKmpWindow: kmpfile: %s", kmpfile) self.kmpfile = kmpfile self.online = online self.endonclose = False self.viewwindow = viewkmp self.download = downloadwindow self.accelerators = None keyboardid = os.path.basename(os.path.splitext(kmpfile)[0]) installed_kmp_ver = get_kmp_version(keyboardid) if installed_kmp_ver: logging.info("installed kmp version %s", installed_kmp_ver) windowtitle = "Installing keyboard/package " + keyboardid Gtk.Window.__init__(self, title=windowtitle) init_accel(self) self.set_border_width(12) vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=12) mainhbox = Gtk.Box() with tempfile.TemporaryDirectory() as tmpdirname: extract_kmp(kmpfile, tmpdirname) info, system, options, keyboards, files = get_metadata(tmpdirname) self.kbname = keyboards[0]['name'] self.checkcontinue = True if installed_kmp_ver: if info['version']['description'] == installed_kmp_ver: dialog = Gtk.MessageDialog(self, 0, Gtk.MessageType.QUESTION, Gtk.ButtonsType.YES_NO, "Keyboard is installed already") dialog.format_secondary_text( "The " + self.kbname + " keyboard is already installed at version " + installed_kmp_ver + ". Do you want to uninstall then reinstall it?") response = dialog.run() dialog.destroy() if response == Gtk.ResponseType.YES: logging.debug("QUESTION dialog closed by clicking YES button") uninstall_kmp(keyboardid) elif response == Gtk.ResponseType.NO: logging.debug("QUESTION dialog closed by clicking NO button") self.checkcontinue = False else: try: logging.info("package version %s", info['version']['description']) logging.info("installed kmp version %s", installed_kmp_ver) if StrictVersion(info['version']['description']) <= StrictVersion(installed_kmp_ver): dialog = Gtk.MessageDialog(self, 0, Gtk.MessageType.QUESTION, Gtk.ButtonsType.YES_NO, "Keyboard is installed already") dialog.format_secondary_text( "The " + self.kbname + " keyboard is already installed with a newer version " + installed_kmp_ver + ". Do you want to uninstall it and install the older version" + info['version']['description'] + "?") response = dialog.run() dialog.destroy() if response == Gtk.ResponseType.YES: logging.debug("QUESTION dialog closed by clicking YES button") uninstall_kmp(keyboardid) elif response == Gtk.ResponseType.NO: logging.debug("QUESTION dialog closed by clicking NO button") self.checkcontinue = False except: logging.warning("Exception uninstalling an old kmp, continuing") pass image = Gtk.Image() if options and "graphicFile" in options: image.set_from_file(os.path.join(tmpdirname, options['graphicFile'])) else: img_default = find_keyman_image("defaultpackage.gif") image.set_from_file(img_default) mainhbox.pack_start(image, False, False, 0) self.page1 = Gtk.Box() self.page1.set_border_width(12) grid = Gtk.Grid() self.page1.add(grid) label1 = Gtk.Label() label1.set_text("Keyboard layouts: ") label1.set_halign(Gtk.Align.END) grid.add(label1) prevlabel = label1 label = Gtk.Label() keyboardlayout = "" for kb in keyboards: if keyboardlayout != "": keyboardlayout = keyboardlayout + "\n" keyboardlayout = keyboardlayout + kb['name'] label.set_text(keyboardlayout) label.set_halign(Gtk.Align.START) label.set_selectable(True) grid.attach_next_to(label, label1, Gtk.PositionType.RIGHT, 1, 1) fonts = get_fonts(files) if fonts: label2 = Gtk.Label() # Fonts are optional label2.set_text("Fonts: ") label2.set_halign(Gtk.Align.END) grid.attach_next_to(label2, prevlabel, Gtk.PositionType.BOTTOM, 1, 1) prevlabel = label2 label = Gtk.Label() fontlist = "" for font in fonts: if fontlist != "": fontlist = fontlist + "\n" if font['description'][:5] == "Font ": fontdesc = font['description'][5:] else: fontdesc = font['description'] fontlist = fontlist + fontdesc label.set_text(fontlist) label.set_halign(Gtk.Align.START) label.set_selectable(True) grid.attach_next_to(label, label2, Gtk.PositionType.RIGHT, 1, 1) label3 = Gtk.Label() label3.set_text("Package version: ") label3.set_halign(Gtk.Align.END) grid.attach_next_to(label3, prevlabel, Gtk.PositionType.BOTTOM, 1, 1) prevlabel = label3 label = Gtk.Label() label.set_text(info['version']['description']) label.set_halign(Gtk.Align.START) label.set_selectable(True) grid.attach_next_to(label, label3, Gtk.PositionType.RIGHT, 1, 1) if info and 'author' in info: label4 = Gtk.Label() label4.set_text("Author: ") label4.set_halign(Gtk.Align.END) grid.attach_next_to(label4, prevlabel, Gtk.PositionType.BOTTOM, 1, 1) prevlabel = label4 label = Gtk.Label() if 'url' in info['author']: label.set_markup("<a href=\"" + info['author']['url'] + "\" title=\"" + info['author']['url'] + "\">" + info['author']['description'] + "</a>") else: label.set_text(info['author']['description']) label.set_halign(Gtk.Align.START) label.set_selectable(True) grid.attach_next_to(label, label4, Gtk.PositionType.RIGHT, 1, 1) if info and 'website' in info: label5 = Gtk.Label() # Website is optional and may be a mailto for the author label5.set_text("Website: ") label5.set_halign(Gtk.Align.END) grid.attach_next_to(label5, prevlabel, Gtk.PositionType.BOTTOM, 1, 1) prevlabel = label5 label = Gtk.Label() label.set_markup("<a href=\"" + info['website']['description'] + "\">" + info['website']['description'] + "</a>") label.set_halign(Gtk.Align.START) label.set_selectable(True) grid.attach_next_to(label, label5, Gtk.PositionType.RIGHT, 1, 1) if info and 'copyright' in info: label6 = Gtk.Label() label6.set_text("Copyright: ") label6.set_halign(Gtk.Align.END) grid.attach_next_to(label6, prevlabel, Gtk.PositionType.BOTTOM, 1, 1) label = Gtk.Label() label.set_text(info['copyright']['description']) label.set_halign(Gtk.Align.START) label.set_selectable(True) grid.attach_next_to(label, label6, Gtk.PositionType.RIGHT, 1, 1) self.page2 = Gtk.Box() webview = WebKit2.WebView() webview.connect("decide-policy", self.doc_policy) if options and "readmeFile" in options: self.readme = options['readmeFile'] else: self.readme = "noreadme" readme_file = os.path.join(tmpdirname, self.readme) if os.path.isfile(readme_file): with open(readme_file, "r") as read_file: readme_data = read_file.read() readme_uri = pathlib.Path(readme_file).as_uri() logging.debug(readme_data) webview.load_html(readme_data, readme_uri) s = Gtk.ScrolledWindow() s.add(webview) self.page2.pack_start(s, True, True, 0) self.notebook = Gtk.Notebook() self.notebook.set_tab_pos(Gtk.PositionType.BOTTOM) mainhbox.pack_start(self.notebook, True, True, 0) self.notebook.append_page( self.page1, Gtk.Label('Details')) self.notebook.append_page( self.page2, Gtk.Label('README')) else: mainhbox.pack_start(self.page1, True, True, 0) vbox.pack_start(mainhbox, True, True, 0) hbox = Gtk.Box(spacing=6) vbox.pack_start(hbox, False, False, 0) button = Gtk.Button.new_with_mnemonic("_Install") button.connect("clicked", self.on_install_clicked) hbox.pack_start(button, False, False, 0) button = Gtk.Button.new_with_mnemonic("_Cancel") button.connect("clicked", self.on_cancel_clicked) hbox.pack_end(button, False, False, 0) bind_accelerator(self.accelerators, button, '<Control>w') self.add(vbox) self.resize(635, 270)
def main(): logging.basicConfig(level=logging.DEBUG, format='%(levelname)s:%(message)s') keyboarddata = list_keyboards() if keyboarddata: with open('./nokmp.txt', 'wt') as nokmp, \ open('./infnokeyboard.txt', 'wt') as infnokeyboard, \ open('./goodjsonkmpkmn.txt', 'wt') as goodjsonkmpkmn, \ open('./jsonkmpnokmn.txt', 'wt') as jsonkmpnokmn, \ open('./jsonkmpbadkmn.txt', 'wt') as jsonkmpbadkmn, \ open('./jsonkmpmissingkmn.txt', 'wt') as jsonkmpmissingkmn, \ open('./brokeninf.txt', 'wt') as brokeninf, \ open('./nodata.txt', 'wt') as nodata, \ open('./goodinfkmp.txt', 'wt') as goodinfkmp: print("Keyboard: will work in kmfl :)", file=goodjsonkmpkmn) # goodjsonkmpkmn print("Keyboard: has uncompilable kmn", file=jsonkmpbadkmn) # jsonkmpbadkmn print("Keyboard: has json in kmp but can't find the kmn on github", file=jsonkmpmissingkmn) # jsonkmpmissingkmn print( "Keyboard: has json in kmp but has no sourcePath to look for kmn on github", file=jsonkmpnokmn) # jsonkmpnokmn print("Keyboard: has kmp with kmp.inf", file=goodinfkmp) print("Keyboard: has kmp with kmp.inf but it has no Keyboard", file=infnokeyboard) print("Keyboard: has kmp but no kmp.json and no or broken kmp.inf", file=brokeninf) print("Keyboard: does not have kmp so mobile/web only", file=nokmp) print("Keyboard: has no data", file=nodata) for kbid in keyboarddata: kbdata = get_keyboard_data(kbid, True) print(kbid) if kbdata: if 'packageFilename' in kbdata: kmpfile = get_kmp_file(kbdata, True) with tempfile.TemporaryDirectory() as tmpdirname: extract_kmp(kmpfile, tmpdirname) try: info, system, options, keyboards, files = get_metadata( tmpdirname) if keyboards: if 'sourcePath' in kbdata: response = get_kmn( kbid, kbdata['sourcePath']) if response.status_code == 200: kmndownloadfile = os.path.join( tmpdirname, kbid + ".kmn") with open(kmndownloadfile, 'wb') as f: f.write(response.content) subprocess.run( ["kmflcomp", kmndownloadfile], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) kmfl_file = os.path.join( tmpdirname, kbid + ".kmfl") if os.path.isfile(kmfl_file): logging.debug("goodjsonkmpkmn") print(kbid, file=goodjsonkmpkmn ) # goodjsonkmpkmn else: logging.debug("jsonkmpbadkmn") print(kbid, file=jsonkmpbadkmn ) # jsonkmpbadkmn else: logging.debug("jsonkmpmissingkmn") print(kbid, file=jsonkmpmissingkmn ) # jsonkmpmissingkmn else: logging.debug("jsonkmpnokmn") print( kbid, file=jsonkmpnokmn) # jsonkmpnokmn else: info, system, options, keyboards, files = get_infdata( tmpdirname) if keyboards: logging.debug("infnokeyboard") print(kbid, file=goodinfkmp) elif files: logging.debug("goodinfkmp") print(kbid, file=infnokeyboard) else: print(kbid, file=brokeninf) except KeyError: logging.debug("brokeninf") print(kbid, file=brokeninf) else: logging.debug("nokmp") print(kbid, file=nokmp) else: logging.debug("nodata") print(kbid, file=nodata)