updated and fixed formatting with proper version of python black
This commit is contained in:
parent
a80796ac72
commit
db89fbf066
9 changed files with 49 additions and 41 deletions
|
@ -56,7 +56,7 @@ def node_label_positions(
|
||||||
src_x: int, src_y: int, dst_x: int, dst_y: int
|
src_x: int, src_y: int, dst_x: int, dst_y: int
|
||||||
) -> tuple[tuple[float, float], tuple[float, float]]:
|
) -> tuple[tuple[float, float], tuple[float, float]]:
|
||||||
v_x, v_y = dst_x - src_x, dst_y - src_y
|
v_x, v_y = dst_x - src_x, dst_y - src_y
|
||||||
v_len = math.sqrt(v_x ** 2 + v_y ** 2)
|
v_len = math.sqrt(v_x**2 + v_y**2)
|
||||||
if v_len == 0:
|
if v_len == 0:
|
||||||
u_x, u_y = 0.0, 0.0
|
u_x, u_y = 0.0, 0.0
|
||||||
else:
|
else:
|
||||||
|
@ -147,7 +147,7 @@ class Edge:
|
||||||
perp_m = -1 / m
|
perp_m = -1 / m
|
||||||
b = mp_y - (perp_m * mp_x)
|
b = mp_y - (perp_m * mp_x)
|
||||||
# get arc x and y
|
# get arc x and y
|
||||||
offset = math.sqrt(self.arc ** 2 / (1 + (1 / m ** 2)))
|
offset = math.sqrt(self.arc**2 / (1 + (1 / m**2)))
|
||||||
arc_x = mp_x
|
arc_x = mp_x
|
||||||
if self.arc >= 0:
|
if self.arc >= 0:
|
||||||
arc_x += offset
|
arc_x += offset
|
||||||
|
|
|
@ -41,10 +41,7 @@ n2 = session.add_node(CoreNode, position=position, options=options)
|
||||||
session.emane.set_config(
|
session.emane.set_config(
|
||||||
emane.id,
|
emane.id,
|
||||||
EmaneIeee80211abgModel.name,
|
EmaneIeee80211abgModel.name,
|
||||||
{
|
{"unicastrate": "3", "eventservicettl": "2"},
|
||||||
"unicastrate": "3",
|
|
||||||
"eventservicettl": "2"
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# link nodes to emane
|
# link nodes to emane
|
||||||
|
|
|
@ -36,8 +36,9 @@ class ChatServer:
|
||||||
self.sockets.append(client_sock)
|
self.sockets.append(client_sock)
|
||||||
name = f"{addr[0]}:{addr[1]}"
|
name = f"{addr[0]}:{addr[1]}"
|
||||||
print(f"[server] {name} joining")
|
print(f"[server] {name} joining")
|
||||||
self.broadcast({server, client_sock},
|
self.broadcast(
|
||||||
f"[server] {name} entered room\n")
|
{server, client_sock}, f"[server] {name} entered room\n"
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
peer = sock.getpeername()
|
peer = sock.getpeername()
|
||||||
name = f"{peer[0]}:{peer[1]}"
|
name = f"{peer[0]}:{peer[1]}"
|
||||||
|
@ -48,14 +49,16 @@ class ChatServer:
|
||||||
self.broadcast({server, sock}, f"[{name}] {data}\n")
|
self.broadcast({server, sock}, f"[{name}] {data}\n")
|
||||||
else:
|
else:
|
||||||
print(f"[server] {name} leaving")
|
print(f"[server] {name} leaving")
|
||||||
self.broadcast({server, sock},
|
self.broadcast(
|
||||||
f"[server] {name} leaving\n")
|
{server, sock}, f"[server] {name} leaving\n"
|
||||||
|
)
|
||||||
sock.close()
|
sock.close()
|
||||||
self.sockets.remove(sock)
|
self.sockets.remove(sock)
|
||||||
except socket.error:
|
except socket.error:
|
||||||
print(f"[server] {name} leaving")
|
print(f"[server] {name} leaving")
|
||||||
self.broadcast({server, sock},
|
self.broadcast(
|
||||||
f"[server] {name} leaving\n")
|
{server, sock}, f"[server] {name} leaving\n"
|
||||||
|
)
|
||||||
sock.close()
|
sock.close()
|
||||||
self.sockets.remove(sock)
|
self.sockets.remove(sock)
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
|
|
|
@ -4,8 +4,9 @@ from core.api.grpc.wrappers import NodeType, Position
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
# interface helper
|
# interface helper
|
||||||
iface_helper = client.InterfaceHelper(ip4_prefix="10.0.0.0/24",
|
iface_helper = client.InterfaceHelper(
|
||||||
ip6_prefix="2001::/64")
|
ip4_prefix="10.0.0.0/24", ip6_prefix="2001::/64"
|
||||||
|
)
|
||||||
|
|
||||||
# create grpc client and connect
|
# create grpc client and connect
|
||||||
core = client.CoreGrpcClient()
|
core = client.CoreGrpcClient()
|
||||||
|
@ -16,8 +17,9 @@ def main():
|
||||||
|
|
||||||
# create nodes
|
# create nodes
|
||||||
position = Position(x=200, y=200)
|
position = Position(x=200, y=200)
|
||||||
wlan = session.add_node(1, name="wlan1", _type=NodeType.WIRELESS_LAN,
|
wlan = session.add_node(
|
||||||
position=position)
|
1, name="wlan1", _type=NodeType.WIRELESS_LAN, position=position
|
||||||
|
)
|
||||||
position = Position(x=100, y=100)
|
position = Position(x=100, y=100)
|
||||||
node1 = session.add_node(2, name="n2", model="mdr", position=position)
|
node1 = session.add_node(2, name="n2", model="mdr", position=position)
|
||||||
position = Position(x=300, y=100)
|
position = Position(x=300, y=100)
|
||||||
|
|
|
@ -55,8 +55,9 @@ def main():
|
||||||
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
|
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
|
||||||
)
|
)
|
||||||
parser.add_argument("-a", "--address", help="address to listen on", required=True)
|
parser.add_argument("-a", "--address", help="address to listen on", required=True)
|
||||||
parser.add_argument("-p", "--port", type=int, help="port to listen on",
|
parser.add_argument(
|
||||||
default=DEFAULT_PORT)
|
"-p", "--port", type=int, help="port to listen on", default=DEFAULT_PORT
|
||||||
|
)
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
client = ChatClient(args.address, args.port)
|
client = ChatClient(args.address, args.port)
|
||||||
client.run()
|
client.run()
|
||||||
|
|
|
@ -97,7 +97,7 @@ def main():
|
||||||
core.move_node(sessions[0].id, node_number, position=position)
|
core.move_node(sessions[0].id, node_number, position=position)
|
||||||
current_x = x
|
current_x = x
|
||||||
current_y = y
|
current_y = y
|
||||||
time.sleep(.25)
|
time.sleep(0.25)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
|
@ -24,7 +24,7 @@ def main():
|
||||||
_type=NodeType.EMANE,
|
_type=NodeType.EMANE,
|
||||||
name="emane1",
|
name="emane1",
|
||||||
position=position,
|
position=position,
|
||||||
emane=EmaneIeee80211abgModel.name
|
emane=EmaneIeee80211abgModel.name,
|
||||||
)
|
)
|
||||||
position = Position(x=250, y=250)
|
position = Position(x=250, y=250)
|
||||||
node2 = session.add_node(_id=2, model="mdr", name="n2", position=position)
|
node2 = session.add_node(_id=2, model="mdr", name="n2", position=position)
|
||||||
|
|
|
@ -24,7 +24,7 @@ def main():
|
||||||
_type=NodeType.EMANE,
|
_type=NodeType.EMANE,
|
||||||
name="emane1",
|
name="emane1",
|
||||||
position=position,
|
position=position,
|
||||||
emane=EmaneIeee80211abgModel.name
|
emane=EmaneIeee80211abgModel.name,
|
||||||
)
|
)
|
||||||
position = Position(x=250, y=250)
|
position = Position(x=250, y=250)
|
||||||
node2 = session.add_node(_id=2, model="mdr", name="n2", position=position)
|
node2 = session.add_node(_id=2, model="mdr", name="n2", position=position)
|
||||||
|
|
45
tasks.py
45
tasks.py
|
@ -141,7 +141,7 @@ def get_os(install_type: Optional[str]) -> OsInfo:
|
||||||
if not line:
|
if not line:
|
||||||
continue
|
continue
|
||||||
key, value = line.split("=")
|
key, value = line.split("=")
|
||||||
d[key] = value.strip("\"")
|
d[key] = value.strip('"')
|
||||||
name_value = d["ID"]
|
name_value = d["ID"]
|
||||||
like_value = d.get("ID_LIKE", "")
|
like_value = d.get("ID_LIKE", "")
|
||||||
version_value = d["VERSION_ID"]
|
version_value = d["VERSION_ID"]
|
||||||
|
@ -149,10 +149,10 @@ def get_os(install_type: Optional[str]) -> OsInfo:
|
||||||
|
|
||||||
|
|
||||||
def check_existing_core(c: Context, hide: bool) -> None:
|
def check_existing_core(c: Context, hide: bool) -> None:
|
||||||
if c.run("python -c \"import core\"", warn=True, hide=hide):
|
if c.run('python -c "import core"', warn=True, hide=hide):
|
||||||
raise SystemError("existing python core installation detected, please remove")
|
raise SystemError("existing python core installation detected, please remove")
|
||||||
python_bin = get_env_python()
|
python_bin = get_env_python()
|
||||||
if c.run(f"{python_bin} -c \"import core\"", warn=True, hide=hide):
|
if c.run(f'{python_bin} -c "import core"', warn=True, hide=hide):
|
||||||
raise SystemError(
|
raise SystemError(
|
||||||
f"existing {python_bin} core installation detected, please remove"
|
f"existing {python_bin} core installation detected, please remove"
|
||||||
)
|
)
|
||||||
|
@ -166,7 +166,7 @@ def install_system(c: Context, os_info: OsInfo, hide: bool, no_python: bool) ->
|
||||||
c.run(
|
c.run(
|
||||||
"sudo apt install -y automake pkg-config gcc libev-dev nftables "
|
"sudo apt install -y automake pkg-config gcc libev-dev nftables "
|
||||||
f"iproute2 ethtool tk bash",
|
f"iproute2 ethtool tk bash",
|
||||||
hide=hide
|
hide=hide,
|
||||||
)
|
)
|
||||||
if not no_python:
|
if not no_python:
|
||||||
c.run(f"sudo apt install -y {python_dep}-tk", hide=hide)
|
c.run(f"sudo apt install -y {python_dep}-tk", hide=hide)
|
||||||
|
@ -243,7 +243,7 @@ def install_ospf_mdr(c: Context, os_info: OsInfo, hide: bool) -> None:
|
||||||
"./configure --disable-doc --enable-user=root --enable-group=root "
|
"./configure --disable-doc --enable-user=root --enable-group=root "
|
||||||
"--with-cflags=-ggdb --sysconfdir=/usr/local/etc/quagga --enable-vtysh "
|
"--with-cflags=-ggdb --sysconfdir=/usr/local/etc/quagga --enable-vtysh "
|
||||||
"--localstatedir=/var/run/quagga",
|
"--localstatedir=/var/run/quagga",
|
||||||
hide=hide
|
hide=hide,
|
||||||
)
|
)
|
||||||
c.run("make -j$(nproc)", hide=hide)
|
c.run("make -j$(nproc)", hide=hide)
|
||||||
c.run("sudo make install", hide=hide)
|
c.run("sudo make install", hide=hide)
|
||||||
|
@ -258,7 +258,8 @@ def install_service(c, verbose=False, prefix=DEFAULT_PREFIX):
|
||||||
systemd_dir = Path("/lib/systemd/system/")
|
systemd_dir = Path("/lib/systemd/system/")
|
||||||
service_file = systemd_dir.joinpath("core-daemon.service")
|
service_file = systemd_dir.joinpath("core-daemon.service")
|
||||||
if systemd_dir.exists():
|
if systemd_dir.exists():
|
||||||
service_data = inspect.cleandoc(f"""
|
service_data = inspect.cleandoc(
|
||||||
|
f"""
|
||||||
[Unit]
|
[Unit]
|
||||||
Description=Common Open Research Emulator Service
|
Description=Common Open Research Emulator Service
|
||||||
After=network.target
|
After=network.target
|
||||||
|
@ -270,7 +271,8 @@ def install_service(c, verbose=False, prefix=DEFAULT_PREFIX):
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
WantedBy=multi-user.target
|
WantedBy=multi-user.target
|
||||||
""")
|
"""
|
||||||
|
)
|
||||||
temp = NamedTemporaryFile("w", delete=False)
|
temp = NamedTemporaryFile("w", delete=False)
|
||||||
temp.write(service_data)
|
temp.write(service_data)
|
||||||
temp.close()
|
temp.close()
|
||||||
|
@ -289,10 +291,12 @@ def install_core_files(c, local=False, verbose=False, prefix=DEFAULT_PREFIX):
|
||||||
if not local:
|
if not local:
|
||||||
core_python = bin_dir.joinpath("core-python")
|
core_python = bin_dir.joinpath("core-python")
|
||||||
temp = NamedTemporaryFile("w", delete=False)
|
temp = NamedTemporaryFile("w", delete=False)
|
||||||
temp.writelines([
|
temp.writelines(
|
||||||
"#!/bin/bash\n",
|
[
|
||||||
f'exec "{VENV_PYTHON}" "$@"\n',
|
"#!/bin/bash\n",
|
||||||
])
|
f'exec "{VENV_PYTHON}" "$@"\n',
|
||||||
|
]
|
||||||
|
)
|
||||||
temp.close()
|
temp.close()
|
||||||
c.run(f"sudo cp {temp.name} {core_python}", hide=hide)
|
c.run(f"sudo cp {temp.name} {core_python}", hide=hide)
|
||||||
c.run(f"sudo chmod 755 {core_python}", hide=hide)
|
c.run(f"sudo chmod 755 {core_python}", hide=hide)
|
||||||
|
@ -312,7 +316,7 @@ def install_core_files(c, local=False, verbose=False, prefix=DEFAULT_PREFIX):
|
||||||
help={
|
help={
|
||||||
"verbose": "enable verbose",
|
"verbose": "enable verbose",
|
||||||
"install-type": "used to force an install type, "
|
"install-type": "used to force an install type, "
|
||||||
"can be one of the following (redhat, debian)",
|
"can be one of the following (redhat, debian)",
|
||||||
"no-python": "avoid installing python system dependencies",
|
"no-python": "avoid installing python system dependencies",
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -344,7 +348,7 @@ def build(
|
||||||
"local": "determines if core will install to local system, default is False",
|
"local": "determines if core will install to local system, default is False",
|
||||||
"prefix": f"prefix where scripts are installed, default is {DEFAULT_PREFIX}",
|
"prefix": f"prefix where scripts are installed, default is {DEFAULT_PREFIX}",
|
||||||
"install-type": "used to force an install type, "
|
"install-type": "used to force an install type, "
|
||||||
"can be one of the following (redhat, debian)",
|
"can be one of the following (redhat, debian)",
|
||||||
"ospf": "disable ospf installation",
|
"ospf": "disable ospf installation",
|
||||||
"no-python": "avoid installing python system dependencies",
|
"no-python": "avoid installing python system dependencies",
|
||||||
},
|
},
|
||||||
|
@ -399,7 +403,7 @@ def install(
|
||||||
"emane-version": "version of emane install",
|
"emane-version": "version of emane install",
|
||||||
"verbose": "enable verbose",
|
"verbose": "enable verbose",
|
||||||
"install-type": "used to force an install type, "
|
"install-type": "used to force an install type, "
|
||||||
"can be one of the following (redhat, debian)",
|
"can be one of the following (redhat, debian)",
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
def install_emane(c, emane_version, verbose=False, install_type=None):
|
def install_emane(c, emane_version, verbose=False, install_type=None):
|
||||||
|
@ -444,9 +448,7 @@ def install_emane(c, emane_version, verbose=False, install_type=None):
|
||||||
c.run("make -j$(nproc)", hide=hide)
|
c.run("make -j$(nproc)", hide=hide)
|
||||||
with p.start("installing emane python bindings for core virtual environment"):
|
with p.start("installing emane python bindings for core virtual environment"):
|
||||||
with c.cd(DAEMON_DIR):
|
with c.cd(DAEMON_DIR):
|
||||||
c.run(
|
c.run(f"poetry run pip install {emane_python_dir.absolute()}", hide=hide)
|
||||||
f"poetry run pip install {emane_python_dir.absolute()}", hide=hide
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@task(
|
@task(
|
||||||
|
@ -489,7 +491,10 @@ def uninstall(
|
||||||
if Path(VENV_PYTHON).is_file():
|
if Path(VENV_PYTHON).is_file():
|
||||||
with c.cd(DAEMON_DIR):
|
with c.cd(DAEMON_DIR):
|
||||||
if dev:
|
if dev:
|
||||||
c.run(f"{ACTIVATE_VENV} && poetry run pre-commit uninstall", hide=hide)
|
c.run(
|
||||||
|
f"{ACTIVATE_VENV} && poetry run pre-commit uninstall",
|
||||||
|
hide=hide,
|
||||||
|
)
|
||||||
c.run(f"sudo {VENV_PYTHON} -m pip uninstall -y core", hide=hide)
|
c.run(f"sudo {VENV_PYTHON} -m pip uninstall -y core", hide=hide)
|
||||||
# remove installed files
|
# remove installed files
|
||||||
bin_dir = Path(prefix).joinpath("bin")
|
bin_dir = Path(prefix).joinpath("bin")
|
||||||
|
@ -518,7 +523,7 @@ def uninstall(
|
||||||
"prefix": f"prefix where scripts are installed, default is {DEFAULT_PREFIX}",
|
"prefix": f"prefix where scripts are installed, default is {DEFAULT_PREFIX}",
|
||||||
"branch": "branch to install latest code from, default is current branch",
|
"branch": "branch to install latest code from, default is current branch",
|
||||||
"install-type": "used to force an install type, "
|
"install-type": "used to force an install type, "
|
||||||
"can be one of the following (redhat, debian)",
|
"can be one of the following (redhat, debian)",
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
def reinstall(
|
def reinstall(
|
||||||
|
@ -528,7 +533,7 @@ def reinstall(
|
||||||
local=False,
|
local=False,
|
||||||
prefix=DEFAULT_PREFIX,
|
prefix=DEFAULT_PREFIX,
|
||||||
branch=None,
|
branch=None,
|
||||||
install_type=None
|
install_type=None,
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
run the uninstall task, get latest from specified branch, and run install task
|
run the uninstall task, get latest from specified branch, and run install task
|
||||||
|
|
Loading…
Reference in a new issue