-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Also switched from default single quoted string to double. - Source code moved from ./src/iproute4mac to ./iproute4mac. - Ruff code style applied.
- Loading branch information
Showing
21 changed files
with
1,012 additions
and
1,037 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
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 |
---|---|---|
|
@@ -2,6 +2,7 @@ __pycache__/ | |
build/ | ||
dist/ | ||
venv/ | ||
.tox/ | ||
*.egg-info/ | ||
_sharedmem.cpython* | ||
.ipynb_checkpoints/ | ||
|
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,22 +1,8 @@ | ||
default_language_version: | ||
python: python3 | ||
repos: | ||
- repo: https://github.com/pycqa/flake8 | ||
rev: 7.1.0 | ||
- repo: https://github.com/astral-sh/ruff-pre-commit | ||
rev: v0.5.4 | ||
hooks: | ||
- id: flake8 | ||
pass_filenames: false | ||
args: [ | ||
src, | ||
--select, 'E9,F63,F7,F82', | ||
--show-source, | ||
--statistics | ||
] | ||
- id: flake8 | ||
pass_filenames: false | ||
args: [ | ||
src, | ||
--max-line-length=128, | ||
--statistics, | ||
--ignore, 'F403,F405,W503' | ||
] | ||
- id: ruff | ||
- id: ruff-format |
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
line-length = 128 | ||
|
||
[lint] | ||
ignore = ["F403", "F405"] |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
VERSION = "0.2.0" |
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 |
---|---|---|
@@ -0,0 +1,138 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import sys | ||
|
||
import iproute4mac | ||
from iproute4mac.utils import * | ||
from iproute4mac.iplink import * | ||
from iproute4mac.ipaddress import * | ||
|
||
|
||
def do_help(argv=[], option={}): | ||
usage() | ||
|
||
|
||
def usage(): | ||
stderr("""\ | ||
Usage: bridge [ OPTIONS ] OBJECT { COMMAND | help } | ||
bridge [ -force ] -batch filename | ||
where OBJECT := { link | fdb | mdb | vlan | vni | monitor } | ||
OPTIONS := { -V[ersion] | -s[tatistics] | -d[etails] | | ||
-o[neline] | -t[imestamp] | -n[etns] name | | ||
-com[pressvlans] -c[olor] -p[retty] -j[son] }""") | ||
exit(-1) | ||
|
||
|
||
""" Implemented objects """ | ||
objs = [ | ||
("link", do_notimplemented), | ||
("fdb", do_notimplemented), | ||
("mdb", do_notimplemented), | ||
("vlan", do_notimplemented), | ||
("vni", do_notimplemented), | ||
("monitor", do_notimplemented), | ||
("help", do_help), | ||
] | ||
|
||
|
||
def do_obj(argv, option): | ||
obj = argv.pop(0) | ||
for o, f in objs: | ||
if o.startswith(obj): | ||
return f(argv, option) | ||
|
||
stderr(f'Object "{obj}" is unknown, try "bridge help".') | ||
return EXIT_FAILURE | ||
|
||
|
||
def main(): | ||
batch_file = None | ||
option = { | ||
"preferred_family": AF_UNSPEC, | ||
"show_stats": False, | ||
"show_details": False, | ||
"oneline": False, | ||
"timestamp": False, | ||
"compress_vlans": False, | ||
"force": False, | ||
"json": False, | ||
"pretty": False, | ||
"do_all": False, | ||
} | ||
|
||
if sys.platform != "darwin": | ||
stderr("Unupported OS.") | ||
exit(-1) | ||
|
||
argv = sys.argv[1:] | ||
while argv: | ||
if argv[0] == "--": | ||
argv.pop(0) | ||
break | ||
elif argv[0][0] != "-": | ||
break | ||
|
||
opt = argv.pop(0) | ||
if opt[1] == "-": | ||
opt = opt[1:] | ||
|
||
if "-help".startswith(opt): | ||
usage() | ||
elif "-Version".startswith(opt): | ||
print(f"bridge wrapper, iproute4mac-{iproute4mac.VERSION}") | ||
exit(0) | ||
elif "-stats".startswith(opt) or "-statistics".startswith(opt): | ||
option["show_stats"] = True | ||
elif "-details".startswith(opt): | ||
option["show_details"] = True | ||
elif "-oneline".startswith(opt): | ||
option["oneline"] = True | ||
elif "-timestamp".startswith(opt): | ||
option["timestamp"] = True | ||
elif "-family".startswith(opt): | ||
try: | ||
opt = argv.pop(0) | ||
except IndexError: | ||
missarg("family type") | ||
if opt == "help": | ||
usage() | ||
option["preferred_family"] = read_family(opt) | ||
if option["preferred_family"] == AF_UNSPEC: | ||
invarg("invalid protocol family", opt) | ||
elif opt == "-4": | ||
option["preferred_family"] = AF_INET | ||
elif opt == "-6": | ||
option["preferred_family"] = AF_INET6 | ||
elif "-netns".startswith(opt): | ||
do_notimplemented() | ||
elif matches_color(opt): | ||
# Color option is not implemented | ||
pass | ||
elif "-compressvlans".startswith(opt): | ||
option["compress_vlans"] = True | ||
elif "-force".startswith(opt): | ||
option["force"] = True | ||
elif "-json".startswith(opt): | ||
option["json"] = True | ||
elif "-pretty".startswith(opt): | ||
option["pretty"] = True | ||
elif "-batch".startswith(opt): | ||
try: | ||
batch_file = argv.pop(0) | ||
except IndexError: | ||
missarg("batch file") | ||
else: | ||
stderr(f'Option "{opt}" is unknown, try "bridge help".') | ||
exit(-1) | ||
|
||
if batch_file: | ||
do_notimplemented() | ||
|
||
if argv: | ||
return do_obj(argv, option) | ||
|
||
usage() | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
Oops, something went wrong.