From c66a8d90b916872d5670d2b845de7e7b3d1aca7b Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Thu, 28 Jun 2018 02:50:16 +0200 Subject: Don't recalculate time Only ever get the time once. Otherwise, we could imagine an unlikely situation where the new file would get created at 59 seconds and the family name would be updated at 00 seconds, causing the two timestamps to differ by a minute. Now the two timestamps will always be the same. --- typarichive.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/typarichive.py b/typarichive.py index 7a48701..80d5cbf 100644 --- a/typarichive.py +++ b/typarichive.py @@ -26,21 +26,21 @@ import re import shutil -def new_font_name(filename): - time_string = datetime.now().strftime('%Y%m%d%H%M') - +def new_font_name(filename, time_string): return re.sub(r'\d{12}', time_string, filename) font = Glyphs.font filepath = font.filepath +time_string = datetime.now().strftime('%Y%m%d%H%M') font_directory = path.dirname(filepath) archive_directory = path.join(font_directory, '_archive') new_font_path = path.join( font_directory, new_font_name( - path.basename(filepath))) + path.basename(filepath), + time_string)) shutil.copy2(filepath, new_font_path) @@ -49,4 +49,6 @@ shutil.move(filepath, archive_directory) font.close() Glyphs.open(new_font_path) -Glyphs.font.familyName = new_font_name(Glyphs.font.familyName) +Glyphs.font.familyName = new_font_name( + Glyphs.font.familyName, + time_string) -- cgit v1.2.3