Index: shared/scripts/configuration/utility.py =================================================================== diff -u -r812fa8b32b6fc107eb56cf1ab7b4c9ffc581f661 -r2413e6298b362ada05bed6e59568300c2034e18d --- shared/scripts/configuration/utility.py (.../utility.py) (revision 812fa8b32b6fc107eb56cf1ab7b4c9ffc581f661) +++ shared/scripts/configuration/utility.py (.../utility.py) (revision 2413e6298b362ada05bed6e59568300c2034e18d) @@ -34,9 +34,11 @@ from dialin.protocols import DenaliMessage, DenaliCanMessenger, DenaliChannels from datetime import datetime - +CLOUD_CREDENTIALS_LOCATION = '/home/denali/Desktop/cloudsync/credentials' +CLOUD_SYNC_LOG_LOCATION = '/home/denali/Desktop/sd-card/cloudsync/' LOG_LOCATION = "/home/denali/Desktop/sd-card/log/*.log" + def color_verification(exp_val = "Red", act_val = "#c53b33"): test.compare(config.COLOR_CODES[color_name],(act_val.color[name])) @@ -985,3 +987,98 @@ return names.o_recirculate_rejection_msg +def get_current_date_and_time(date_format='%Y/%m/%d - %H:%M:%S'): + """ + Method to get current date and time. + @input date_format (str) - format of date to be retrieved. + @return (str) - date in specified format. + """ + date = datetime.now() + return str(date.strftime(date_format)) + + +def append_cloudsync_credentials_file(): + """ + This function is used for creating .pem files in the cloudsync folder. + pem files is created on '/home/denali/Desktop/cloudsync/credentials' + """ + PEM_FILES = ['1.pem', '2.pem', '3.pem' ] + try: + os.makedirs(CLOUD_CREDENTIALS_LOCATION, exist_ok = True) + test.log("Directory created successfully") + for file_handler in range(len(PEM_FILES)): + path = os.path.join(CLOUD_CREDENTIALS_LOCATION, PEM_FILES[file_handler]) + with open(path, 'w') as file_reader: + pass + except OSError: + test.log("Directory can not be created") + + +def get_cloud_sync_input_file(): + """ + This function is the handler for getting file from log folder. + Application log file is automatically created on '/home/denali/Desktop/sd-card/cloudsync/ {current_date}_inp.log' + @return latest_file - (string) returns latest input log file path from sd-data + """ + try: + current_date = get_current_date_and_time(date_format = "%Y_%m_%d") + latest_file = CLOUD_SYNC_LOG_LOCATION+current_date+'_inp.buf' + return latest_file + except: + return False + + +def get_cloud_sync_output_file(): + """ + This function is the handler for getting file from log folder. + Application log file is automatically created on '/home/denali/Desktop/sd-card/cloudsync/ {current_date}_out.log' + @return latest_file - (string) returns latest output log file path from sd-data + """ + try: + current_date = get_current_date_and_time(date_format = "%Y_%m_%d") + latest_file = CLOUD_SYNC_LOG_LOCATION+current_date+'_out.buf' + return latest_file + except: + return False + + +def retrive_log_data(readline_count = 1): + """ + This function is the handler for getting file from log folder. + Application log data is automatically appended on '/home/denali/Desktop/sd-card/cloudsync/ {current_date}_out.log' + @input readline_count (int) - number of line to be read from cloud-sync log. + @return cloudsync_data - (list) returns extracted log data. + """ + cloudsync_data = [] + count = 0 + file_name = get_cloud_sync_input_file() + try: + with open(file_name,mode = 'r') as filereader: + contents = csv.reader(filereader) + try: + for reader in reversed(list(contents)): + if readline_count == count: + return cloudsync_data + cloudsync_data.append(reader) + count = count + 1 + except: + test.fail("application log data is corrupted") + except: + test.fail("Log file is not created or log file is not created based on standard log naming format.") + + +def get_epoch_value_consistancy(current_epoch_value, expected_epoch_value): + """ + This function is verify consistancy of epoch value. + @input current_epoch_value (float) - current epoch time + @input expected_epoch_value (str) - epoch time from cloud-sync log. + @return (bool) - True - if expected value is in range. else, return False + """ + expected_epoch_value = int(expected_epoch_value) + maximum_epoch_value = int(current_epoch_value + 25) + minimum_epoch_value = int(current_epoch_value - 25) + + if expected_epoch_value > minimum_epoch_value and expected_epoch_value < maximum_epoch_value : + return True + return False +