Skip to content

Commit

Permalink
Merge pull request #126 from mcci-usb/v420
Browse files Browse the repository at this point in the history
Version 4.2.0
  • Loading branch information
vseenivasan authored Nov 29, 2023
2 parents fce96db + 6ee526e commit 3622fc3
Show file tree
Hide file tree
Showing 54 changed files with 3,308 additions and 773 deletions.
21 changes: 19 additions & 2 deletions src/comDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,11 +254,18 @@ def get_devices(self):
self.top.UpdateSingle("No Switch found", 3)

def DeviceAdd(self, evt):
"""
Handle the event for adding devices.
Args:
evt: The event object.
Returns:
None
"""

ilist = self.fst_lb.GetItems()
slist = self.fst_lb.GetSelections()


flist = []
temp_list = []
self.top.switch_list.clear()
Expand Down Expand Up @@ -403,6 +410,16 @@ def OnSize (self, evt):
self.Layout()

def EVT_RESULT(win, func):
"""
Bind a function to the custom result event.
Args:
win: The window to which the event is connected.
func: The function to be called when the event occurs.
Returns:
None
"""
win.Connect(-1, -1, EVT_RESULT_ID, func)

def get_devices(top):
Expand Down
174 changes: 171 additions & 3 deletions src/configdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@
import defaultconfig

def get_user_data_dir():
"""
Get the user-specific data directory based on the operating system.
Returns:
Path: The user-specific data directory as a `Path` object.
"""

if sys.platform == "win32":
import winreg
key = winreg.OpenKey(winreg.HKEY_CURRENT_USER,
Expand All @@ -45,19 +52,44 @@ def get_user_data_dir():


def get_file_path():
"""
Get the file path for a configuration file in the user-specific data directory.
Returns:
str: The full path to the configuration file.
"""
lpath = get_user_data_dir()
dpath = os.path.join(lpath, "MCCI", "Cricket")

os.makedirs(dpath, exist_ok=True)
fpath = os.path.join(dpath, "config.json")
return fpath


def save_config(fpath, cdata):
"""
Save configuration data to a specified file.
Args:
fpath (str): The path to the file where the configuration data will be saved.
cdata (dict): The configuration data to be saved.
Returns:
None
"""
with open(fpath, "w") as out_file:
json.dump(cdata, out_file)

def read_config(fpath):
"""
Read configuration data from a specified file.
Args:
fpath (str): The path to the file from which configuration data will be read.
Returns:
dict: The configuration data read from the file. If the file doesn't exist or
cannot be read, an empty dictionary is returned.
"""
cdata = None
try:
with open(fpath, 'r') as open_file:
Expand All @@ -68,13 +100,27 @@ def read_config(fpath):


def load_default_config():
"""
Load the default configuration data, save it to a file, and return the loaded data.
Returns:
dict: The default configuration data loaded and saved to a file.
"""
cdata = defaultconfig.config_data
fpath = get_file_path()
save_config(fpath, cdata)
return cdata


def read_all_config():
"""
Read configuration data from a file. If the file doesn't exist or cannot be read,
load the default configuration data, save it to the file, and return the loaded data.
Returns:
dict: The configuration data read from the file or the default configuration data
loaded and saved to the file.
"""
cdata = None
fpath = get_file_path()
try:
Expand All @@ -85,6 +131,20 @@ def read_all_config():
return cdata

def set_sut_base_data(gdata):
"""
Set base data for the System Under Test (SUT) in the configuration.
Args:
gdata (dict): The base data to be set for the SUT. The dictionary should have
a single key representing the SUT, and its corresponding value.
Returns:
None
Raises:
ValueError: If the provided key in `gdata` does not match any existing SUT key
in the configuration.
"""
cdata = read_all_config()

key = list(gdata.keys())[0]
Expand All @@ -96,8 +156,22 @@ def set_sut_base_data(gdata):
else:
print("\nData config error!")


def set_sut_config_data(gdata):
"""
Set configuration data for the System Under Test (SUT) in the configuration.
Args:
gdata (dict): The configuration data to be set for the SUT. The dictionary
should have a key representing the SUT, and its value should
be another dictionary with the configuration data.
Returns:
None
Raises:
ValueError: If the provided key in `gdata` does not match any existing SUT key
in the configuration.
"""
cdata = read_all_config()
key = list(gdata.keys())[0]
keys = list(cdata["dut"].keys())
Expand All @@ -109,8 +183,22 @@ def set_sut_config_data(gdata):
else:
print("\nData config error!")


def set_sut_watch_data(gdata):
"""
Set watch data for the System Under Test (SUT) in the configuration.
Args:
gdata (dict): The watch data to be set for the SUT. The dictionary should
have a key representing the SUT, and its value should be a
dictionary with watch data.
Returns:
None
Raises:
ValueError: If the provided key in `gdata` does not match any existing SUT key
in the configuration.
"""
cdata = read_all_config()

key = list(gdata.keys())[0]
Expand All @@ -127,13 +215,35 @@ def set_sut_watch_data(gdata):
# To store Config menu, DUT selection menu

def set_base_config_data(gdata):
"""
Set base configuration data in the configuration.
Args:
gdata (dict): The base configuration data to be set. The dictionary should
include keys 'myrole' and 'dut' with their corresponding values.
Returns:
None
"""
cdata = read_all_config()
cdata["myrole"] = gdata["myrole"]
cdata["dut"]["nodes"] = gdata["dut"]["nodes"]
cdata["rpanel"] = gdata["rpanel"]
fpath = get_file_path()
save_config(fpath, cdata)

def set_switch_config(gdata):
"""
Set switch configuration data in the configuration.
Args:
gdata (dict): The switch configuration data to be set. The dictionary should
have a key representing the switch, and its value should be the
configuration data for that switch.
Returns:
None
"""
cdata = read_all_config()
# cdata["swconfig"] = gdata
key = list(gdata.keys())[0]
Expand All @@ -146,19 +256,77 @@ def set_switch_config(gdata):
save_config(fpath, cdata)

def updt_batch_location(bloc):
"""
Update the batch location in the configuration.
Args:
bloc (str): The new batch location to be set.
Returns:
None
"""
cdata = read_all_config()
cdata["batch"]["location"] = bloc
fpath = get_file_path()
save_config(fpath, cdata)

def updt_screen_size(gdata):
"""
Update the screen size configuration in the global configuration.
Args:
gdata (dict): The new screen size configuration.
Returns:
None
"""
cdata = read_all_config()
cdata["screen"] = gdata["screen"]
fpath = get_file_path()
save_config(fpath, cdata)

def updt_warning_dialog(gdata):
"""
Update the warning dialog configuration in the global configuration.
Args:
gdata (dict): The new warning dialog configuration.
Returns:
None
"""
cdata = read_all_config()
cdata["wdialog"] = gdata["wdialog"]
fpath = get_file_path()
save_config(fpath, cdata)

def updt_portal_credentials(gdata):
"""
Update the portal credentials configuration in the global configuration.
Args:
gdata (dict): The new portal credentials configuration.
Returns:
None
"""
cdata = read_all_config()
cdata["msudp"] = gdata["msudp"]
fpath = get_file_path()
save_config(fpath, cdata)

def read_msudp_config():
"""
Read the portal credentials configuration from the global configuration.
Returns:
dict: The portal credentials configuration.
"""
cdata = None
fpath = get_file_path()
try:
with open(fpath, 'r') as open_file:
cdata = json.load(open_file)
except:
cdata = load_default_config()
return cdata["msudp"]
4 changes: 3 additions & 1 deletion src/defaultconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,7 @@
},
"batch" : {"location": ""},
"screen": {"pos": [], "size": []},
"wdialog": False
"wdialog": False,
"msudp": {"uname": "mcci", "pwd": "mcci"},
"rpanel": {"dut1": True, "dut2": True, "u4tree": True}
}
Loading

0 comments on commit 3622fc3

Please sign in to comment.