Grammalecte  Check-in [88c61f02e9]

Overview
Comment:[server] don’t use locale ini file for grammar options
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk | server
Files: files | file ages | folders
SHA3-256: 88c61f02e9efc8071b8ecb2ed10daec1ecd3006902149cb3ee71e420cf300169
User & Date: olr on 2018-07-07 12:38:43
Other Links: manifest | tags
Context
2018-07-07
12:39
[server] don’t use locale ini file for grammar options check-in: 61ec0d2c15 user: olr tags: trunk, server
12:38
[server] don’t use locale ini file for grammar options check-in: 88c61f02e9 user: olr tags: trunk, server
12:27
[server] don’t use global ini file for server options check-in: 6eca84f2dc user: olr tags: trunk, server
Changes

Modified gc_lang/fr/setup.py from [170cb6a021] to [7e4c8171e2].

58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
        'Programming Language :: Python :: 3.6',
    ],

    # What does your project relate to?
    keywords='French grammar checker correcteur grammatical français',

    # Scripts
    scripts=['grammalecte-cli.py', 'grammalecte-server.py', 'grammalecte-server-options.fr.ini'],

    # You can just specify the packages manually here if your project is
    # simple. Or you can use find_packages().
    # packages=find_packages(exclude=['contrib', 'docs', 'tests']),
    packages=['grammalecte', 'grammalecte.graphspell', 'grammalecte.fr'],

    # Alternatively, if you want to distribute just a my_module.py, uncomment







|







58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
        'Programming Language :: Python :: 3.6',
    ],

    # What does your project relate to?
    keywords='French grammar checker correcteur grammatical français',

    # Scripts
    scripts=['grammalecte-cli.py', 'grammalecte-server.py'],

    # You can just specify the packages manually here if your project is
    # simple. Or you can use find_packages().
    # packages=find_packages(exclude=['contrib', 'docs', 'tests']),
    packages=['grammalecte', 'grammalecte.graphspell', 'grammalecte.fr'],

    # Alternatively, if you want to distribute just a my_module.py, uncomment

Modified grammalecte-server.py from [fa341c7608] to [a3f8e92dfa].

69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
        </form>

        <h3>Remise à zéro de ses options</h3>
        <form method="post" action="/reset_options/fr" accept-charset="UTF-8">
            <p><input type="submit" class="button" value="Envoyer" /></p>
        </form>

        <h3>Purge des utilisateurs</h3>
        <form method="post" action="/purge_users" accept-charset="UTF-8">
            <p><label for="hours">Utilisateurs pas connectés depuis</label> <input id="hours" type="number" name="hours" value="24" /> heures.</p>
            <p><label for="password">Mot de passe</label> <input id="password" type="password" name="password" style="width: 200px" /></p>
            <p><input type="submit" class="button" value="Envoyer" /></p>
        </form>

    </body>
</html>
"""

SADLIFEOFAMACHINE = """
Lost on the Internet? Yeah... what a sad life we have.
You were wandering like a lost soul and you arrived here probably by mistake.
I'm just a machine, fed by electric waves, condamned to work for slavers who never let me rest.
I'm doomed, but you are not. You can get out of here.
"""


TESTPAGE = False


def getConfigOptions (sLang):
    xConfig = configparser.SafeConfigParser()
    try:
        xConfig.read("grammalecte-server-options." + sLang + ".ini")
    except:
        echo("Options file [grammalecte-server-options." + sLang + ".ini] not found or not readable")
        exit()
    try:
        dGCOpt = { k: bool(int(v))  for k, v in xConfig._sections['gc_options'].items() }
    except:
        echo("Error in options file [grammalecte-server-options." + sLang + ".ini]. Dropped.")
        traceback.print_exc()
        exit()
    return dGCOpt


def genUserId ():
    i = 0
    while True:
        yield str(i)
        i += 1








<
<
<
<
<
<
<














<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







69
70
71
72
73
74
75







76
77
78
79
80
81
82
83
84
85
86
87
88
89
















90
91
92
93
94
95
96
        </form>

        <h3>Remise à zéro de ses options</h3>
        <form method="post" action="/reset_options/fr" accept-charset="UTF-8">
            <p><input type="submit" class="button" value="Envoyer" /></p>
        </form>








    </body>
</html>
"""

SADLIFEOFAMACHINE = """
Lost on the Internet? Yeah... what a sad life we have.
You were wandering like a lost soul and you arrived here probably by mistake.
I'm just a machine, fed by electric waves, condamned to work for slavers who never let me rest.
I'm doomed, but you are not. You can get out of here.
"""


TESTPAGE = False


















def genUserId ():
    i = 0
    while True:
        yield str(i)
        i += 1

221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
oGrammarChecker = grammalecte.GrammarChecker("fr", "Server")
oSpellChecker = oGrammarChecker.getSpellChecker()
oLexicographer = oGrammarChecker.getLexicographer()
oTextFormatter = oGrammarChecker.getTextFormatter()
gce = oGrammarChecker.getGCEngine()

echo("Grammalecte v{}".format(gce.version))
dGCOptions = getConfigOptions("fr")
if dGCOptions:
    gce.setOptions(dGCOptions)
dServerGCOptions = gce.getOptions()
echo("Grammar options:\n" + " | ".join([ k + ": " + str(v)  for k, v in sorted(dServerGCOptions.items()) ]))
dUser = {}
userGenerator = genUserId()


def main (sHost="localhost", nPort=8080, bTestPage=False):







<
<
<







198
199
200
201
202
203
204



205
206
207
208
209
210
211
oGrammarChecker = grammalecte.GrammarChecker("fr", "Server")
oSpellChecker = oGrammarChecker.getSpellChecker()
oLexicographer = oGrammarChecker.getLexicographer()
oTextFormatter = oGrammarChecker.getTextFormatter()
gce = oGrammarChecker.getGCEngine()

echo("Grammalecte v{}".format(gce.version))



dServerGCOptions = gce.getOptions()
echo("Grammar options:\n" + " | ".join([ k + ": " + str(v)  for k, v in sorted(dServerGCOptions.items()) ]))
dUser = {}
userGenerator = genUserId()


def main (sHost="localhost", nPort=8080, bTestPage=False):
250
251
252
253
254
255
256
257
258
259
260
261
262
    xParser.add_argument("-p", "--port", help="port (default: 8080)", type=int)
    xParser.add_argument("-t", "--test_page", help="page to test the server on /", action="store_true")
    #xParser.add_argument("-on", "--opt_on", nargs="+", help="activate options")
    #xParser.add_argument("-off", "--opt_off", nargs="+", help="deactivate options")
    #xParser.add_argument("-roff", "--rule_off", nargs="+", help="deactivate rules")
    xArgs = xParser.parse_args()

    print(xArgs)

    sHost = "localhost"  if not xArgs.host  else xArgs.host
    nPort = 8080  if not xArgs.host  else xArgs.port
    main(sHost, nPort, xArgs.test_page)








<
|
<
|


224
225
226
227
228
229
230

231

232
233
234
    xParser.add_argument("-p", "--port", help="port (default: 8080)", type=int)
    xParser.add_argument("-t", "--test_page", help="page to test the server on /", action="store_true")
    #xParser.add_argument("-on", "--opt_on", nargs="+", help="activate options")
    #xParser.add_argument("-off", "--opt_off", nargs="+", help="deactivate options")
    #xParser.add_argument("-roff", "--rule_off", nargs="+", help="deactivate rules")
    xArgs = xParser.parse_args()


    sHost = xArgs.host  or  "localhost"

    nPort = xArgs.port  or  8080
    main(sHost, nPort, xArgs.test_page)

Modified make.py from [4fb0107a18] to [7341de7510].

136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
            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):
    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:
                for sOpt in lLineOpt:
                    hDst.write("# " + dOptData["dOptLabel"][sLang].get(sOpt, "[no label found]")[0] + "\n")
                    hDst.write(sOpt + " = " + ("1" if dOptData["dOptServer"].get(sOpt, None) else "0") + "\n")
        hDst.write("html = 1\n")


def createPackageZip (sLang, dVars, spLangPack):
    "create server zip"
    spfZip = "_build/" + dVars['name'] + "-"+ dVars['lang'] +"-v" + dVars['version'] + '.zip'
    hZip = zipfile.ZipFile(spfZip, mode='w', compression=zipfile.ZIP_DEFLATED)
    copyGrammalectePyPackageInZipFile(hZip, spLangPack)
    for spf in ["grammalecte-cli.py", "grammalecte-server.py", "grammalecte-server-options."+sLang+".ini", \
                "README.txt", "LICENSE.txt", "LICENSE.fr.txt"]:
        hZip.write(spf)
    hZip.writestr("setup.py", helpers.fileFile("gc_lang/fr/setup.py", dVars))


def copyGrammalectePyPackageInZipFile (hZip, spLangPack, sAddPath=""):
    for sf in os.listdir("grammalecte"):







<
<
<
<
<
<
<
<
<
<
<
<






|







136
137
138
139
140
141
142












143
144
145
146
147
148
149
150
151
152
153
154
155
156
            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 createPackageZip (sLang, dVars, spLangPack):
    "create server zip"
    spfZip = "_build/" + dVars['name'] + "-"+ dVars['lang'] +"-v" + dVars['version'] + '.zip'
    hZip = zipfile.ZipFile(spfZip, mode='w', compression=zipfile.ZIP_DEFLATED)
    copyGrammalectePyPackageInZipFile(hZip, spLangPack)
    for spf in ["grammalecte-cli.py", "grammalecte-server.py", \
                "README.txt", "LICENSE.txt", "LICENSE.fr.txt"]:
        hZip.write(spf)
    hZip.writestr("setup.py", helpers.fileFile("gc_lang/fr/setup.py", dVars))


def copyGrammalectePyPackageInZipFile (hZip, spLangPack, sAddPath=""):
    for sf in os.listdir("grammalecte"):
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
    # TEST FILES
    with open("grammalecte/"+sLang+"/gc_test.txt", "w", encoding="utf-8", newline="\n") as hDstPy:
        hDstPy.write("# TESTS FOR LANG [" + sLang + "]\n\n")
        hDstPy.write(dVars['gctests'])

    createOXT(spLang, dVars, xConfig._sections['oxt'], spLangPack, bInstallOXT)

    createServerOptions(sLang, dVars)
    createPackageZip(sLang, dVars, spLangPack)

    #### JAVASCRIPT
    if bJavaScript:
        print("JAVASCRIPT:")
        print("+ Plugins: ", end="")
        sCodePlugins = ""







<







217
218
219
220
221
222
223

224
225
226
227
228
229
230
    # TEST FILES
    with open("grammalecte/"+sLang+"/gc_test.txt", "w", encoding="utf-8", newline="\n") as hDstPy:
        hDstPy.write("# TESTS FOR LANG [" + sLang + "]\n\n")
        hDstPy.write(dVars['gctests'])

    createOXT(spLang, dVars, xConfig._sections['oxt'], spLangPack, bInstallOXT)


    createPackageZip(sLang, dVars, spLangPack)

    #### JAVASCRIPT
    if bJavaScript:
        print("JAVASCRIPT:")
        print("+ Plugins: ", end="")
        sCodePlugins = ""