Index: shared/scripts/configuration/utility.py =================================================================== diff -u -r8a47faf40db724c9f1360b5e5579530410ee86ca -r26be96f1f86d5823902beed32660f12cdb87d881 --- shared/scripts/configuration/utility.py (.../utility.py) (revision 8a47faf40db724c9f1360b5e5579530410ee86ca) +++ shared/scripts/configuration/utility.py (.../utility.py) (revision 26be96f1f86d5823902beed32660f12cdb87d881) @@ -13,27 +13,25 @@ ############################################################################ import os -import names +import csv import test -import object -import squish -import glob -from configuration import config -from builtins import int as pyInt - + CLOUD_CREDENTIALS_LOCATION = '/home/denali/Desktop/cloudsync/credentials' -CLOUD_SYNC_LOG_LOCATION = '/home/denali/Desktop/sd-card/cloudsync' +CLOUD_SYNC_LOG_LOCATION = '/home/denali/Desktop/sd-card/cloudsync/' + PEM_FILES = ['1.pem', '2.pem', '3.pem' ] + def get_current_date_and_time(date_format='%Y/%b/%d - %H:%M:%S'): date = datetime.now() return str(date.strftime(date_format)) + def append_cloudsync_credentials_file(): try: @@ -47,21 +45,56 @@ except OSError as error: test.log("Directory can not be created") -def get_extracted_file_inp_buf(): + +def get_cloud_sync_input_file(): """ - This function is the handler for getting file from cloudsync folder. + 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 file that append on log folder 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 file that append on log folder 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 - This handler will go inside cloudsync folder and looks for newly added input buf file based on current time. - If it is satisfying that condition, it will return the exact path of newly created input buf file. - @return latest_file - (string) returns latest file that append on log folder from sd-data +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}_input.log' + @return latest_file - (list) returns latest file that append on log folder from sd-data + """ + cloudsync_data = [] + count = 0 + file_name = get_cloud_sync_input_file() try: - list_of_files = glob.glob(config.CLOUD_SYNC_INP__BUF_LOCATION) - latest_file = max(list_of_files, key=os.path.getctime) - test.log(str(latest_file)) - return str(latest_file) + 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("input buf file is not created during application interaction") - return False - \ No newline at end of file + test.fail("Log file is not created or log file is not created based on standard log naming format.") + + \ No newline at end of file