summaryrefslogtreecommitdiff
path: root/subplot.py
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2020-04-04 10:51:43 +0300
committerLars Wirzenius <liw@liw.fi>2020-04-11 19:43:42 +0300
commite6dd3c17b9ec3a24541a9d2f3ae7182170ac81f9 (patch)
tree19037245493dc3a8afaa4af361e69a4833e1cc26 /subplot.py
parent392ec661bc8db402d1efd2286962e692779c3429 (diff)
downloadsubplot-e6dd3c17b9ec3a24541a9d2f3ae7182170ac81f9.tar.gz
Change: docgen to not change output needlessly
If the output file wouldn't change, then don't update it. This is imperfect, since it still needs to produce the output file, so it can spend a bit of processing power to make no changes. But the alternative would be to make needless changes.
Diffstat (limited to 'subplot.py')
-rw-r--r--subplot.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/subplot.py b/subplot.py
index bc972f8..48320b6 100644
--- a/subplot.py
+++ b/subplot.py
@@ -87,6 +87,32 @@ def stdout_matches(ctx, pattern):
stdout = ctx.get('stdout', '')
return pattern in stdout
+def _get_metadata(filename):
+ st = os.lstat(filename)
+ keys = [
+ 'st_dev',
+ 'st_gid',
+ 'st_ino',
+ 'st_mode',
+ 'st_mtime',
+ 'st_size',
+ 'st_uid',
+ ]
+ return {
+ key: getattr(st, key)
+ for key in keys
+ }
+
+def remember_metadata(ctx, filename=None):
+ ctx['remembered-metadata'] = _get_metadata(filename)
+
+def has_same_metadata_as_remembered(ctx, filename=None):
+ assert_eq(ctx['remembered-metadata'], _get_metadata(filename))
+
+def only_these_files_exist(ctx, filenames=None):
+ filenames = filenames.replace(',', '').split()
+ assert_eq(set(os.listdir('.')), set(filenames))
+
def runcmd(ctx, argv):
p = subprocess.Popen(argv, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = p.communicate("")