Refactor various names.
This commit is contained in:
parent
27de5b4587
commit
7e3e101987
3
.idea/2024-bsc-sebastian-lenzlinger.iml
generated
3
.idea/2024-bsc-sebastian-lenzlinger.iml
generated
@ -4,4 +4,7 @@
|
||||
<option name="format" value="PLAIN" />
|
||||
<option name="myDocStringFormat" value="Plain" />
|
||||
</component>
|
||||
<component name="TestRunnerService">
|
||||
<option name="PROJECT_TEST_RUNNER" value="py.test" />
|
||||
</component>
|
||||
</module>
|
||||
40
.idea/workspace.xml
generated
40
.idea/workspace.xml
generated
@ -4,9 +4,26 @@
|
||||
<option name="autoReloadType" value="SELECTIVE" />
|
||||
</component>
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="7a3ac8e1-7fbf-4aa7-9cf9-a51d7ade8503" name="Changes" comment="Start tracking development config files.">
|
||||
<list default="true" id="7a3ac8e1-7fbf-4aa7-9cf9-a51d7ade8503" name="Changes" comment="SYNC">
|
||||
<change afterPath="$PROJECT_DIR$/code/iottb/cli.py" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/code/iottb/utils/__init__.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/.idea/2024-bsc-sebastian-lenzlinger.iml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/2024-bsc-sebastian-lenzlinger.iml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/code/kydcap/subcommands/sniff.py" beforeDir="false" afterPath="$PROJECT_DIR$/code/kydcap/subcommands/sniff.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/archive/metadata_utils.py" beforeDir="false" afterPath="$PROJECT_DIR$/archive/metadata_utils.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/code/kydcap/__init__.py" beforeDir="false" afterPath="$PROJECT_DIR$/code/iottb/__init__.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/code/kydcap/__main__.py" beforeDir="false" afterPath="$PROJECT_DIR$/code/iottb/__main__.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/code/kydcap/config.py" beforeDir="false" afterPath="$PROJECT_DIR$/code/iottb/definitions.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/code/kydcap/models/__init__.py" beforeDir="false" afterPath="$PROJECT_DIR$/code/iottb/models/__init__.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/code/kydcap/models/capture_metadata_model.py" beforeDir="false" afterPath="$PROJECT_DIR$/code/iottb/models/capture_metadata_model.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/code/kydcap/models/device_metadata_model.py" beforeDir="false" afterPath="$PROJECT_DIR$/code/iottb/models/device_metadata_model.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/code/kydcap/subcommands/__init__.py" beforeDir="false" afterPath="$PROJECT_DIR$/code/iottb/subcommands/__init__.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/code/kydcap/subcommands/initialize_device_root_dir.py" beforeDir="false" afterPath="$PROJECT_DIR$/code/iottb/subcommands/init.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/code/kydcap/subcommands/sniff.py" beforeDir="false" afterPath="$PROJECT_DIR$/code/iottb/subcommands/capture.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/code/kydcap/utils/__init__.py" beforeDir="false" afterPath="$PROJECT_DIR$/code/iottb/subcommands/config.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/code/kydcap/utils/capture_metadata_utils.py" beforeDir="false" afterPath="$PROJECT_DIR$/code/iottb/utils/capture_metadata_utils.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/code/kydcap/utils/device_metadata_utils.py" beforeDir="false" afterPath="$PROJECT_DIR$/code/iottb/utils/device_metadata_utils.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/code/kydcap/utils/tcpdump_utils.py" beforeDir="false" afterPath="$PROJECT_DIR$/code/iottb/utils/tcpdump_utils.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/code/tests/utils/test_capture_metadata_utils.py" beforeDir="false" afterPath="$PROJECT_DIR$/code/tests/utils/test_capture_metadata_utils.py" afterDir="false" />
|
||||
</list>
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
@ -24,7 +41,7 @@
|
||||
<option name="PUSH_AUTO_UPDATE" value="true" />
|
||||
<option name="RECENT_BRANCH_BY_REPOSITORY">
|
||||
<map>
|
||||
<entry key="$PROJECT_DIR$" value="main" />
|
||||
<entry key="$PROJECT_DIR$" value="sync" />
|
||||
</map>
|
||||
</option>
|
||||
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
|
||||
@ -50,7 +67,7 @@
|
||||
"Python.main.executor": "Run",
|
||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||
"SHARE_PROJECT_CONFIGURATION_FILES": "true",
|
||||
"git-widget-placeholder": "main",
|
||||
"git-widget-placeholder": "cli-dev",
|
||||
"last_opened_file_path": "/home/slnopriv/projects/2024-bsc-sebastian-lenzlinger/code/kydcap/utils/device_metadata_utils.py",
|
||||
"node.js.detected.package.eslint": "true",
|
||||
"node.js.detected.package.tslint": "true",
|
||||
@ -147,6 +164,8 @@
|
||||
<workItem from="1714554228183" duration="34000" />
|
||||
<workItem from="1714554269789" duration="56478000" />
|
||||
<workItem from="1714616237168" duration="6135000" />
|
||||
<workItem from="1714850899817" duration="2659000" />
|
||||
<workItem from="1714917763516" duration="1306000" />
|
||||
</task>
|
||||
<task id="LOCAL-00001" summary="Add code for capture testbed. This is a huge commit. End of day sync...">
|
||||
<option name="closed" value="true" />
|
||||
@ -196,7 +215,15 @@
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1714617266799</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="7" />
|
||||
<task id="LOCAL-00007" summary="SYNC">
|
||||
<option name="closed" value="true" />
|
||||
<created>1714823516954</created>
|
||||
<option name="number" value="00007" />
|
||||
<option name="presentableId" value="LOCAL-00007" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1714823516954</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="8" />
|
||||
<servers />
|
||||
</component>
|
||||
<component name="TypeScriptGeneratedFilesManager">
|
||||
@ -252,7 +279,8 @@
|
||||
<MESSAGE value="Add test module." />
|
||||
<MESSAGE value="Update gitignore again." />
|
||||
<MESSAGE value="Start tracking development config files." />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="Start tracking development config files." />
|
||||
<MESSAGE value="SYNC" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="SYNC" />
|
||||
</component>
|
||||
<component name="com.intellij.coverage.CoverageDataManagerImpl">
|
||||
<SUITE FILE_PATH="coverage/2024_bsc_sebastian_lenzlinger$__init__.coverage" NAME="__init__ Coverage Results" MODIFIED="1714619300966" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="false" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/code/kydcap" />
|
||||
|
||||
@ -3,8 +3,8 @@ from pathlib import Path
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
from kydcap.models.device_metadata_model import DeviceMetadata
|
||||
from kydcap.config import DEVICE_METADATA_FILE
|
||||
from iottb.models.device_metadata_model import DeviceMetadata
|
||||
from iottb.definitions import DEVICE_METADATA_FILE
|
||||
|
||||
|
||||
def write_device_metadata_to_file(metadata: DeviceMetadata, device_path: Path):
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
#!/usr/bin/env python3
|
||||
import argparse
|
||||
|
||||
from kydcap.subcommands.sniff import setup_sniff_parser
|
||||
from kydcap.subcommands.initialize_device_root_dir import setup_init_root_dir_parser
|
||||
from iottb.subcommands.capture import setup_capture_parser
|
||||
from iottb.subcommands.init import setup_init_iottb_root_parser
|
||||
|
||||
CAP_DIR_PREFIX = ...
|
||||
|
||||
@ -12,11 +12,11 @@ CAP_DIR_PREFIX = ...
|
||||
######################
|
||||
def setup_argparse():
|
||||
# create top level parser
|
||||
root_parser = argparse.ArgumentParser(prog="kydcap")
|
||||
root_parser = argparse.ArgumentParser(prog="iottb")
|
||||
subparsers = root_parser.add_subparsers(title="subcommands", required=True, dest="command")
|
||||
|
||||
setup_sniff_parser(subparsers)
|
||||
setup_init_root_dir_parser(subparsers)
|
||||
setup_capture_parser(subparsers)
|
||||
setup_init_iottb_root_parser(subparsers)
|
||||
|
||||
return root_parser
|
||||
|
||||
2
code/iottb/cli.py
Normal file
2
code/iottb/cli.py
Normal file
@ -0,0 +1,2 @@
|
||||
import argparse
|
||||
from .subcommands.capture import handle_sniff
|
||||
@ -4,7 +4,7 @@ from enum import Flag, unique, global_enum
|
||||
|
||||
DEVICE_METADATA_FILE = "device-metadata.json"
|
||||
CAPTURE_METADATA_FILE = "capture-metadata.json"
|
||||
TODAY_DATE_STRING = datetime.now().strftime("%d%b%Y").lower()
|
||||
TODAY_DATE_STRING = datetime.now().strftime("%d%b%Y").lower() # TODO convert to function in utils or so
|
||||
|
||||
|
||||
@unique
|
||||
@ -6,7 +6,7 @@ from typing import Optional, Any
|
||||
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
from kydcap.config import ReturnCodes
|
||||
from iottb.definitions import ReturnCodes
|
||||
|
||||
|
||||
class KydcapCaptureMetadata(BaseModel):
|
||||
@ -19,6 +19,7 @@ class KydcapCaptureMetadata(BaseModel):
|
||||
start_time: str
|
||||
stop_time: str
|
||||
packet_count: Optional[int]
|
||||
pcap_filter: str = ""
|
||||
|
||||
# Optional Fields
|
||||
device_ip_address: Optional[str] = None
|
||||
@ -4,8 +4,8 @@ from datetime import datetime
|
||||
from pathlib import Path
|
||||
from typing import Optional, List, Any
|
||||
|
||||
# kydcap modules
|
||||
from kydcap.config import ReturnCodes
|
||||
# iottb modules
|
||||
from iottb.definitions import ReturnCodes
|
||||
|
||||
# 3rd party libs
|
||||
from pydantic import BaseModel, Field
|
||||
@ -1,17 +1,17 @@
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
|
||||
from kydcap.config import *
|
||||
from kydcap.models.device_metadata_model import DeviceMetadata
|
||||
from iottb.definitions import *
|
||||
from iottb.models.device_metadata_model import DeviceMetadata
|
||||
|
||||
|
||||
def setup_sniff_parser(subparsers):
|
||||
def setup_capture_parser(subparsers):
|
||||
parser = subparsers.add_parser('sniff', help='Sniff packets with tcpdump')
|
||||
# metadata args
|
||||
parser.add_argument("-a", "--ip-address=", help="IP address of the device to sniff", dest="device_ip")
|
||||
parser.add_argument("-a", "--ip-address", help="IP address of the device to sniff", dest="device_ip")
|
||||
# tcpdump args
|
||||
parser_sniff_tcpdump = parser.add_argument_group('tcpdump arguments')
|
||||
parser_sniff_tcpdump.add_argument("-i", "--interface=", help="Interface to capture on.", dest="capture_interface",
|
||||
parser_sniff_tcpdump.add_argument("-i", "--interface", help="Interface to capture on.", dest="capture_interface",
|
||||
default="any")
|
||||
parser_sniff_tcpdump.add_argument("-I", "--monitor-mode", help="Put interface into monitor mode",
|
||||
action="store_true")
|
||||
@ -30,7 +30,7 @@ def setup_sniff_parser(subparsers):
|
||||
cap_size_group = parser.add_mutually_exclusive_group(required=False)
|
||||
cap_size_group.add_argument("-c", "--count", type=int, help="Number of packets to capture.", default=0)
|
||||
cap_size_group.add_argument("--mins", type=int, help="Time in minutes to capture.", default=60)
|
||||
parser.set_defaults(func=handle_sniff)
|
||||
parser.set_defaults(func=handle_capture)
|
||||
# return parser
|
||||
# parser.add_default(func=handle_sniff(args=sniff_args))
|
||||
|
||||
@ -40,6 +40,9 @@ def cwd_is_device_root_dir() -> bool:
|
||||
return device_metadata_file.exists()
|
||||
|
||||
|
||||
def get_user_capture_config():
|
||||
pass
|
||||
|
||||
def start_guided_device_root_dir_setup():
|
||||
assert False, "Not implemented"
|
||||
|
||||
@ -52,7 +55,7 @@ def handle_metadata():
|
||||
if response.lower() == "y":
|
||||
start_guided_device_root_dir_setup()
|
||||
else:
|
||||
print("'kydcap init-device-root --help' for more information.")
|
||||
print("'iottb init-device-root --help' for more information.")
|
||||
exit(ReturnCodes.ABORTED)
|
||||
# device_id = handle_capture_metadata()
|
||||
return ReturnCodes.SUCCESS
|
||||
@ -68,9 +71,12 @@ def handle_capture_metadata():
|
||||
def handle_date_dir():
|
||||
pass
|
||||
|
||||
|
||||
def run_tcpdum(cmd):
|
||||
subprocess.run(cmd)
|
||||
def handle_sniff(args):
|
||||
|
||||
|
||||
def handle_capture(args):
|
||||
if cwd_is_device_root_dir():
|
||||
handle_date_dir()
|
||||
cmd = ['sudo tcpdump', '-i', args.capture_interface]
|
||||
@ -1,11 +1,11 @@
|
||||
import pathlib
|
||||
|
||||
from kydcap.config import DEVICE_METADATA_FILE
|
||||
from kydcap.models.device_metadata_model import DeviceMetadata
|
||||
from iottb.definitions import DEVICE_METADATA_FILE
|
||||
from iottb.models.device_metadata_model import DeviceMetadata
|
||||
|
||||
|
||||
def setup_init_root_dir_parser(subparsers):
|
||||
parser = subparsers.add_parser("init-device-root", aliases=["idr"])
|
||||
def setup_init_iottb_root_parser(subparsers):
|
||||
parser = subparsers.add_parser("init", aliases=["idr"])
|
||||
parser.add_argument("--root_dir", type=pathlib.Path, default=pathlib.Path.cwd())
|
||||
group = parser.add_mutually_exclusive_group()
|
||||
group.add_argument("--dynamic", action="store_true", help="enable guided setup", default=False)
|
||||
@ -14,7 +14,7 @@ def setup_init_root_dir_parser(subparsers):
|
||||
|
||||
|
||||
def handle_idr(args):
|
||||
print("Entered kydcap initialize-device-root")
|
||||
print("Entered iottb initialize-device-root")
|
||||
root_dir = args.root_dir
|
||||
device_name = None
|
||||
if args.dynamic:
|
||||
0
code/iottb/utils/__init__.py
Normal file
0
code/iottb/utils/__init__.py
Normal file
@ -1,7 +1,7 @@
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
from kydcap.config import ReturnCodes
|
||||
from iottb.definitions import ReturnCodes
|
||||
|
||||
|
||||
def set_device_ip_address(ip_addr: str, file_path: Path):
|
||||
@ -2,7 +2,7 @@ import json
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
|
||||
from kydcap.config import ReturnCodes
|
||||
from iottb.definitions import ReturnCodes
|
||||
|
||||
|
||||
def update_firmware_version(version: str, file_path: Path):
|
||||
@ -3,4 +3,4 @@ from pathlib import Path
|
||||
from unittest.mock import mock_open, patch
|
||||
import pytest
|
||||
|
||||
from kydcap.utils.capture_metadata_utils import set_device_ip_address
|
||||
from iottb.utils.capture_metadata_utils import set_device_ip_address
|
||||
Loading…
x
Reference in New Issue
Block a user