Index: gc_lang/fr/dictionnaire/genfrdic.py ================================================================== --- gc_lang/fr/dictionnaire/genfrdic.py +++ gc_lang/fr/dictionnaire/genfrdic.py @@ -193,16 +193,10 @@ for sLine in hSrc: yield sLine else: print("# Error: file not found.") - -def createFolder (sp): - "make a folder if it doesn’t exist; don’t change anything if it exists" - if not os.path.exists(sp): - os.makedirs(sp, exist_ok=True) - class Dictionnaire: def __init__ (self, version, name): # Dictionary self.sName = name @@ -528,11 +522,11 @@ hDst.write(oFlex.getGrammarCheckerRepr()) def createFiles (self, spDst, lDictVars, nMode, bSimplified): sDicName = PREFIX_DICT_PATH + self.sVersion spDic = spDst + '/' + sDicName - createFolder(spDic) + os.makedirs(spDic, exist_ok=True) for dVars in lDictVars: # template vars dVars['version'] = self.sVersion # Dictionaries files (.dic) (.aff) self.writeAffixes(spDic, dVars, nMode, bSimplified) @@ -544,14 +538,14 @@ # LibreOffice extension echo(" * Dictionnaire >> extension pour LibreOffice") dTplVars['version'] = self.sVersion sExtensionName = EXT_PREFIX_OOO + self.sVersion spExt = spBuild + '/' + sExtensionName - createFolder(spExt+'/META-INF') - createFolder(spExt+'/ui') - createFolder(spExt+'/dictionaries') - createFolder(spExt+'/pythonpath') + os.makedirs(spExt+'/META-INF', exist_ok=True) + os.makedirs(spExt+'/ui', exist_ok=True) + os.makedirs(spExt+'/dictionaries', exist_ok=True) + os.makedirs(spExt+'/pythonpath', exist_ok=True) shutil.copy2('_templates/ooo/manifest.xml', spExt+'/META-INF') shutil.copy2('_templates/ooo/DictionarySwitcher.py', spExt) shutil.copy2('_templates/ooo/ds_strings.py', spExt+'/pythonpath') shutil.copy2('_templates/ooo/addons.xcu', spExt+'/ui') shutil.copy2('_templates/ooo/french_flag.png', spExt) @@ -587,11 +581,11 @@ # Mozilla extension 1 echo(" * Dictionnaire >> extension pour Mozilla") dTplVars['version'] = self.sVersion sExtensionName = EXT_PREFIX_MOZ + self.sVersion spExt = spBuild + '/' + sExtensionName - createFolder(spExt+'/dictionaries') + os.makedirs(spExt+'/dictionaries', exist_ok=True) copyTemplate('_templates/moz', spExt, 'manifest.json', dTplVars) spDict = spBuild + '/' + PREFIX_DICT_PATH + self.sVersion shutil.copy2(spDict+'/fr-classique.dic', spExt+'/dictionaries/fr-classic.dic') shutil.copy2(spDict+'/fr-classique.aff', spExt+'/dictionaries/fr-classic.aff') copyTemplate('orthographe', spExt, 'README_dict_fr.txt', dTplVars) @@ -613,11 +607,11 @@ hNotes.write("{0.lemma}/{0.flags}\t{0.oldFq} > {0.fq}\n".format(oEntry)) def createLexiconPackages (self, spBuild, version, oStatsLex, spDestGL=""): sLexName = LEX_PREFIX + version spLex = spBuild + '/' + sLexName - createFolder(spLex) + os.makedirs(spLex, exist_ok=True) # write lexicon self.sortLexiconByFreq() self.writeLexicon(spLex + '/' + sLexName + '.txt', version, oStatsLex) self.writeGrammarCheckerLexicon(spBuild + '/' + sLexName + '.lex', version) copyTemplate('lexique', spLex, 'README_lexique.txt', {'version': version}) @@ -1414,11 +1408,11 @@ def createThesaurusPackage (spBuild, sVersion, spCopy="", spDataDestGL=""): print(" * Création du thésaurus") spThesaurus = spBuild+"/thesaurus-v"+sVersion - createFolder(spThesaurus) + os.makedirs(spThesaurus, exist_ok=True) thes_build.build("thesaurus/thes_fr.dat", "thesaurus/synsets_fr.dat", spThesaurus) shutil.copy2('thesaurus/README_thes_fr.txt', spThesaurus) if spCopy: # copy in libreoffice extension package print(" Copie du thésaurus dans:", spCopy) @@ -1449,11 +1443,11 @@ echo("Mode: " + str(xArgs.mode)) echo("Compression: " + str(not(xArgs.uncompress))) ### création du répertoire spBuild = BUILD_PATH + '/' + xArgs.verdic - createFolder(spBuild) + os.makedirs(spBuild, exist_ok=True) ### Lecture des fichiers et création du dictionnaire oFrenchDict = Dictionnaire(xArgs.verdic, "French dictionary") for sFile in ['orthographe/FRANCAIS.dic']: oFrenchDict.readDictionary(sFile) Index: helpers.py ================================================================== --- helpers.py +++ helpers.py @@ -74,16 +74,10 @@ if not os.path.exists(sp): os.makedirs(sp, exist_ok=True) else: eraseFolderContent(sp) - -def createFolder (sp): - "make a folder if it doesn’t exist; don’t change anything if it exists" - if not os.path.exists(sp): - os.makedirs(sp, exist_ok=True) - def copyFolder (spSrc, spDst): "copy folder content from src to dst" try: shutil.copytree(spSrc, spDst) Index: lex_build.py ================================================================== --- lex_build.py +++ lex_build.py @@ -3,22 +3,22 @@ """ Lexicon builder """ import argparse -import helpers +import os import graphspell.dawg as fsa def build (spfSrc, sLangCode, sLangName, sfDict, bJavaScript=False, sDicName="", sDescription="", sFilter="", cStemmingMethod="S", nCompressMethod=1): "transform a text lexicon as a binary indexable dictionary" oDAWG = fsa.DAWG(spfSrc, cStemmingMethod, sLangCode, sLangName, sDicName, sDescription, sFilter) - helpers.createFolder("graphspell/_dictionaries") + os.makedirs("graphspell/_dictionaries", exist_ok=True) oDAWG.writeAsJSObject("graphspell/_dictionaries/" + sfDict + ".json") if bJavaScript: - helpers.createFolder("graphspell-js/_dictionaries") + os.makedirs("graphspell-js/_dictionaries", exist_ok=True) oDAWG.writeAsJSObject("graphspell-js/_dictionaries/" + sfDict + ".json") def main (): "parse args from CLI" Index: make.py ================================================================== --- make.py +++ make.py @@ -283,17 +283,17 @@ def copyGraphspellCore (bJavaScript=False): "copy Graphspell package in Grammalecte package" print("> Copy Graphspell package in Grammalecte package") helpers.createCleanFolder("grammalecte/graphspell") - helpers.createFolder("grammalecte/graphspell/_dictionaries") + os.makedirs("grammalecte/graphspell/_dictionaries", exist_ok=True) for sf in os.listdir("graphspell"): if not os.path.isdir("graphspell/"+sf): shutil.copy2("graphspell/"+sf, "grammalecte/graphspell") if bJavaScript: helpers.createCleanFolder("grammalecte-js/graphspell") - helpers.createFolder("grammalecte-js/graphspell/_dictionaries") + os.makedirs("grammalecte-js/graphspell/_dictionaries", exist_ok=True) dVars = {} for sf in os.listdir("js_extension"): dVars[sf[:-3]] = open("js_extension/"+sf, "r", encoding="utf-8").read() for sf in os.listdir("graphspell-js"): if not os.path.isdir("graphspell-js/"+sf): @@ -419,14 +419,14 @@ if xArgs.build_data: xArgs.build_data_before = True xArgs.build_data_after = True - helpers.createFolder("_build") - helpers.createFolder("grammalecte") + os.makedirs("_build", exist_ok=True) + os.makedirs("grammalecte", exist_ok=True) if xArgs.javascript: - helpers.createFolder("grammalecte-js") + os.makedirs("grammalecte-js", exist_ok=True) copyGraphspellCore(xArgs.javascript) for sLang in xArgs.lang: if os.path.exists("gc_lang/"+sLang) and os.path.isdir("gc_lang/"+sLang):