-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #276 from alltilla/grpc-factor-out-common-classes
grpc: factor out base classes for gRPC based drivers
- Loading branch information
Showing
69 changed files
with
1,871 additions
and
1,903 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
#!/usr/bin/env python3 | ||
############################################################################# | ||
# Copyright (c) 2024 Axoflow | ||
# Copyright (c) 2024 Attila Szakacs <[email protected]> | ||
# Copyright (c) 2010-2017 Balabit | ||
# | ||
# This library is free software; you can redistribute it and/or | ||
|
@@ -33,36 +35,65 @@ | |
import sys | ||
import codecs | ||
|
||
grammar_file = os.path.join(os.environ.get('top_srcdir', ''), 'lib/cfg-grammar.y') | ||
if not os.path.isfile(grammar_file): | ||
grammar_file = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'cfg-grammar.y') | ||
if not os.path.isfile(grammar_file): | ||
sys.exit('Error opening cfg-grammar.y') | ||
ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | ||
COMMON_GRAMMAR_FILE = 'lib/cfg-grammar.y' | ||
BLOCKS = {} | ||
|
||
|
||
def locate_file(file_name): | ||
full_path = os.path.join(os.environ.get('top_srcdir', ''), file_name) | ||
if not os.path.isfile(full_path): | ||
full_path = os.path.join(ROOT_DIR, file_name) | ||
if not os.path.isfile(full_path): | ||
sys.exit('Error opening ' + file_name) | ||
return full_path | ||
|
||
|
||
def print_to_stdout(line): | ||
if sys.hexversion >= 0x3000000: | ||
sys.stdout.buffer.write(line.encode("utf-8")) | ||
else: | ||
print(line.encode("utf-8"), end='') | ||
|
||
def include_block(block_type): | ||
start_marker = 'START_' + block_type | ||
end_marker = 'END_' + block_type | ||
|
||
with codecs.open(grammar_file, encoding="utf-8") as f: | ||
in_block = False | ||
def collect_block_definitions(file_name): | ||
with codecs.open(locate_file(file_name), encoding="utf-8") as f: | ||
block_name = None | ||
block = [] | ||
for line in f: | ||
if start_marker in line: | ||
in_block = True | ||
elif end_marker in line: | ||
in_block = False | ||
elif in_block: | ||
print_to_stdout(line) | ||
|
||
for line in fileinput.input(openhook=fileinput.hook_encoded("utf-8")): | ||
if 'INCLUDE_DECLS' in line: | ||
include_block('DECLS') | ||
elif 'INCLUDE_RULES' in line: | ||
include_block('RULES') | ||
else: | ||
print_to_stdout(line) | ||
if line.startswith('/* START_') and line.endswith(' */\n'): | ||
block_name = line[len('/* START_'):-len(' */\n')] | ||
elif block_name and line == '/* END_' + block_name + ' */\n': | ||
BLOCKS[block_name] = BLOCKS.get(block_name, '') + ''.join(block) | ||
block_name = None | ||
block = [] | ||
elif block_name: | ||
block.append(line) | ||
|
||
|
||
def include_block(block_type): | ||
try: | ||
print_to_stdout(BLOCKS[block_type]) | ||
except KeyError: | ||
sys.exit('Block not found: ' + block_type) | ||
|
||
|
||
def print_preprocessed_grammar(): | ||
for line in fileinput.input(openhook=fileinput.hook_encoded("utf-8")): | ||
if line.startswith('/* INCLUDE_') and line.endswith(' */\n'): | ||
block_name = line[len('/* INCLUDE_'):-len(' */\n')] | ||
include_block(block_name) | ||
elif line.startswith('/* REQUIRE ') and line.endswith(' */\n'): | ||
file_name = line[len('/* REQUIRE '):-len(' */\n')] | ||
collect_block_definitions(file_name) | ||
else: | ||
print_to_stdout(line) | ||
|
||
|
||
def main(): | ||
collect_block_definitions(COMMON_GRAMMAR_FILE) | ||
print_preprocessed_grammar() | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.