From 890b2bbe45294bf313c6b6899a2c94a86231668a Mon Sep 17 00:00:00 2001 From: Alexis Christoforides Date: Thu, 7 Jun 2018 13:40:18 -0700 Subject: Allow artifacts to expire --- bockbuild.py | 3 +++ bockbuild/util/util.py | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/bockbuild.py b/bockbuild.py index af913c8..a3b0cfe 100755 --- a/bockbuild.py +++ b/bockbuild.py @@ -207,6 +207,9 @@ class Bockbuild: elif not os.path.exists(package.build_artifact): package.request_build('No artifact') + elif is_expired(package.build_artifact, config.artifact_lifespan_days): + package.request_build('Artifact expired (older than %d days)' % config.artifact_lifespan_days) + elif is_changed(package.buildstring, package.buildstring_file): package.request_build('Updated') diff --git a/bockbuild/util/util.py b/bockbuild/util/util.py index 15a8cef..96233cc 100644 --- a/bockbuild/util/util.py +++ b/bockbuild/util/util.py @@ -11,6 +11,7 @@ import shutil import tarfile import hashlib import stat +from datetime import datetime,timedelta import functools # from @@ -44,6 +45,7 @@ class config: absolute_root = None # there is no file resolution beneath this path. Displayed paths are shortened by omitting this segment. state_root = None exit_code = exit_codes.NOTSET + artifact_lifespan_days = 7 class CommandException (Exception): # shell command failure @@ -298,6 +300,9 @@ def is_changed(new, file, show_diff=True): else: return False +def is_expired (path, age_cutoff_days): + artifact_age_days = (datetime.utcnow() - datetime.utcfromtimestamp(os.path.getmtime(path))).days + return artifact_age_days > age_cutoff_days def get_filetype(path): # the env variables are to work around a issue with OS X and 'file': -- cgit v1.2.3