Index: grammalecte-cli.py ================================================================== --- grammalecte-cli.py +++ grammalecte-cli.py @@ -152,13 +152,13 @@ xArgs.textformatter = False # grammar options oGrammarChecker.gce.setOptions({"html": True, "latex": True}) if xArgs.opt_on: - oGrammarChecker.gce.setOptions({ opt:True for opt in xArgs.opt_on if opt in oGrammarChecker.gce.getOptions() }) + oGrammarChecker.gce.setOptions({ opt:True for opt in xArgs.opt_on }) if xArgs.opt_off: - oGrammarChecker.gce.setOptions({ opt:False for opt in xArgs.opt_off if opt in oGrammarChecker.gce.getOptions() }) + oGrammarChecker.gce.setOptions({ opt:False for opt in xArgs.opt_off }) # disable grammar rules if xArgs.rule_off: for sRule in xArgs.rule_off: oGrammarChecker.gce.ignoreRule(sRule) Index: grammalecte-server.py ================================================================== --- grammalecte-server.py +++ grammalecte-server.py @@ -106,11 +106,11 @@ return SADLIFEOFAMACHINE @app.route("/get_options/fr") def listOptions (): sUserId = request.cookies.user_id - dOptions = dUser[sUserId]["gc_options"] if sUserId and sUserId in dUser else dServerGCOptions + dOptions = dUser[sUserId]["gc_options"] if sUserId and sUserId in dUser else dGCOptions return '{ "values": ' + json.dumps(dOptions) + ', "labels": ' + json.dumps(gce.getOptionsLabels("fr"), ensure_ascii=False) + ' }' # POST @app.route("/gc_text/fr", method="POST") @@ -126,11 +126,11 @@ response.set_cookie("user_id", request.cookies.user_id, path="/", max_age=86400) # we renew cookie for 24h else: response.delete_cookie("user_id", path="/") if request.forms.options: try: - dOptions = dict(dServerGCOptions) if not dOptions else dict(dOptions) + dOptions = dict(dGCOptions) if not dOptions else dict(dOptions) dOptions.update(json.loads(request.forms.options)) except: sError = "request options not used" sJSON = '{ "program": "grammalecte-fr", "version": "'+gce.version+'", "lang": "'+gce.lang+'", "error": "'+sError+'", "data" : [\n' for i, sText in enumerate(txt.getParagraph(request.forms.text), 1): @@ -147,11 +147,11 @@ @app.route("/set_options/fr", method="POST") def setOptions (): if request.forms.options: sUserId = request.cookies.user_id if request.cookies.user_id else next(userGenerator) - dOptions = dUser[sUserId]["gc_options"] if sUserId in dUser else dict(dServerGCOptions) + dOptions = dUser[sUserId]["gc_options"] if sUserId in dUser else dict(dGCOptions) try: dOptions.update(json.loads(request.forms.options)) dUser[sUserId] = { "time": int(time.time()), "gc_options": dOptions } response.set_cookie("user_id", sUserId, path="/", max_age=86400) # 24h return json.dumps(dUser[sUserId]["gc_options"]) @@ -199,36 +199,49 @@ 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()) ])) +dGCOptions = gce.getOptions() dUser = {} userGenerator = genUserId() -def main (sHost="localhost", nPort=8080, bTestPage=False): +def main (sHost="localhost", nPort=8080, dOptions=None, bTestPage=False): # start server - print("Python: " + sys.version) + global dGCOptions + global TESTPAGE + if bTestPage: - global TESTPAGE TESTPAGE = True + if dOptions: + oGrammarChecker.gce.setOptions(dOptions) + dGCOptions = gce.getOptions() + + print("Python: " + sys.version) + echo("Grammalecte v{}".format(gce.version)) + echo("Grammar options:\n" + " | ".join([ k + ": " + str(v) for k, v in sorted(dGCOptions.items()) ])) run(app, host=sHost, port=nPort) + if __name__ == '__main__': xParser = argparse.ArgumentParser() #xParser.add_argument("lang", type=str, nargs='+', help="lang project to generate (name of folder in /lang)") xParser.add_argument("-ht", "--host", help="host (default: localhost)", type=str) 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") + xParser.add_argument("-on", "--opt_on", nargs="+", help="activate options") + xParser.add_argument("-off", "--opt_off", nargs="+", help="deactivate options") xArgs = xParser.parse_args() + dOpt = None + if xArgs.opt_on or xArgs.opt_off: + dOpt = {} + if xArgs.opt_on: + dOpt = { opt:True for opt in xArgs.opt_on } + if xArgs.opt_off: + dOpt.update({ opt:False for opt in xArgs.opt_off }) + sHost = xArgs.host or "localhost" nPort = xArgs.port or 8080 - main(sHost, nPort, xArgs.test_page) - + main(sHost, nPort, dOpt, xArgs.test_page)