From 7b4333dc4ebbebfa17e57b4d1f75ccd3d0320e36 Mon Sep 17 00:00:00 2001 From: Konrad Kleine Date: Tue, 29 May 2007 21:24:01 +0200 Subject: [PATCH] Bug 590# fixed (codestyle issues) --- sugar/logger.py | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/sugar/logger.py b/sugar/logger.py index 6bec4c67..23160118 100644 --- a/sugar/logger.py +++ b/sugar/logger.py @@ -115,39 +115,45 @@ def start(module_id): def cleanup(): logs_dir = _get_logs_dir() - - #--------------------------------------------------------- - # Configure logfile backups - #--------------------------------------------------------- + # File extension for backed up logfiles. - file_suffix = int( time.time() ) + + file_suffix = int(time.time()) + # Absolute directory path where to store old logfiles. # It will be created recursivly if it's not present. + backup_dirpath = os.path.join(logs_dir, 'old') + # How many versions shall be backed up of every logfile? + num_backup_versions = 4 - #--------------------------------------------------------- # Make sure the backup location for old log files exists + if not os.path.exists(backup_dirpath): os.makedirs(backup_dirpath) # Iterate over every item in 'logs' directory + for filename in os.listdir(logs_dir): old_filepath = os.path.join(logs_dir, filename) if os.path.isfile(old_filepath): + # Backup every file + new_filename = filename + '.' + str(file_suffix) new_filepath = os.path.join(backup_dirpath, new_filename) os.rename(old_filepath, new_filepath) - backup_map = {} - # Tempoarily map all backup logfiles + for filename in os.listdir(backup_dirpath): + # Remove the 'file_suffix' from the filename. + end = filename.rfind(".") key = filename[0:end].lower() key = key.replace(".", "_") @@ -159,10 +165,9 @@ def cleanup(): backup_list.append( os.path.join(backup_dirpath, filename) ) - print backup_map - # Only keep 'num_backup_versions' versions of every logfile. # Remove the others. + for key in backup_map: backup_list = backup_map[key] backup_list.sort() @@ -170,4 +175,4 @@ def cleanup(): for i in range(num_backup_versions, len(backup_list)): os.remove(backup_list[i]) - \ No newline at end of file +