Skip to content

Commit

Permalink
add --no-multicast-scouting flag to examples
Browse files Browse the repository at this point in the history
  • Loading branch information
DenisBiryukov91 committed Dec 11, 2024
1 parent ce22b76 commit f9213ea
Show file tree
Hide file tree
Showing 21 changed files with 153 additions and 855 deletions.
1 change: 1 addition & 0 deletions examples/common/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .common import *
66 changes: 66 additions & 0 deletions examples/common/common.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import argparse
import json

import zenoh


def add_config_arguments(parser: argparse.ArgumentParser):
parser.add_argument(
"--mode",
"-m",
dest="mode",
choices=["peer", "client"],
type=str,
help="The zenoh session mode.",
)
parser.add_argument(
"--connect",
"-e",
dest="connect",
metavar="ENDPOINT",
action="append",
type=str,
help="Endpoints to connect to.",
)
parser.add_argument(
"--listen",
"-l",
dest="listen",
metavar="ENDPOINT",
action="append",
type=str,
help="Endpoints to listen on.",
)
parser.add_argument(
"--config",
"-c",
dest="config",
metavar="FILE",
type=str,
help="A configuration file.",
)
parser.add_argument(
"--no-multicast-scouting",
dest="no_multicast_scouting",
default=False,
action="store_true",
help="Disable multicast scouting.",
)


def get_config_from_args(args) -> zenoh.Config:
conf = (
zenoh.Config.from_file(args.config)
if args.config is not None
else zenoh.Config()
)
if args.mode is not None:
conf.insert_json5("mode", json.dumps(args.mode))
if args.connect is not None:
conf.insert_json5("connect/endpoints", json.dumps(args.connect))
if args.listen is not None:
conf.insert_json5("listen/endpoints", json.dumps(args.listen))
if args.no_multicast_scouting is not None:
conf.insert_json5("scouting/multicast/enabled", json.dumps(False))

return conf
50 changes: 5 additions & 45 deletions examples/z_delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,33 +29,10 @@ def main(conf: zenoh.Config, key: str):
import argparse
import json

import common

parser = argparse.ArgumentParser(prog="z_delete", description="zenoh put example")
parser.add_argument(
"--mode",
"-m",
dest="mode",
choices=["peer", "client"],
type=str,
help="The zenoh session mode.",
)
parser.add_argument(
"--connect",
"-e",
dest="connect",
metavar="ENDPOINT",
action="append",
type=str,
help="Endpoints to connect to.",
)
parser.add_argument(
"--listen",
"-l",
dest="listen",
metavar="ENDPOINT",
action="append",
type=str,
help="Endpoints to listen on.",
)
common.add_config_arguments(parser)
parser.add_argument(
"--key",
"-k",
Expand All @@ -64,27 +41,10 @@ def main(conf: zenoh.Config, key: str):
type=str,
help="The key expression matching resources to delete.",
)
parser.add_argument(
"--config",
"-c",
dest="config",
metavar="FILE",
type=str,
help="A configuration file.",
)

args = parser.parse_args()
conf = (
zenoh.Config.from_file(args.config)
if args.config is not None
else zenoh.Config()
)
if args.mode is not None:
conf.insert_json5("mode", json.dumps(args.mode))
if args.connect is not None:
conf.insert_json5("connect/endpoints", json.dumps(args.connect))
if args.listen is not None:
conf.insert_json5("listen/endpoints", json.dumps(args.listen))
conf = common.get_config_from_args(args)

key = args.key

main(conf, key)
50 changes: 5 additions & 45 deletions examples/z_get.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,33 +42,10 @@ def main(
import argparse
import json

import common

parser = argparse.ArgumentParser(prog="z_get", description="zenoh get example")
parser.add_argument(
"--mode",
"-m",
dest="mode",
choices=["peer", "client"],
type=str,
help="The zenoh session mode.",
)
parser.add_argument(
"--connect",
"-e",
dest="connect",
metavar="ENDPOINT",
action="append",
type=str,
help="Endpoints to connect to.",
)
parser.add_argument(
"--listen",
"-l",
dest="listen",
metavar="ENDPOINT",
action="append",
type=str,
help="Endpoints to listen on.",
)
common.add_config_arguments(parser)
parser.add_argument(
"--selector",
"-s",
Expand Down Expand Up @@ -101,27 +78,10 @@ def main(
type=float,
help="The query timeout",
)
parser.add_argument(
"--config",
"-c",
dest="config",
metavar="FILE",
type=str,
help="A configuration file.",
)

args = parser.parse_args()
conf = (
zenoh.Config.from_file(args.config)
if args.config is not None
else zenoh.Config()
)
if args.mode is not None:
conf.insert_json5("mode", json.dumps(args.mode))
if args.connect is not None:
conf.insert_json5("connect/endpoints", json.dumps(args.connect))
if args.listen is not None:
conf.insert_json5("listen/endpoints", json.dumps(args.listen))
conf = common.get_config_from_args(args)

target = {
"ALL": zenoh.QueryTarget.ALL,
"BEST_MATCHING": zenoh.QueryTarget.BEST_MATCHING,
Expand Down
49 changes: 4 additions & 45 deletions examples/z_get_liveliness.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,35 +35,12 @@ def main(conf: zenoh.Config, key: str, timeout: float):
import argparse
import json

import common

parser = argparse.ArgumentParser(
prog="z_get_liveliness", description="zenoh put example"
)
parser.add_argument(
"--mode",
"-m",
dest="mode",
choices=["peer", "client"],
type=str,
help="The zenoh session mode.",
)
parser.add_argument(
"--connect",
"-e",
dest="connect",
metavar="ENDPOINT",
action="append",
type=str,
help="Endpoints to connect to.",
)
parser.add_argument(
"--listen",
"-l",
dest="listen",
metavar="ENDPOINT",
action="append",
type=str,
help="Endpoints to listen on.",
)
common.add_config_arguments(parser)
parser.add_argument(
"--key",
"-k",
Expand All @@ -80,26 +57,8 @@ def main(conf: zenoh.Config, key: str, timeout: float):
type=float,
help="The query timeout.",
)
parser.add_argument(
"--config",
"-c",
dest="config",
metavar="FILE",
type=str,
help="A configuration file.",
)

args = parser.parse_args()
conf = (
zenoh.Config.from_file(args.config)
if args.config is not None
else zenoh.Config()
)
if args.mode is not None:
conf.insert_json5("mode", json.dumps(args.mode))
if args.connect is not None:
conf.insert_json5("connect/endpoints", json.dumps(args.connect))
if args.listen is not None:
conf.insert_json5("listen/endpoints", json.dumps(args.listen))
conf = common.get_config_from_args(args)

main(conf, args.key, args.timeout)
49 changes: 4 additions & 45 deletions examples/z_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,53 +31,12 @@ def main(conf: zenoh.Config):
import argparse
import json

import common

parser = argparse.ArgumentParser(prog="z_info", description="zenoh info example")
parser.add_argument(
"--mode",
"-m",
dest="mode",
choices=["peer", "client"],
type=str,
help="The zenoh session mode.",
)
parser.add_argument(
"--connect",
"-e",
dest="connect",
metavar="ENDPOINT",
action="append",
type=str,
help="Endpoints to connect to.",
)
parser.add_argument(
"--listen",
"-l",
dest="listen",
metavar="ENDPOINT",
action="append",
type=str,
help="Endpoints to listen on.",
)
parser.add_argument(
"--config",
"-c",
dest="config",
metavar="FILE",
type=str,
help="A configuration file.",
)
common.add_config_arguments(parser)

args = parser.parse_args()
conf = (
zenoh.Config.from_file(args.config)
if args.config is not None
else zenoh.Config()
)
if args.mode is not None:
conf.insert_json5("mode", json.dumps(args.mode))
if args.connect is not None:
conf.insert_json5("connect/endpoints", json.dumps(args.connect))
if args.listen is not None:
conf.insert_json5("listen/endpoints", json.dumps(args.listen))
conf = common.get_config_from_args(args)

main(conf)
49 changes: 4 additions & 45 deletions examples/z_liveliness.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,35 +36,12 @@ def main(conf: zenoh.Config, key: str):
import argparse
import json

import common

parser = argparse.ArgumentParser(
prog="z_liveliness", description="zenoh put example"
)
parser.add_argument(
"--mode",
"-m",
dest="mode",
choices=["peer", "client"],
type=str,
help="The zenoh session mode.",
)
parser.add_argument(
"--connect",
"-e",
dest="connect",
metavar="ENDPOINT",
action="append",
type=str,
help="Endpoints to connect to.",
)
parser.add_argument(
"--listen",
"-l",
dest="listen",
metavar="ENDPOINT",
action="append",
type=str,
help="Endpoints to listen on.",
)
common.add_config_arguments(parser)
parser.add_argument(
"--key",
"-k",
Expand All @@ -73,26 +50,8 @@ def main(conf: zenoh.Config, key: str):
type=str,
help="The key expression to write.",
)
parser.add_argument(
"--config",
"-c",
dest="config",
metavar="FILE",
type=str,
help="A configuration file.",
)

args = parser.parse_args()
conf = (
zenoh.Config.from_file(args.config)
if args.config is not None
else zenoh.Config()
)
if args.mode is not None:
conf.insert_json5("mode", json.dumps(args.mode))
if args.connect is not None:
conf.insert_json5("connect/endpoints", json.dumps(args.connect))
if args.listen is not None:
conf.insert_json5("listen/endpoints", json.dumps(args.listen))
conf = common.get_config_from_args(args)

main(conf, args.key)
Loading

0 comments on commit f9213ea

Please sign in to comment.