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
|
||||
) -> tuple[tuple[float, float], tuple[float, float]]:
|
||||
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:
|
||||
u_x, u_y = 0.0, 0.0
|
||||
else:
|
||||
|
@ -147,7 +147,7 @@ class Edge:
|
|||
perp_m = -1 / m
|
||||
b = mp_y - (perp_m * mp_x)
|
||||
# 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
|
||||
if self.arc >= 0:
|
||||
arc_x += offset
|
||||
|
|
|
@ -41,10 +41,7 @@ n2 = session.add_node(CoreNode, position=position, options=options)
|
|||
session.emane.set_config(
|
||||
emane.id,
|
||||
EmaneIeee80211abgModel.name,
|
||||
{
|
||||
"unicastrate": "3",
|
||||
"eventservicettl": "2"
|
||||
},
|
||||
{"unicastrate": "3", "eventservicettl": "2"},
|
||||
)
|
||||
|
||||
# link nodes to emane
|
||||
|
|
|
@ -36,8 +36,9 @@ class ChatServer:
|
|||
self.sockets.append(client_sock)
|
||||
name = f"{addr[0]}:{addr[1]}"
|
||||
print(f"[server] {name} joining")
|
||||
self.broadcast({server, client_sock},
|
||||
f"[server] {name} entered room\n")
|
||||
self.broadcast(
|
||||
{server, client_sock}, f"[server] {name} entered room\n"
|
||||
)
|
||||
else:
|
||||
peer = sock.getpeername()
|
||||
name = f"{peer[0]}:{peer[1]}"
|
||||
|
@ -48,14 +49,16 @@ class ChatServer:
|
|||
self.broadcast({server, sock}, f"[{name}] {data}\n")
|
||||
else:
|
||||
print(f"[server] {name} leaving")
|
||||
self.broadcast({server, sock},
|
||||
f"[server] {name} leaving\n")
|
||||
self.broadcast(
|
||||
{server, sock}, f"[server] {name} leaving\n"
|
||||
)
|
||||
sock.close()
|
||||
self.sockets.remove(sock)
|
||||
except socket.error:
|
||||
print(f"[server] {name} leaving")
|
||||
self.broadcast({server, sock},
|
||||
f"[server] {name} leaving\n")
|
||||
self.broadcast(
|
||||
{server, sock}, f"[server] {name} leaving\n"
|
||||
)
|
||||
sock.close()
|
||||
self.sockets.remove(sock)
|
||||
except KeyboardInterrupt:
|
||||
|
|
|
@ -4,8 +4,9 @@ from core.api.grpc.wrappers import NodeType, Position
|
|||
|
||||
def main():
|
||||
# interface helper
|
||||
iface_helper = client.InterfaceHelper(ip4_prefix="10.0.0.0/24",
|
||||
ip6_prefix="2001::/64")
|
||||
iface_helper = client.InterfaceHelper(
|
||||
ip4_prefix="10.0.0.0/24", ip6_prefix="2001::/64"
|
||||
)
|
||||
|
||||
# create grpc client and connect
|
||||
core = client.CoreGrpcClient()
|
||||
|
@ -16,8 +17,9 @@ def main():
|
|||
|
||||
# create nodes
|
||||
position = Position(x=200, y=200)
|
||||
wlan = session.add_node(1, name="wlan1", _type=NodeType.WIRELESS_LAN,
|
||||
position=position)
|
||||
wlan = session.add_node(
|
||||
1, name="wlan1", _type=NodeType.WIRELESS_LAN, position=position
|
||||
)
|
||||
position = Position(x=100, y=100)
|
||||
node1 = session.add_node(2, name="n2", model="mdr", position=position)
|
||||
position = Position(x=300, y=100)
|
||||
|
|
|
@ -55,8 +55,9 @@ def main():
|
|||
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
|
||||
)
|
||||
parser.add_argument("-a", "--address", help="address to listen on", required=True)
|
||||
parser.add_argument("-p", "--port", type=int, help="port to listen on",
|
||||
default=DEFAULT_PORT)
|
||||
parser.add_argument(
|
||||
"-p", "--port", type=int, help="port to listen on", default=DEFAULT_PORT
|
||||
)
|
||||
args = parser.parse_args()
|
||||
client = ChatClient(args.address, args.port)
|
||||
client.run()
|
||||
|
|
|
@ -97,7 +97,7 @@ def main():
|
|||
core.move_node(sessions[0].id, node_number, position=position)
|
||||
current_x = x
|
||||
current_y = y
|
||||
time.sleep(.25)
|
||||
time.sleep(0.25)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
|
@ -24,7 +24,7 @@ def main():
|
|||
_type=NodeType.EMANE,
|
||||
name="emane1",
|
||||
position=position,
|
||||
emane=EmaneIeee80211abgModel.name
|
||||
emane=EmaneIeee80211abgModel.name,
|
||||
)
|
||||
position = Position(x=250, y=250)
|
||||
node2 = session.add_node(_id=2, model="mdr", name="n2", position=position)
|
||||
|
|
|
@ -24,7 +24,7 @@ def main():
|
|||
_type=NodeType.EMANE,
|
||||
name="emane1",
|
||||
position=position,
|
||||
emane=EmaneIeee80211abgModel.name
|
||||
emane=EmaneIeee80211abgModel.name,
|
||||
)
|
||||
position = Position(x=250, y=250)
|
||||
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:
|
||||
continue
|
||||
key, value = line.split("=")
|
||||
d[key] = value.strip("\"")
|
||||
d[key] = value.strip('"')
|
||||
name_value = d["ID"]
|
||||
like_value = d.get("ID_LIKE", "")
|
||||
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:
|
||||
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")
|
||||
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(
|
||||
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(
|
||||
"sudo apt install -y automake pkg-config gcc libev-dev nftables "
|
||||
f"iproute2 ethtool tk bash",
|
||||
hide=hide
|
||||
hide=hide,
|
||||
)
|
||||
if not no_python:
|
||||
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 "
|
||||
"--with-cflags=-ggdb --sysconfdir=/usr/local/etc/quagga --enable-vtysh "
|
||||
"--localstatedir=/var/run/quagga",
|
||||
hide=hide
|
||||
hide=hide,
|
||||
)
|
||||
c.run("make -j$(nproc)", 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/")
|
||||
service_file = systemd_dir.joinpath("core-daemon.service")
|
||||
if systemd_dir.exists():
|
||||
service_data = inspect.cleandoc(f"""
|
||||
service_data = inspect.cleandoc(
|
||||
f"""
|
||||
[Unit]
|
||||
Description=Common Open Research Emulator Service
|
||||
After=network.target
|
||||
|
@ -270,7 +271,8 @@ def install_service(c, verbose=False, prefix=DEFAULT_PREFIX):
|
|||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
""")
|
||||
"""
|
||||
)
|
||||
temp = NamedTemporaryFile("w", delete=False)
|
||||
temp.write(service_data)
|
||||
temp.close()
|
||||
|
@ -289,10 +291,12 @@ def install_core_files(c, local=False, verbose=False, prefix=DEFAULT_PREFIX):
|
|||
if not local:
|
||||
core_python = bin_dir.joinpath("core-python")
|
||||
temp = NamedTemporaryFile("w", delete=False)
|
||||
temp.writelines([
|
||||
"#!/bin/bash\n",
|
||||
f'exec "{VENV_PYTHON}" "$@"\n',
|
||||
])
|
||||
temp.writelines(
|
||||
[
|
||||
"#!/bin/bash\n",
|
||||
f'exec "{VENV_PYTHON}" "$@"\n',
|
||||
]
|
||||
)
|
||||
temp.close()
|
||||
c.run(f"sudo cp {temp.name} {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={
|
||||
"verbose": "enable verbose",
|
||||
"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",
|
||||
},
|
||||
)
|
||||
|
@ -344,7 +348,7 @@ def build(
|
|||
"local": "determines if core will install to local system, default is False",
|
||||
"prefix": f"prefix where scripts are installed, default is {DEFAULT_PREFIX}",
|
||||
"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",
|
||||
"no-python": "avoid installing python system dependencies",
|
||||
},
|
||||
|
@ -399,7 +403,7 @@ def install(
|
|||
"emane-version": "version of emane install",
|
||||
"verbose": "enable verbose",
|
||||
"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):
|
||||
|
@ -444,9 +448,7 @@ def install_emane(c, emane_version, verbose=False, install_type=None):
|
|||
c.run("make -j$(nproc)", hide=hide)
|
||||
with p.start("installing emane python bindings for core virtual environment"):
|
||||
with c.cd(DAEMON_DIR):
|
||||
c.run(
|
||||
f"poetry run pip install {emane_python_dir.absolute()}", hide=hide
|
||||
)
|
||||
c.run(f"poetry run pip install {emane_python_dir.absolute()}", hide=hide)
|
||||
|
||||
|
||||
@task(
|
||||
|
@ -489,7 +491,10 @@ def uninstall(
|
|||
if Path(VENV_PYTHON).is_file():
|
||||
with c.cd(DAEMON_DIR):
|
||||
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)
|
||||
# remove installed files
|
||||
bin_dir = Path(prefix).joinpath("bin")
|
||||
|
@ -518,7 +523,7 @@ def uninstall(
|
|||
"prefix": f"prefix where scripts are installed, default is {DEFAULT_PREFIX}",
|
||||
"branch": "branch to install latest code from, default is current branch",
|
||||
"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(
|
||||
|
@ -528,7 +533,7 @@ def reinstall(
|
|||
local=False,
|
||||
prefix=DEFAULT_PREFIX,
|
||||
branch=None,
|
||||
install_type=None
|
||||
install_type=None,
|
||||
):
|
||||
"""
|
||||
run the uninstall task, get latest from specified branch, and run install task
|
||||
|
|
Loading…
Reference in a new issue