updated and fixed formatting with proper version of python black

This commit is contained in:
Blake Harnden 2023-06-13 21:49:50 -07:00
parent a80796ac72
commit db89fbf066
9 changed files with 49 additions and 41 deletions

View file

@ -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

View file

@ -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:

View file

@ -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)

View file

@ -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()

View file

@ -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__":

View file

@ -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)

View file

@ -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)

View file

@ -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([
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)
@ -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")
@ -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