Index: gc_lang/fr/build.py ================================================================== --- gc_lang/fr/build.py +++ gc_lang/fr/build.py @@ -1,35 +1,57 @@ # Builder for French language import os import platform import zipfile +import shutil +import json +import traceback from distutils import dir_util, file_util import helpers def build (sLang, dVars): "complementary build launched from make.py" createWebExtension(sLang, dVars) + convertWebExtensionForChrome(sLang, dVars) createMailExtension(sLang, dVars) createNodeJSPackage(sLang) def createWebExtension (sLang, dVars): "create Web-extension" - print("Building WebExtension") + print("> Building WebExtension for Firefox") helpers.createCleanFolder("_build/webext/"+sLang) dir_util.copy_tree("gc_lang/"+sLang+"/webext/", "_build/webext/"+sLang) dir_util.copy_tree("grammalecte-js", "_build/webext/"+sLang+"/grammalecte") dVars['webextOptionsHTML'] = _createOptionsForWebExtension(dVars) helpers.copyAndFileTemplate("_build/webext/"+sLang+"/manifest.json", "_build/webext/"+sLang+"/manifest.json", dVars) helpers.copyAndFileTemplate("_build/webext/"+sLang+"/panel/main.html", "_build/webext/"+sLang+"/panel/main.html", dVars) with helpers.CD("_build/webext/"+sLang): os.system("web-ext build") # Copy Firefox zip extension to _build - helpers.moveFolderContent("_build/webext/"+sLang+"/web-ext-artifacts", "_build", "fx-"+sLang+"-", True) + helpers.moveFolderContent("_build/webext/"+sLang+"/web-ext-artifacts", "_build", "firefox-", True) + + +def convertWebExtensionForChrome (sLang, dVars): + "Create the extension for Chrome" + print("> Converting WebExtension for Chrome") + try: + with open(f"_build/webext/{sLang}/manifest.json", "r", encoding="utf-8") as hSrc: + dManifest = json.load(hSrc) + if "applications" in dManifest: + del dManifest["applications"] + if "chrome_settings_overrides" in dManifest: + del dManifest["chrome_settings_overrides"] + with open(f"_build/webext/{sLang}/manifest.json", "w", encoding="utf-8") as hDst: + json.dump(dManifest, hDst, ensure_ascii=True, indent=2) + shutil.make_archive(f"_build/chrome-grammalecte-{sLang}-v{dVars['version']}", 'zip', "_build/webext/"+sLang) + except: + traceback.print_exc() + print(" Error. Converting the WebExtension for Chrome failed.") def _createOptionsForWebExtension (dVars): sHTML = "" sLang = dVars['sDefaultUILang'] @@ -42,11 +64,11 @@ return sHTML def createMailExtension (sLang, dVars): "create extension for Thunderbird (as MailExtension)" - print("Building extension for Thunderbird (MailExtension)") + print("> Building extension for Thunderbird (MailExtension)") spfZip = "_build/" + dVars['tb_identifier'] + "-v" + dVars['version'] + '.mailext.xpi' hZip = zipfile.ZipFile(spfZip, mode='w', compression=zipfile.ZIP_DEFLATED) _copyGrammalecteJSPackageInZipFile(hZip, sLang) for spf in ["LICENSE.txt", "LICENSE.fr.txt"]: hZip.write(spf) Index: helpers.py ================================================================== --- helpers.py +++ helpers.py @@ -99,12 +99,12 @@ return Template(open(spf, "r", encoding="utf-8").read()).safe_substitute(dVars) def copyAndFileTemplate (spfSrc, spfDst, dVars): "write file as with variables filed with " - s = Template(open(spfSrc, "r", encoding="utf-8").read()).safe_substitute(dVars) - open(spfDst, "w", encoding="utf-8", newline="\n").write(s) + sText = Template(open(spfSrc, "r", encoding="utf-8").read()).safe_substitute(dVars) + open(spfDst, "w", encoding="utf-8", newline="\n").write(sText) def addFolderToZipAndFileFile (hZip, spSrc, spDst, dVars, bRecursive): "add folder content to zip archive and file files with " # recursive function