@@ -68,18 +68,21 @@ def compare_containers(container1,container2,by=None):
6868
6969
7070
71- def calculate_similarity (container1 ,container2 ,by = "files.txt" ):
71+ def calculate_similarity (container1 ,container2 ,by = "files.txt" , comparison = None ):
7272 '''calculate_similarity will calculate similarity of two containers by files content, default will calculate
7373 2.0*len(intersect) / total package1 + total package2
7474 :param container1: container 1
7575 :param container2: container 2
7676 :param by: the one or more metrics (eg files.txt) list to use to compare
7777 valid are currently files.txt or folders.txt
78+ :param comparison: the comparison result object for the tree. If provided,
79+ will skip over function to obtain it.
7880 '''
7981 if not isinstance (by ,list ):
8082 by = [by ]
8183
82- comparison = compare_containers (container1 ,container2 ,by = by )
84+ if comparison == None :
85+ comparison = compare_containers (container1 ,container2 ,by = by )
8386 scores = dict ()
8487
8588 for b in by :
@@ -145,15 +148,18 @@ def get_container_contents(container,gets=None,split_delim=None):
145148###################################################################################
146149
147150
148- def container_difference (container ,container_subtract ):
151+ def container_difference (container ,container_subtract , comparison = None ):
149152 '''container_difference will return a data structure to render an html
150153 tree (graph) of the differences between two images or packages. The second
151154 container is subtracted from the first
152155 :param container: the primary container object (to subtract from)
153156 :param container_subtract: the second container object to remove
157+ :param comparison: the comparison result object for the tree. If provided,
158+ will skip over function to obtain it.
154159 '''
155- comparison = compare_containers (container ,container_subtract ,
156- by = ['files.txt' ,'folders.txt' ])
160+ if comparison == None :
161+ comparison = compare_containers (container ,container_subtract ,
162+ by = ['files.txt' ,'folders.txt' ])
157163 files = comparison ["files.txt" ]['unique1' ]
158164 folders = comparison ['folders.txt' ]['unique1' ]
159165 tree = make_container_tree (folders = folders ,
@@ -162,14 +168,17 @@ def container_difference(container,container_subtract):
162168
163169
164170
165- def container_similarity (container1 ,container2 ):
171+ def container_similarity (container1 ,container2 , comparison = None ):
166172 '''container_sim will return a data structure to render an html tree
167173 (graph) of the intersection (commonalities) between two images or packages
168174 :param container1: the first container object
169175 :param container2: the second container object
176+ :param comparison: the comparison result object for the tree. If provided,
177+ will skip over function to obtain it.
170178 '''
171- comparison = compare_containers (container1 ,container2 ,
172- by = ['files.txt' ,'folders.txt' ])
179+ if comparison == None :
180+ comparison = compare_containers (container1 ,container2 ,
181+ by = ['files.txt' ,'folders.txt' ])
173182 files = comparison ["files.txt" ]['intersect' ]
174183 folders = comparison ['folders.txt' ]['intersect' ]
175184 tree = make_container_tree (folders = folders ,
0 commit comments