commit e7663fb358dea488958e0dccbef265817bcc15ab
Author: Radek Pazdera <rpazdera(a)redhat.com>
Date: Thu Nov 8 16:17:45 2012 +0100
Utils: Adding has_changed_since
This predicate will examine a file or a directory subtree and
evaluate False in case any file has been modified after the
threshold time.
Signed-off-by: Radek Pazdera <rpazdera(a)redhat.com>
Common/Utils.py | 19 +++++++++++++++++++
1 files changed, 19 insertions(+), 0 deletions(-)
---
diff --git a/Common/Utils.py b/Common/Utils.py
index 0170920..3109a31 100644
--- a/Common/Utils.py
+++ b/Common/Utils.py
@@ -129,3 +129,22 @@ def dir_md5sum(dir_path):
os.unlink(tar_filepath)
return md5_digest
+
+def has_changed_since(filepath, threshold):
+ if os.path.isfile(filepath):
+ return _is_newer_than(filepath, threshold)
+
+ for root, dirs, files in os.walk(directory):
+ for f in files:
+ if _is_newer_than(f, threshold):
+ return False
+
+ for d in dirs:
+ if _is_newer_than(d, threshold):
+ return False
+
+ return True
+
+def _is_newer_than(f, threshold):
+ stat = os.stat(f)
+ return stat.st_mtime > threshold
Show replies by date