Grammalecte  Check-in [3ecdf872a2]

Overview
Comment:[build][fr] useless to use os.makedirs via a function
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | trunk | fr | build
Files: files | file ages | folders
SHA3-256: 3ecdf872a25e67b49e19bb9968be23e04abef7fcfc1dc923dec60b44233e6f94
User & Date: olr on 2025-11-24 17:52:47
Other Links: manifest | tags
Context
2025-11-24
17:52
[build][fr] useless to use os.makedirs via a function Leaf check-in: 3ecdf872a2 user: olr tags: trunk, fr, build
17:40
[build][fr] create folders recursively check-in: fc398bebae user: olr tags: trunk, fr, build
Changes

Modified gc_lang/fr/dictionnaire/genfrdic.py from [48e0746ca6] to [fce132f18a].

191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
191
192
193
194
195
196
197






198
199
200
201
202
203
204







-
-
-
-
-
-







    if os.path.isfile(spf):
        with open(spf, "r", encoding="utf-8") as hSrc:
            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
        self.lEntry = []
        self.nEntry = 0
526
527
528
529
530
531
532
533

534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552




553
554
555
556
557
558
559
520
521
522
523
524
525
526

527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542




543
544
545
546
547
548
549
550
551
552
553







-
+















-
-
-
-
+
+
+
+







            hDst.write(Flexion.simpleHeader())
            for oFlex in self.lFlexions:
                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)
            self.writeDictionary(spDic, dVars, nMode, bSimplified)
        copyTemplate('orthographe', spDic, 'README_dict_fr.txt', dVars)
        createZipFiles(spDic, spDst, sDicName + '.zip')

    def createLibreOfficeExtension (self, spBuild, dTplVars, lDictVars, sThesVer, spDestGL=""):
        # 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)
        shutil.copy2('_templates/ooo/french_flag_16.bmp', spExt+'/ui')
        copyTemplate('_templates/ooo', spExt, 'description.xml', dTplVars)
585
586
587
588
589
590
591
592

593
594
595
596
597
598
599
579
580
581
582
583
584
585

586
587
588
589
590
591
592
593







-
+








    def createMozillaExtensions (self, spBuild, dTplVars, lDictVars, spDestGL=""):
        # 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)
        createZipFiles(spExt, spBuild, sExtensionName + '.xpi')
        # Grammalecte
611
612
613
614
615
616
617
618

619
620
621
622
623
624
625
605
606
607
608
609
610
611

612
613
614
615
616
617
618
619







-
+







                if oEntry.fq != oEntry.oldFq:
                    hDiff.write("{0.iD}\t{0.fq}\n".format(oEntry))
                    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})
        # zip
        createZipFiles(spLex, spBuild, sLexName + '.zip')
1412
1413
1414
1415
1416
1417
1418
1419

1420
1421
1422
1423
1424
1425
1426
1406
1407
1408
1409
1410
1411
1412

1413
1414
1415
1416
1417
1418
1419
1420







-
+







            for e in self.dFlexions.items():
                hDst.write("{} - {}\n".format(e[0], e[1]))


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)
        shutil.copy2(spThesaurus+'/thes_fr.dat', spCopy)
        shutil.copy2(spThesaurus+'/thes_fr.idx', spCopy)
1447
1448
1449
1450
1451
1452
1453
1454

1455
1456
1457
1458
1459
1460
1461
1441
1442
1443
1444
1445
1446
1447

1448
1449
1450
1451
1452
1453
1454
1455







-
+







    echo("Version: " + xArgs.verdic)
    echo("Simplify: " + str(xArgs.simplify))
    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)
    oFrenchDict.readAffixes('orthographe/FRANCAIS_7.aff')

Modified helpers.py from [82e1f566c6] to [3b783d8a38].

72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
72
73
74
75
76
77
78






79
80
81
82
83
84
85







-
-
-
-
-
-







def createCleanFolder (sp):
    "make an empty folder or erase its content if not empty"
    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)
    except OSError as e:
        if e.errno == errno.ENOTDIR:

Modified lex_build.py from [f032803b08] to [a97d060e85].

1
2
3
4
5
6
7
8

9
10
11
12
13
14
15
16

17
18
19

20
21
22
23
24
25
26
1
2
3
4
5
6
7

8
9
10
11
12
13
14
15

16
17
18

19
20
21
22
23
24
25
26







-
+







-
+


-
+







#!python3

"""
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"
    xParser = argparse.ArgumentParser()
    xParser.add_argument("src_lexicon", type=str, help="path and file name of the source lexicon")

Modified make.py from [a2a625b112] to [78c9ddad51].

281
282
283
284
285
286
287
288

289
290
291
292
293
294

295
296
297
298
299
300
301
281
282
283
284
285
286
287

288
289
290
291
292
293

294
295
296
297
298
299
300
301







-
+





-
+







    return dVars['version']


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):
                shutil.copy2("graphspell-js/"+sf, "grammalecte-js/graphspell")
                helpers.copyAndFileTemplate("graphspell-js/"+sf, "grammalecte-js/graphspell/"+sf, dVars)
417
418
419
420
421
422
423
424
425


426
427

428
429
430
431
432
433
434
417
418
419
420
421
422
423


424
425
426

427
428
429
430
431
432
433
434







-
-
+
+

-
+







    oNow = datetime.datetime.now()
    print("============== MAKE GRAMMALECTE at {0.hour:>2} h {0.minute:>2} min {0.second:>2} s ==============".format(oNow))

    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):
            xConfig = getConfig(sLang)
            dVars = xConfig._sections['args']