Commit 38c82a2a authored by eckhart's avatar eckhart

DHParser/templates/DSLServer.pyi updated, so it reflects latest changes in...

DHParser/templates/DSLServer.pyi updated, so it reflects latest changes in examples/EBNF/EBNFServer.py
parent 7836ab9e
...@@ -199,6 +199,8 @@ def create_log(log_name: str) -> str: ...@@ -199,6 +199,8 @@ def create_log(log_name: str) -> str:
if not ldir: if not ldir:
ldir = log_dir() ldir = log_dir()
if ldir: 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: with open(os.path.join(ldir, file_name), 'w', encoding='utf-8') as f:
f.write('LOG-FILE: ' + log_name + '\n\n') f.write('LOG-FILE: ' + log_name + '\n\n')
return log_name return log_name
...@@ -219,7 +221,7 @@ def append_log(log_name: str, *strings, echo: bool = False) -> None: ...@@ -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 :param echo: If True, the log message will be echoed on the terminal. This
will also happen if logging is turned off. 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: if not ldir:
ldir = log_dir() ldir = log_dir()
if ldir and log_name: if ldir and log_name:
......
...@@ -754,10 +754,19 @@ class Server: ...@@ -754,10 +754,19 @@ class Server:
# self.known_methods.add(name) # self.known_methods.add(name)
def start_logging(self, filename: str = "") -> str: def start_logging(self, filename: str = "") -> str:
if not filename: """Starts logging to a file. If `filename` is void or a directory
filename = self.server_name + '_' + hex(id(self))[2:] + '.log' an auto-generated file name will be used. The file will be written
if not log_dir(): to the standard log-dir, unless a path is specified in filename."""
filename = os.path.join('.', 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) self.log_file = create_log(filename)
if self.log_file: if self.log_file:
self.log('Python Version: %s\nDHParser Version: %s\n\n' self.log('Python Version: %s\nDHParser Version: %s\n\n'
...@@ -766,6 +775,7 @@ class Server: ...@@ -766,6 +775,7 @@ class Server:
return 'Unable to write log-file: "%s"' % filename return 'Unable to write log-file: "%s"' % filename
def stop_logging(self): def stop_logging(self):
"""Stops logging."""
if self.log_file: if self.log_file:
self.log('Logging will be stopped now!') self.log('Logging will be stopped now!')
ret = 'Stopped logging to file: "%s"' % self.log_file ret = 'Stopped logging to file: "%s"' % self.log_file
......
...@@ -406,17 +406,17 @@ async def start_server_daemon(host, port, requests) -> list: ...@@ -406,17 +406,17 @@ async def start_server_daemon(host, port, requests) -> list:
def parse_logging_args(args): def parse_logging_args(args):
if args.logging: if args.logging or args.logging is None:
echo = repr('ECHO_ON') if args.startserver else repr('ECHO_OFF') echo = repr('ECHO_ON') if isinstance(args.startserver, list) else repr('ECHO_OFF')
if args.logging in ('OFF', 'STOP', 'NO', 'FALSE'): if args.logging in ('OFF', 'STOP', 'NO', 'FALSE'):
log_path = repr(None) log_path = repr(None)
echo = repr('ECHO_OFF') echo = repr('ECHO_OFF')
elif args.logging in ('ON', 'START', 'YES', 'TRUE'): elif args.logging in ('ON', 'START', 'YES', 'TRUE'):
log_path = repr('') log_path = repr('')
else: 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))) 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 return log_path, request
else: else:
return None, '' return None, ''
...@@ -439,11 +439,14 @@ if __name__ == "__main__": ...@@ -439,11 +439,14 @@ if __name__ == "__main__":
help='host name or IP-address of the server (default: 127.0.0.1)') 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], parser.add_argument('-p', '--port', nargs=1, type=int, default=[-1],
help='port number of the server (default:8888)') 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 ' help='turns logging on (default) or off or writes log to a '
'specific directory (implies on)') 'specific directory (implies on)')
parser.add_argument('-b', '--debug', action='store_true', help="debug messages")
args = parser.parse_args() args = parser.parse_args()
if args.debug:
DEBUG = True
host = args.host[0] host = args.host[0]
port = int(args.port[0]) port = int(args.port[0])
......
...@@ -17,9 +17,7 @@ ...@@ -17,9 +17,7 @@
# - replace the regex_heuristics by an always matching parser # - replace the regex_heuristics by an always matching parser
# #
# Ambiguities can also be avoided by NOT using all the syntactic variants # 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)*?\*\)/ @ comment = /(?!#x[A-Fa-f0-9])#.*(?:\n|$)|\/\*(?:.|\n)*?\*\/|\(\*(?:.|\n)*?\*\)/
# comments can be either C-Style: /* ... */ # comments can be either C-Style: /* ... */
......
...@@ -521,17 +521,17 @@ async def start_server_daemon(host, port, requests) -> list: ...@@ -521,17 +521,17 @@ async def start_server_daemon(host, port, requests) -> list:
def parse_logging_args(args): def parse_logging_args(args):
if args.logging: if args.logging or args.logging is None:
echo = repr('ECHO_ON') if args.startserver else repr('ECHO_OFF') echo = repr('ECHO_ON') if isinstance(args.startserver, list) else repr('ECHO_OFF')
if args.logging in ('OFF', 'STOP', 'NO', 'FALSE'): if args.logging in ('OFF', 'STOP', 'NO', 'FALSE'):
log_path = repr(None) log_path = repr(None)
echo = repr('ECHO_OFF') echo = repr('ECHO_OFF')
elif args.logging in ('ON', 'START', 'YES', 'TRUE'): elif args.logging in ('ON', 'START', 'YES', 'TRUE'):
log_path = repr('') log_path = repr('')
else: 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))) 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 return log_path, request
else: else:
return None, '' return None, ''
...@@ -554,11 +554,14 @@ if __name__ == "__main__": ...@@ -554,11 +554,14 @@ if __name__ == "__main__":
help='host name or IP-address of the server (default: 127.0.0.1)') 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], parser.add_argument('-p', '--port', nargs=1, type=int, default=[-1],
help='port number of the server (default:8888)') 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 ' help='turns logging on (default) or off or writes log to a '
'specific directory (implies on)') 'specific directory (implies on)')
parser.add_argument('-b', '--debug', action='store_true', help="debug messages")
args = parser.parse_args() args = parser.parse_args()
if args.debug:
DEBUG = True
host = args.host[0] host = args.host[0]
port = int(args.port[0]) port = int(args.port[0])
......
...@@ -89,7 +89,7 @@ function startLangServerTCP(addr: number) : Disposable { ...@@ -89,7 +89,7 @@ function startLangServerTCP(addr: number) : Disposable {
} }
export function activate(context: ExtensionContext) { export function activate(context: ExtensionContext) {
// console.log('activating language server connector!'); console.log('activating language server connector!');
let disposable = startLangServerTCP(defaultPort); let disposable = startLangServerTCP(defaultPort);
context.subscriptions.push(disposable); context.subscriptions.push(disposable);
} }
......
...@@ -206,18 +206,18 @@ ...@@ -206,18 +206,18 @@
} }
}, },
"minimist": { "minimist": {
"version": "0.0.8", "version": "1.2.5",
"resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz",
"integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=", "integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==",
"dev": true "dev": true
}, },
"mkdirp": { "mkdirp": {
"version": "0.5.1", "version": "0.5.5",
"resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz", "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.5.tgz",
"integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=", "integrity": "sha512-NKmAlESf6jMGym1++R0Ra7wvhV+wFW63FaSOFPwRahvea0gMUcGUhVeAg/0BC0wiv9ih5NYPB1Wn1UEI1/L+xQ==",
"dev": true, "dev": true,
"requires": { "requires": {
"minimist": "0.0.8" "minimist": "^1.2.5"
} }
}, },
"once": { "once": {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment