Index: make.py ================================================================== --- make.py +++ make.py @@ -1,11 +1,14 @@ #!/usr/bin/env python3 # coding: UTF-8 + +""" +Grammalecte builder +""" import sys import os -import subprocess import re import zipfile import traceback import configparser import datetime @@ -15,40 +18,43 @@ import json import platform from distutils import dir_util, file_util -import dialog_bundled +#import dialog_bundled import compile_rules import helpers import lex_build sWarningMessage = "The content of this folder is generated by code and replaced at each build.\n" def getConfig (sLang): + "load config.ini in at gc_lang/, returns xConfigParser object" xConfig = configparser.SafeConfigParser() xConfig.optionxform = str try: - xConfig.read("gc_lang/" + sLang + "/config.ini", encoding="utf-8") - except: + xConfig.read_file(open("gc_lang/" + sLang + "/config.ii", "r", encoding="utf-8")) + except FileNotFoundError: print("# Error. Can’t read config file [" + sLang + "]") exit() return xConfig def createOptionsLabelProperties (dOptLbl): + "create content for .properties files (LibreOffice)" sContent = "" for sOpt, tLabel in dOptLbl.items(): sContent += sOpt + "=" + tLabel[0] + "\n" if tLabel[1]: sContent += "hlp_" + sOpt + "=" + tLabel[1] + "\n" return sContent def createDialogOptionsXDL (dVars): + "create bundled dialog options file .xdl (LibreOffice)" sFixedline = '\n' sCheckbox = '\n' iTabIndex = 1 nPosY = 5 nWidth = 240 @@ -133,17 +139,17 @@ if bInstall: print("> installation in Writer") if dVars.get('unopkg', False): cmd = '"'+os.path.abspath(dVars.get('unopkg')+'" add -f '+spfZip) print(cmd) - #subprocess.run(cmd) os.system(cmd) else: print("# Error: path and filename of unopkg not set in config.ini") def createServerOptions (sLang, dOptData): + "create file options for Grammalecte server" with open("grammalecte-server-options."+sLang+".ini", "w", encoding="utf-8", newline="\n") as hDst: hDst.write("# Server options. Lang: " + sLang + "\n\n[gc_options]\n") for sSection, lOpt in dOptData["lStructOpt"]: hDst.write("\n########## " + dOptData["dOptLabel"][sLang].get(sSection, sSection + "[no label found]")[0] + " ##########\n") for lLineOpt in lOpt: @@ -164,10 +170,11 @@ hZip.write(spf) hZip.writestr("setup.py", helpers.fileFile("gc_lang/fr/setup.py", dVars)) def copyGrammalectePyPackageInZipFile (hZip, spLangPack, sAddPath=""): + "copy Grammalecte Python package in zip file" for sf in os.listdir("grammalecte"): if not os.path.isdir("grammalecte/"+sf): hZip.write("grammalecte/"+sf, sAddPath+"grammalecte/"+sf) for sf in os.listdir("grammalecte/graphspell"): if not os.path.isdir("grammalecte/graphspell/"+sf): @@ -179,10 +186,11 @@ if not os.path.isdir(spLangPack+"/"+sf): hZip.write(spLangPack+"/"+sf, sAddPath+spLangPack+"/"+sf) def create (sLang, xConfig, bInstallOXT, bJavaScript): + "make Grammalecte for project " oNow = datetime.datetime.now() print("============== MAKE GRAMMALECTE [{0}] at {1.hour:>2} h {1.minute:>2} min {1.second:>2} s ==============".format(sLang, oNow)) #### READ CONFIGURATION print("> read configuration...") @@ -251,11 +259,11 @@ # options data struct dVars["dOptJavaScript"] = json.dumps(list(dVars["dOptJavaScript"].items())) dVars["dOptFirefox"] = json.dumps(list(dVars["dOptFirefox"].items())) dVars["dOptThunderbird"] = json.dumps(list(dVars["dOptThunderbird"].items())) - + # create folder spLangPack = "grammalecte-js/"+sLang helpers.createCleanFolder(spLangPack) # create files @@ -274,20 +282,21 @@ helpers.copyAndFileTemplate(spLang+"/modules-js/"+sf, spLangPack+"/"+sf, dVars) print(sf, end=", ") print() try: - build_module = importlib.import_module("gc_lang."+sLang+".build") + buildjs = importlib.import_module("gc_lang."+sLang+".build") except ImportError: print("# No complementary builder in folder gc_lang/"+sLang) else: - build_module.build(sLang, dVars, spLangPack) + buildjs.build(sLang, dVars, spLangPack) return dVars['version'] def copyGraphspellCore (bJavaScript=False): + "copy Graphspell package in Grammalecte package" helpers.createCleanFolder("grammalecte/graphspell") dir_util.mkpath("grammalecte/graphspell/_dictionaries") for sf in os.listdir("graphspell"): if not os.path.isdir("graphspell/"+sf): file_util.copy_file("graphspell/"+sf, "grammalecte/graphspell") @@ -302,10 +311,11 @@ file_util.copy_file("graphspell-js/"+sf, "grammalecte-js/graphspell") helpers.copyAndFileTemplate("graphspell-js/"+sf, "grammalecte-js/graphspell/"+sf, dVars) def copyGraphspellDictionaries (dVars, bJavaScript=False, bExtendedDict=False, bCommunityDict=False, bPersonalDict=False): + "copy requested Graphspell dictionaries in Grammalecte package" dVars["dic_main_filename_py"] = "" dVars["dic_main_filename_js"] = "" dVars["dic_extended_filename_py"] = "" dVars["dic_extended_filename_js"] = "" dVars["dic_community_filename_py"] = "" @@ -334,16 +344,17 @@ dVars['dic_main_filename_py'] = dVars['dic_default_filename_py'] + ".bdic" dVars['dic_main_filename_js'] = dVars['dic_default_filename_js'] + ".json" def buildDictionary (dVars, sType, bJavaScript=False): + "build binary dictionary for Graphspell from lexicons" if sType == "main": spfLexSrc = dVars['lexicon_src'] - l_sfDictDst = dVars['dic_filenames'].split(",") - l_sDicName = dVars['dic_name'].split(",") - l_sFilter = dVars['dic_filter'].split(",") - for sfDictDst, sDicName, sFilter in zip(l_sfDictDst, l_sDicName, l_sFilter): + lSfDictDst = dVars['dic_filenames'].split(",") + lDicName = dVars['dic_name'].split(",") + lFilter = dVars['dic_filter'].split(",") + for sfDictDst, sDicName, sFilter in zip(lSfDictDst, lDicName, lFilter): lex_build.build(spfLexSrc, dVars['lang'], dVars['lang_name'], sfDictDst, bJavaScript, sDicName, sFilter, dVars['stemming_method'], int(dVars['fsa_method'])) else: if sType == "extended": spfLexSrc = dVars['lexicon_extended_src'] sfDictDst = dVars['dic_extended_filename'] @@ -359,10 +370,11 @@ lex_build.build(spfLexSrc, dVars['lang'], dVars['lang_name'], sfDictDst, bJavaScript, sDicName, "", dVars['stemming_method'], int(dVars['fsa_method'])) def main (): + "build Grammalecte with requested options" print("Python: " + sys.version) xParser = argparse.ArgumentParser() xParser.add_argument("lang", type=str, nargs='+', help="lang project to generate (name of folder in /lang)") xParser.add_argument("-b", "--build_data", help="launch build_data.py (part 1 and 2)", action="store_true") xParser.add_argument("-bb", "--build_data_before", help="launch build_data.py (only part 1: before dictionary building)", action="store_true") @@ -404,29 +416,29 @@ xArgs.add_community_dictionary = False if not dVars["lexicon_personal_src"]: xArgs.add_personal_dictionary = False # build data - build_data_module = None + databuild = None if xArgs.build_data_before or xArgs.build_data_after: # lang data try: - build_data_module = importlib.import_module("gc_lang."+sLang+".build_data") + databuild = importlib.import_module("gc_lang."+sLang+".build_data") except ImportError: print("# Error. Couldn’t import file build_data.py in folder gc_lang/"+sLang) - if build_data_module and xArgs.build_data_before: - build_data_module.before('gc_lang/'+sLang, dVars, xArgs.javascript) + if databuild and xArgs.build_data_before: + databuild.before('gc_lang/'+sLang, dVars, xArgs.javascript) if xArgs.dict: buildDictionary(dVars, "main", xArgs.javascript) if xArgs.add_extended_dictionary: buildDictionary(dVars, "extended", xArgs.javascript) if xArgs.add_community_dictionary: buildDictionary(dVars, "community", xArgs.javascript) if xArgs.add_personal_dictionary: buildDictionary(dVars, "personal", xArgs.javascript) - if build_data_module and xArgs.build_data_after: - build_data_module.after('gc_lang/'+sLang, dVars, xArgs.javascript) + if databuild and xArgs.build_data_after: + databuild.after('gc_lang/'+sLang, dVars, xArgs.javascript) # copy dictionaries from Graphspell copyGraphspellDictionaries(dVars, xArgs.javascript, xArgs.add_extended_dictionary, xArgs.add_community_dictionary, xArgs.add_personal_dictionary) # make @@ -447,16 +459,15 @@ unittest.TextTestRunner().run(xTestSuite) if xArgs.perf or xArgs.perf_memo: hDst = open("./gc_lang/"+sLang+"/perf_memo.txt", "a", encoding="utf-8", newline="\n") if xArgs.perf_memo else None tests.perf(sVersion, hDst) - # Firefox - if False: - # obsolete - with helpers.cd("_build/xpi/"+sLang): - spfFirefox = dVars['win_fx_dev_path'] if platform.system() == "Windows" else dVars['linux_fx_dev_path'] - os.system('jpm run -b "' + spfFirefox + '"') + # Firefox (obsolete) + #if False: + # with helpers.cd("_build/xpi/"+sLang): + # spfFirefox = dVars['win_fx_dev_path'] if platform.system() == "Windows" else dVars['linux_fx_dev_path'] + # os.system('jpm run -b "' + spfFirefox + '"') if xArgs.web_ext or xArgs.firefox: with helpers.cd("_build/webext/"+sLang): if xArgs.lint_web_ext: os.system(r'web-ext lint -o text')