Move unused modules into archive.
This commit is contained in:
@@ -1,11 +1,13 @@
|
||||
import logging
|
||||
import pathlib
|
||||
|
||||
from iottb import definitions
|
||||
from iottb.definitions import DEVICE_METADATA_FILE, ReturnCodes
|
||||
from iottb.definitions import DEVICE_METADATA_FILE
|
||||
from iottb.logger import logger
|
||||
from iottb.models.device_metadata_model import DeviceMetadata
|
||||
from iottb.utils.device_metadata_utils import *
|
||||
from archive.device_metadata_utils import *
|
||||
|
||||
logger.setLevel(logging.INFO) # Since module currently passes all tests
|
||||
|
||||
def setup_init_device_root_parser(subparsers):
|
||||
parser = subparsers.add_parser('add-device', aliases=['add-device-root', 'add'])
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
from iottb.definitions import ReturnCodes
|
||||
|
||||
|
||||
def set_device_ip_address(ip_addr: str, file_path: Path):
|
||||
assert ip_addr is not None
|
||||
assert file_path.is_file()
|
||||
with file_path.open('r') as f:
|
||||
data = json.load(f)
|
||||
current_ip = data['device_ip_address']
|
||||
if current_ip is not None:
|
||||
print(f'Device IP Address is set to {current_ip}')
|
||||
response = input(f'Do you want to change the recorded IP address to {ip_addr}? [Y/N] ')
|
||||
if response.upper() == 'N':
|
||||
print('Aborting change to device IP address')
|
||||
return ReturnCodes.ABORTED
|
||||
with file_path.open('w') as f:
|
||||
json.dump(data, f)
|
||||
return ReturnCodes.SUCCESS
|
||||
|
||||
|
||||
def set_device_mac_address(mac_addr: str, file_path: Path):
|
||||
assert mac_addr is not None
|
||||
assert file_path.is_file()
|
||||
with file_path.open('r') as f:
|
||||
data = json.load(f)
|
||||
current_mac = data['device_mac_address']
|
||||
if current_mac is not None:
|
||||
print(f'Device MAC Address is set to {current_mac}')
|
||||
response = input(f'Do you want to change the recorded MAC address to {mac_addr}? [Y/N] ')
|
||||
if response.upper() == 'N':
|
||||
print('Aborting change to device MAC address')
|
||||
return ReturnCodes.ABORTED
|
||||
with file_path.open('w') as f:
|
||||
json.dump(data, f)
|
||||
return ReturnCodes.SUCCESS
|
||||
@@ -1,51 +0,0 @@
|
||||
import json
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
|
||||
from iottb.definitions import ReturnCodes
|
||||
|
||||
|
||||
def update_firmware_version(version: str, file_path: Path):
|
||||
assert file_path.is_file()
|
||||
with file_path.open('r') as file:
|
||||
metadata = json.load(file)
|
||||
metadata['device_firmware_version'] = version
|
||||
metadata['date_updated'] = datetime.now().strftime('%d-%m-%YT%H:%M:%S').lower()
|
||||
with file_path.open('w') as file:
|
||||
json.dump(metadata, file)
|
||||
return ReturnCodes.SUCCESS
|
||||
|
||||
|
||||
def add_capture_file_reference(capture_file_reference: str, file_path: Path):
|
||||
assert file_path.is_file()
|
||||
with file_path.open('r') as file:
|
||||
metadata = json.load(file)
|
||||
metadata['capture_files'] = capture_file_reference
|
||||
metadata['date_updated'] = datetime.now().strftime('%d-%m-%YT%H:%M:%S').lower()
|
||||
with file_path.open('w') as file:
|
||||
json.dump(metadata, file)
|
||||
return ReturnCodes.SUCCESS
|
||||
|
||||
|
||||
def update_device_serial_number(device_id: str, file_path: Path):
|
||||
assert file_path.is_file()
|
||||
with file_path.open('r') as file:
|
||||
metadata = json.load(file)
|
||||
metadata['device_id'] = device_id
|
||||
metadata['date_updated'] = datetime.now().strftime('%d-%m-%YT%H:%M:%S').lower()
|
||||
with file_path.open('w') as file:
|
||||
json.dump(metadata, file)
|
||||
return ReturnCodes.SUCCESS
|
||||
|
||||
|
||||
def update_device_type(device_type: str, file_path: Path):
|
||||
assert file_path.is_file()
|
||||
with file_path.open('r') as file:
|
||||
metadata = json.load(file)
|
||||
metadata['device_type'] = device_type
|
||||
metadata['date_updated'] = datetime.now().strftime('%d-%m-%YT%H:%M:%S').lower()
|
||||
with file_path.open('w') as file:
|
||||
json.dump(metadata, file)
|
||||
return ReturnCodes.SUCCESS
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ import shutil
|
||||
from iottb.__main__ import main
|
||||
|
||||
|
||||
class TestDeviceSetup(unittest.TestCase):
|
||||
class TestDeviceMetadataFileCreation(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.test_dir = Path('/tmp/iottbtest/test_add_device')
|
||||
self.test_dir.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
@@ -1,6 +1,2 @@
|
||||
import json
|
||||
from pathlib import Path
|
||||
from unittest.mock import mock_open, patch
|
||||
import pytest
|
||||
|
||||
from iottb.utils.capture_metadata_utils import set_device_ip_address
|
||||
|
||||
|
||||
Reference in New Issue
Block a user