From 38c82a2af1bd883e23c387a44875c751af8314cd Mon Sep 17 00:00:00 2001 From: eckhart Date: Sun, 7 Jun 2020 15:38:05 +0200 Subject: [PATCH] DHParser/templates/DSLServer.pyi updated, so it reflects latest changes in examples/EBNF/EBNFServer.py --- DHParser/log.py | 4 +++- DHParser/server.py | 18 ++++++++++++++---- DHParser/templates/DSLServer.pyi | 13 ++++++++----- examples/EBNF/EBNF.ebnf | 4 +--- examples/EBNF/EBNFServer.py | 13 ++++++++----- .../vscode_support/client/src/extension.ts | 2 +- examples/EBNF/vscode_support/package-lock.json | 14 +++++++------- 7 files changed, 42 insertions(+), 26 deletions(-) diff --git a/DHParser/log.py b/DHParser/log.py index 84eda38..b3ecba5 100644 --- a/DHParser/log.py +++ b/DHParser/log.py @@ -199,6 +199,8 @@ def create_log(log_name: str) -> str: if not ldir: ldir = log_dir() if ldir: + if not os.path.exists(ldir): + os.makedirs(ldir) with open(os.path.join(ldir, file_name), 'w', encoding='utf-8') as f: f.write('LOG-FILE: ' + log_name + '\n\n') return log_name @@ -219,7 +221,7 @@ def append_log(log_name: str, *strings, echo: bool = False) -> None: :param echo: If True, the log message will be echoed on the terminal. This will also happen if logging is turned off. """ - ldir, _ = os.path.split(log_name) + ldir, log_name = os.path.split(log_name) if not ldir: ldir = log_dir() if ldir and log_name: diff --git a/DHParser/server.py b/DHParser/server.py index 94a6c05..f9a437e 100644 --- a/DHParser/server.py +++ b/DHParser/server.py @@ -754,10 +754,19 @@ class Server: # self.known_methods.add(name) def start_logging(self, filename: str = "") -> str: - if not filename: - filename = self.server_name + '_' + hex(id(self))[2:] + '.log' - if not log_dir(): - filename = os.path.join('.', filename) + """Starts logging to a file. If `filename` is void or a directory + an auto-generated file name will be used. The file will be written + to the standard log-dir, unless a path is specified in filename.""" + def log_name(): + """Returns an auto-generated log-name.""" + return self.server_name + '_' + hex(id(self))[2:] + '.log' + if os.path.isdir(filename) or filename.endswith(os.path.sep): + filename = os.path.join(filename, log_name()) + else: + if not filename: + filename = log_name() + if not os.path.dirname(filename) and not log_dir(): + filename = os.path.join('.', filename) self.log_file = create_log(filename) if self.log_file: self.log('Python Version: %s\nDHParser Version: %s\n\n' @@ -766,6 +775,7 @@ class Server: return 'Unable to write log-file: "%s"' % filename def stop_logging(self): + """Stops logging.""" if self.log_file: self.log('Logging will be stopped now!') ret = 'Stopped logging to file: "%s"' % self.log_file diff --git a/DHParser/templates/DSLServer.pyi b/DHParser/templates/DSLServer.pyi index dfd1f12..f983744 100644 --- a/DHParser/templates/DSLServer.pyi +++ b/DHParser/templates/DSLServer.pyi @@ -406,17 +406,17 @@ async def start_server_daemon(host, port, requests) -> list: def parse_logging_args(args): - if args.logging: - echo = repr('ECHO_ON') if args.startserver else repr('ECHO_OFF') + if args.logging or args.logging is None: + echo = repr('ECHO_ON') if isinstance(args.startserver, list) else repr('ECHO_OFF') if args.logging in ('OFF', 'STOP', 'NO', 'FALSE'): log_path = repr(None) echo = repr('ECHO_OFF') elif args.logging in ('ON', 'START', 'YES', 'TRUE'): log_path = repr('') else: - log_path = args.logging + log_path = repr('') if args.logging is None else repr(args.logging) request = LOGGING_REQUEST.replace('""', ", ".join((log_path, echo))) - debug('Logging to file %s with call %s' % (repr(log_path), request)) + debug('Logging to %s with call %s' % (log_path, request)) return log_path, request else: return None, '' @@ -439,11 +439,14 @@ if __name__ == "__main__": help='host name or IP-address of the server (default: 127.0.0.1)') parser.add_argument('-p', '--port', nargs=1, type=int, default=[-1], help='port number of the server (default:8888)') - parser.add_argument('-l', '--logging', nargs='?', metavar="ON|LOG_DIR|OFF", + parser.add_argument('-l', '--logging', nargs='?', metavar="ON|LOG_DIR|OFF", default='', help='turns logging on (default) or off or writes log to a ' 'specific directory (implies on)') + parser.add_argument('-b', '--debug', action='store_true', help="debug messages") args = parser.parse_args() + if args.debug: + DEBUG = True host = args.host[0] port = int(args.port[0]) diff --git a/examples/EBNF/EBNF.ebnf b/examples/EBNF/EBNF.ebnf index f1f54e0..8b09d56 100644 --- a/examples/EBNF/EBNF.ebnf +++ b/examples/EBNF/EBNF.ebnf @@ -17,9 +17,7 @@ # - replace the regex_heuristics by an always matching parser # # Ambiguities can also be avoided by NOT using all the syntactic variants -# made possible by this EBNF-grammar within one and the same EBNF-document. - - +# made possible by this EBNF-grammar within one and the same EBNF-docum @ comment = /(?!#x[A-Fa-f0-9])#.*(?:\n|$)|\/\*(?:.|\n)*?\*\/|\(\*(?:.|\n)*?\*\)/ # comments can be either C-Style: /* ... */ diff --git a/examples/EBNF/EBNFServer.py b/examples/EBNF/EBNFServer.py index 692e5b6..12e9ae0 100755 --- a/examples/EBNF/EBNFServer.py +++ b/examples/EBNF/EBNFServer.py @@ -521,17 +521,17 @@ async def start_server_daemon(host, port, requests) -> list: def parse_logging_args(args): - if args.logging: - echo = repr('ECHO_ON') if args.startserver else repr('ECHO_OFF') + if args.logging or args.logging is None: + echo = repr('ECHO_ON') if isinstance(args.startserver, list) else repr('ECHO_OFF') if args.logging in ('OFF', 'STOP', 'NO', 'FALSE'): log_path = repr(None) echo = repr('ECHO_OFF') elif args.logging in ('ON', 'START', 'YES', 'TRUE'): log_path = repr('') else: - log_path = args.logging + log_path = repr('') if args.logging is None else repr(args.logging) request = LOGGING_REQUEST.replace('""', ", ".join((log_path, echo))) - debug('Logging to file %s with call %s' % (repr(log_path), request)) + debug('Logging to %s with call %s' % (log_path, request)) return log_path, request else: return None, '' @@ -554,11 +554,14 @@ if __name__ == "__main__": help='host name or IP-address of the server (default: 127.0.0.1)') parser.add_argument('-p', '--port', nargs=1, type=int, default=[-1], help='port number of the server (default:8888)') - parser.add_argument('-l', '--logging', nargs='?', metavar="ON|LOG_DIR|OFF", + parser.add_argument('-l', '--logging', nargs='?', metavar="ON|LOG_DIR|OFF", default='', help='turns logging on (default) or off or writes log to a ' 'specific directory (implies on)') + parser.add_argument('-b', '--debug', action='store_true', help="debug messages") args = parser.parse_args() + if args.debug: + DEBUG = True host = args.host[0] port = int(args.port[0]) diff --git a/examples/EBNF/vscode_support/client/src/extension.ts b/examples/EBNF/vscode_support/client/src/extension.ts index 32e8d55..096cdb3 100644 --- a/examples/EBNF/vscode_support/client/src/extension.ts +++ b/examples/EBNF/vscode_support/client/src/extension.ts @@ -89,7 +89,7 @@ function startLangServerTCP(addr: number) : Disposable { } export function activate(context: ExtensionContext) { - // console.log('activating language server connector!'); + console.log('activating language server connector!'); let disposable = startLangServerTCP(defaultPort); context.subscriptions.push(disposable); } diff --git a/examples/EBNF/vscode_support/package-lock.json b/examples/EBNF/vscode_support/package-lock.json index beb8ed4..22c9b9d 100644 --- a/examples/EBNF/vscode_support/package-lock.json +++ b/examples/EBNF/vscode_support/package-lock.json @@ -206,18 +206,18 @@ } }, "minimist": { - "version": "0.0.8", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", - "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=", + "version": "1.2.5", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz", + "integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==", "dev": true }, "mkdirp": { - "version": "0.5.1", - "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz", - "integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=", + "version": "0.5.5", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.5.tgz", + "integrity": "sha512-NKmAlESf6jMGym1++R0Ra7wvhV+wFW63FaSOFPwRahvea0gMUcGUhVeAg/0BC0wiv9ih5NYPB1Wn1UEI1/L+xQ==", "dev": true, "requires": { - "minimist": "0.0.8" + "minimist": "^1.2.5" } }, "once": { -- GitLab