X-Git-Url: https://plomlompom.com/repos/?a=blobdiff_plain;f=plomlib.py;h=2d92977a4b967b891c7052e7250b75a5f42f5de9;hb=HEAD;hp=a94eb54af2646ed1079c5498af0cb0bb0aa59775;hpb=520a7a19656bb44f43b405fcd65fc495fac62748;p=misc diff --git a/plomlib.py b/plomlib.py index a94eb54..2d92977 100644 --- a/plomlib.py +++ b/plomlib.py @@ -33,7 +33,7 @@ class PlomDB: return # collect modification times of numbered .bak files - print('DEBUG BACKUP') + # print('DEBUG BACKUP') bak_prefix = f'{self.db_file}.bak.' # backup_dates = [] mtimes_to_paths = {} @@ -41,44 +41,47 @@ class PlomDB: if path.startswith(os.path.basename(bak_prefix))]: path = os.path.dirname(bak_prefix) + f'/{path}' mod_time = os.path.getmtime(path) - print(f'DEBUG pre-exists: {path} {mod_time}') + # print(f'DEBUG pre-exists: {path} {mod_time}') mtimes_to_paths[str(datetime.fromtimestamp(mod_time))] = path - # backup_dates += [str(datetime.fromtimestamp(mod_time))] - for mtime in sorted(mtimes_to_paths.keys()): - print(f'DEBUG mtimes_to_paths: {mtime}:{mtimes_to_paths[mtime]}') + # for mtime in sorted(mtimes_to_paths.keys()): + # print(f'DEBUG mtimes_to_paths: {mtime}:{mtimes_to_paths[mtime]}') # collect what numbered .bak files to save: the older, the fewer; for each # timedelta, keep the newest file that's older ages_to_keep = [timedelta(minutes=4**i) for i in range(0, 8)] - print(f'DEBUG ages_to_keep: {ages_to_keep}') + # print(f'DEBUG ages_to_keep: {ages_to_keep}') now = datetime.now() to_save = {} for age in ages_to_keep: limit = now - age for mtime in reversed(sorted(mtimes_to_paths.keys())): - print(f'DEBUG checking if {mtime} < {limit} ({now} - {age})') - if datetime.strptime(mtime, '%Y-%m-%d %H:%M:%S.%f') < limit: - print('DEBUG it is, adding!') + # print(f'DEBUG checking if {mtime} < {limit} ({now} - {age})') + if len(mtime) < 20: + mtime_test = mtime + '.000000' + else: + mtime_test = mtime + if datetime.strptime(mtime_test, '%Y-%m-%d %H:%M:%S.%f') < limit: + # print('DEBUG it is, adding!') to_save[mtime] = mtimes_to_paths[mtime] break for path in [path for path in mtimes_to_paths.values() if path not in to_save.values()]: - print(f'DEBUG removing {path} cause not in to_save') + # print(f'DEBUG removing {path} cause not in to_save') os.remove(path) i = 0 for mtime in sorted(to_save.keys()): source = to_save[mtime] target = f'{bak_prefix}{i}' - print(f'DEBUG to_save {source} -> {target}') + # print(f'DEBUG to_save {source} -> {target}') if source != target: shutil.move(source, target) i += 1 # put copy of current state at end of bak list - print(f'DEBUG saving current state to {bak_prefix}{i}') + # print(f'DEBUG saving current state to {bak_prefix}{i}') shutil.copy(self.db_file, f'{bak_prefix}{i}') def write_text_to_db(self, text, mode='w'): @@ -95,7 +98,7 @@ class PlomHandler(BaseHTTPRequestHandler): html_foot = '\n' def fail_400(self, e): - self.send_HTML(f'ERROR: {e}', 400) + self.send_HTML(f'ERROR BAR: {e}', 400) def send_HTML(self, html, code=200): self.send_code_and_headers(code, [('Content-type', 'text/html')])