Overview
Comment: | [cli] code cleaning (pylint) |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | cli | rg |
Files: | files | file ages | folders |
SHA3-256: |
90a0252af06511ce112095879e437c59 |
User & Date: | olr on 2018-06-24 16:30:41 |
Other Links: | branch diff | manifest | tags |
Context
2018-06-24
| ||
16:45 | [server] code cleaning (pylint) check-in: 9e6790402a user: olr tags: server, rg | |
16:30 | [cli] code cleaning (pylint) check-in: 90a0252af0 user: olr tags: cli, rg | |
16:25 | [build] darg: code cleaning (pylint) check-in: ac1f358667 user: olr tags: build, rg | |
Changes
Modified grammalecte-cli.py from [3cad321446] to [6896e640a6].
1 2 3 4 5 6 7 8 | #!/usr/bin/env python3 import sys import os.path import argparse import json import grammalecte | > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 | #!/usr/bin/env python3 """ Grammalecte CLI (command line interface) """ import sys import os.path import argparse import json import grammalecte |
︙ | ︙ | |||
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | iParagraph += 1 if lLine: sText, lLineSet = txt.createParagraphWithLines(lLine) yield iParagraph, sText, lLineSet def output (sText, hDst=None): if not hDst: echo(sText, end="") else: hDst.write(sText) def main (): xParser = argparse.ArgumentParser() xParser.add_argument("-f", "--file", help="parse file (UTF-8 required!) [on Windows, -f is similar to -ff]", type=str) xParser.add_argument("-ff", "--file_to_file", help="parse file (UTF-8 required!) and create a result file (*.res.txt)", type=str) xParser.add_argument("-owe", "--only_when_errors", help="display results only when there are errors", action="store_true") xParser.add_argument("-j", "--json", help="generate list of errors in JSON (only with option --file or --file_to_file)", action="store_true") xParser.add_argument("-cl", "--concat_lines", help="concatenate lines not separated by an empty paragraph (only with option --file or --file_to_file)", action="store_true") xParser.add_argument("-tf", "--textformatter", help="auto-format text according to typographical rules (not with option --concat_lines)", action="store_true") | > > | 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 | iParagraph += 1 if lLine: sText, lLineSet = txt.createParagraphWithLines(lLine) yield iParagraph, sText, lLineSet def output (sText, hDst=None): "write in the console or in a file if <hDst> not null" if not hDst: echo(sText, end="") else: hDst.write(sText) def main (): "launch the CLI (command line interface)" xParser = argparse.ArgumentParser() xParser.add_argument("-f", "--file", help="parse file (UTF-8 required!) [on Windows, -f is similar to -ff]", type=str) xParser.add_argument("-ff", "--file_to_file", help="parse file (UTF-8 required!) and create a result file (*.res.txt)", type=str) xParser.add_argument("-owe", "--only_when_errors", help="display results only when there are errors", action="store_true") xParser.add_argument("-j", "--json", help="generate list of errors in JSON (only with option --file or --file_to_file)", action="store_true") xParser.add_argument("-cl", "--concat_lines", help="concatenate lines not separated by an empty paragraph (only with option --file or --file_to_file)", action="store_true") xParser.add_argument("-tf", "--textformatter", help="auto-format text according to typographical rules (not with option --concat_lines)", action="store_true") |
︙ | ︙ | |||
211 212 213 214 215 216 217 | oGrammarChecker.gce.ignoreRule(sRule) echo("done") elif sText.startswith("/++ "): for sRule in sText[3:].strip().split(): oGrammarChecker.gce.reactivateRule(sRule) echo("done") elif sText == "/debug" or sText == "/d": | | | | | | 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 | oGrammarChecker.gce.ignoreRule(sRule) echo("done") elif sText.startswith("/++ "): for sRule in sText[3:].strip().split(): oGrammarChecker.gce.reactivateRule(sRule) echo("done") elif sText == "/debug" or sText == "/d": xArgs.debug = not xArgs.debug echo("debug mode on" if xArgs.debug else "debug mode off") elif sText == "/textformatter" or sText == "/tf": xArgs.textformatter = not xArgs.textformatter echo("textformatter on" if xArgs.debug else "textformatter off") elif sText == "/help" or sText == "/h": echo(_HELP) elif sText == "/lopt" or sText == "/lo": oGrammarChecker.gce.displayOptions("fr") elif sText.startswith("/lr"): sText = sText.strip() sFilter = sText[sText.find(" "):].strip() if sText != "/lr" and sText != "/rules" else None oGrammarChecker.gce.displayRules(sFilter) elif sText == "/quit" or sText == "/q": break elif sText.startswith("/rl"): # reload (todo) pass else: for sParagraph in txt.getParagraph(sText): if xArgs.textformatter: sText = oTextFormatter.formatText(sParagraph) sRes = oGrammarChecker.generateParagraph(sParagraph, bEmptyIfNoErrors=xArgs.only_when_errors, nWidth=xArgs.width, bDebug=xArgs.debug) if sRes: echo("\n" + sRes) else: echo("\nNo error found.") sText = _getText(sInputText) if __name__ == '__main__': main() |