From 159d2fa346b4d96d389b0ce21c7e83e2f0c08476 Mon Sep 17 00:00:00 2001 From: Taylor Helsper Date: Wed, 27 Oct 2021 20:42:12 -0500 Subject: [PATCH] Fix exceptino if upgrade_logs folder didn't exist --- rootfs/standard/var/www/mynode/device_info.py | 41 +++++++++++-------- 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/rootfs/standard/var/www/mynode/device_info.py b/rootfs/standard/var/www/mynode/device_info.py index 52149e62..2bd139ce 100644 --- a/rootfs/standard/var/www/mynode/device_info.py +++ b/rootfs/standard/var/www/mynode/device_info.py @@ -218,29 +218,34 @@ def get_all_upgrade_logs(): folder = "/home/admin/upgrade_logs/" log_id = 0 - # Add latest upgrade log - if os.path.isfile( os.path.join(folder, "upgrade_log_latest.txt") ): - log = {} - log["id"] = log_id - log["name"] = "Latest Upgrade" - modTimeSeconds = os.path.getmtime( os.path.join(folder, "upgrade_log_latest.txt") ) - log["date"] = time.strftime('%Y-%m-%d', time.localtime(modTimeSeconds)) - log["log"] = get_recent_upgrade_log() - log_list.append( log ) - log_id += 1 - - # Add file logs - for f in os.listdir(folder): - fullpath = os.path.join(folder, f) - if os.path.isfile( fullpath ): + try: + # Add latest upgrade log + if os.path.isfile( os.path.join(folder, "upgrade_log_latest.txt") ): log = {} log["id"] = log_id - log["name"] = f - modTimeSeconds = os.path.getmtime(fullpath) + log["name"] = "Latest Upgrade" + modTimeSeconds = os.path.getmtime( os.path.join(folder, "upgrade_log_latest.txt") ) log["date"] = time.strftime('%Y-%m-%d', time.localtime(modTimeSeconds)) - log["log"] = cleanup_log( get_file_contents(fullpath).decode("utf8") ) + log["log"] = get_recent_upgrade_log() log_list.append( log ) log_id += 1 + + # Add file logs + if os.path.isdir(folder): + for f in os.listdir(folder): + fullpath = os.path.join(folder, f) + if os.path.isfile( fullpath ): + log = {} + log["id"] = log_id + log["name"] = f + modTimeSeconds = os.path.getmtime(fullpath) + log["date"] = time.strftime('%Y-%m-%d', time.localtime(modTimeSeconds)) + log["log"] = cleanup_log( get_file_contents(fullpath).decode("utf8") ) + log_list.append( log ) + log_id += 1 + except Exception as e: + pass + return log_list def has_checkin_error():