########################################################################### # # Copyright (c) 2019-2021 Diality Inc. - All Rights Reserved. # # THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN # WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. # # @file utils.py # # @author (last) LTTS # @date (last) 08-July-2022 # ############################################################################ import os import names 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' 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: 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 as error: test.log("Directory can not be created") def get_extracted_file_inp_buf(): """ This function is the handler for getting file from cloudsync folder. 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 """ 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) except: test.fail("input buf file is not created during application interaction") return False