Skip to content

Commit a66bdc3

Browse files
committed
updating comparison exampleo
1 parent 1af7fe0 commit a66bdc3

File tree

2 files changed

+58
-16
lines changed

2 files changed

+58
-16
lines changed

examples/reproducibility/assess_replication.py

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
from glob import glob
22

3+
from singularity.reproduce import (
4+
assess_replication,
5+
assess_differences
6+
)
7+
38
image_files=glob('*.img')
4-
from singularity.reproduce import *
5-
Environment message level found to be DEBUG
9+
10+
# ASSESS REPLICATION #######################################
11+
# returns booleans for if the hashes for levels are the same
612

713
assess_replication(image_files[0],image_files[1])
814

@@ -23,3 +29,32 @@
2329
'RECIPE': True,
2430
'REPLICATE': True,
2531
'RUNSCRIPT': True}
32+
33+
# ASSESS DIFFERENCES #######################################
34+
# returns dictionary with
35+
36+
report = assess_differences(image_files[0],image_files[1])
37+
38+
report.keys()
39+
# dict_keys(['different', 'missing', 'same'])
40+
41+
# These files are equivalent between the images
42+
print(len(report['same']))
43+
5663
44+
45+
# These files are present in both, but different
46+
print(report['different'])
47+
['./etc/hosts',
48+
'./.exec',
49+
'./environment',
50+
'./etc/mtab',
51+
'./etc/resolv.conf',
52+
'./.run',
53+
'./.shell',
54+
'./singularity']
55+
56+
# These files are found in the first image, but not the second
57+
print(report['missing'])
58+
['./var/lib/apt/lists/.wh.archive.ubuntu.com_ubuntu_dists_xenial-updates_main_i18n_Translation-en',
59+
'./bin/gunzip']
60+

singularity/reproduce.py

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,31 +37,38 @@ def assess_replication(image_file1,image_file2,version=None):
3737
return report
3838

3939

40-
def assess_differences(image_file1,image_file2,version=None):
40+
def assess_differences(image_file1,image_file2,level=None,version=None):
4141
'''assess_replications will compare two images on each level of
4242
reproducibility,
4343
'''
4444
levels = get_levels(version=version)
45+
if level is None:
46+
level = "IDENTICAL"
47+
48+
if level not in list(levels.keys()):
49+
bot.logger.error("%s is not a valid level. See get_levels().",level)
50+
sys.exit(1)
51+
4552
different = []
4653
same = []
4754
setdiff = []
48-
for level_name, values in levels.items():
49-
hashes1 = get_content_hashes(image_path=image_file1,
50-
level=level_name)
51-
hashes2 = get_content_hashes(image_path=image_file2,
52-
level=level_name)
53-
for file_name,hash_value in hashes1.items():
54-
if file_name in hashes2:
55-
if hashes2[file_name] == hashes1[file_name]:
56-
same.append(file_name)
57-
else:
58-
different.append(file_name)
55+
56+
# Compare the dictionary of file:hash between two images
57+
hashes1 = get_content_hashes(image_path=image_file1,level=level)
58+
hashes2 = get_content_hashes(image_path=image_file2,level=level)
59+
for file_name,hash_value in hashes1.items():
60+
if file_name in hashes2:
61+
if hashes2[file_name] == hashes1[file_name]:
62+
same.append(file_name)
5963
else:
60-
setdiff.append(file_name)
64+
different.append(file_name)
65+
else:
66+
setdiff.append(file_name)
6167

6268
report = {'missing':setdiff,
6369
'same':same,
6470
'different':different}
71+
6572
return report
6673

6774

@@ -214,7 +221,7 @@ def get_content_hashes(image_path,level=None,regexp=None,include_files=None,skip
214221
digest = dict()
215222
for member in tar:
216223
if member.isfile():
217-
if include_file(member.name,file_filters):
224+
if include_file(member.name,file_filter):
218225
buf = member.tobuf()
219226
hasher = hashlib.sha1()
220227
hasher.update(buf)

0 commit comments

Comments
 (0)