Пример #1
0
def container_difference(container=None,
                         container_subtract=None,
                         image_package=None,
                         image_package_subtract=None,
                         comparison=None):
    '''container_difference will return a data structure to render an html 
    tree (graph) of the differences between two images or packages. The second
    container is subtracted from the first
    :param container: the primary container object (to subtract from)
    :param container_subtract: the second container object to remove
    :param image_package: a zipped package for image 1, created with package
    :param image_package_subtract: a zipped package for subtraction image, created with package
    :param comparison: the comparison result object for the tree. If provided,
    will skip over function to obtain it.
    '''
    if comparison == None:
        comparison = compare_containers(container1=container,
                                        container2=container_subtract,
                                        image_package1=image_package,
                                        image_package2=image_package_subtract,
                                        by=['files.txt', 'folders.txt'])

    files = comparison["files.txt"]['unique1']
    folders = comparison['folders.txt']['unique1']
    tree = make_container_tree(folders=folders, files=files)
    return tree
    def test_container_similarity(self):
        print(
            "Testing singularity.analysis.compare.container_similarity_vector")
        import pandas
        from singularity.analysis.compare import container_similarity_vector
        from singularity.package import get_packages
        packages_set = get_packages('docker-os')[0:2]
        vector = container_similarity_vector(container1=self.container,
                                             custom_set=packages_set)
        self.assertTrue('files.txt' in vector)
        self.assertTrue(isinstance(vector['files.txt'], pandas.DataFrame))

        print(
            "Testing singularity.analysis.compare.compare_singularity_images")
        from singularity.analysis.compare import compare_singularity_images
        sim = compare_singularity_images(self.container, self.comparator)
        self.assertTrue(isinstance(sim, pandas.DataFrame))
        self.assertTrue(sim.loc[self.container, self.comparator] -
                        0.4803262269280298 < 0.01)

        print("Testitng singularity.analysis.compare.compare_containers")
        from singularity.analysis.compare import compare_containers
        comparison = compare_containers(self.container, self.comparator)
        self.assertTrue('files.txt' in comparison)
        for key in ['total1', 'total2', 'intersect', 'unique2', 'unique1']:
            self.assertTrue(key in comparison['files.txt'])

        print("Testing singularity.analysis.compare.calculate_similarity")
        from singularity.analysis.compare import calculate_similarity
        sim = calculate_similarity(self.container, self.comparator)
        self.assertTrue(sim['files.txt'] - 0.4921837537163134 < 0.01)
 def test_compare_containers(self):
     print("Testitng singularity.analysis.compare.compare_containers")
     from singularity.analysis.compare import compare_containers
     comparison = compare_containers(self.container,self.comparator)
     self.assertTrue('files.txt' in comparison)
     for key in ['total1', 'total2', 'intersect', 'unique2', 'unique1']:
         self.assertTrue(key in comparison['files.txt'])
    def test_container_similarity(self):

        print("Testing singularity.analysis.compare.compare_singularity_images")
        from singularity.analysis.compare import compare_singularity_images
        sim = compare_singularity_images(self.container,self.comparator)
        self.assertTrue(isinstance(sim,pandas.DataFrame))
        self.assertTrue(sim.loc[self.container,self.comparator] - 0.4803262269280298 < 0.01)

        print("Testitng singularity.analysis.compare.compare_containers")
        from singularity.analysis.compare import compare_containers
        comparison = compare_containers(self.container, self.comparator)
        for key in ['total1', 'total2', 'intersect', 'unique2', 'unique1']:
            self.assertTrue(key in comparison)
     
        print("Testing singularity.analysis.compare.calculate_similarity")
        from singularity.analysis.compare import calculate_similarity
        sim = calculate_similarity(self.container,self.comparator)
        self.assertTrue(sim - 0.474603405617814 < 0.01)
Пример #5
0
def get_diff(container=None, image_package=None):
    '''get diff will return a dictionary of folder paths and files that
    are in an image or package vs. all standard operating systems. The
    algorithm is explained below. 
    :param container: if provided, will use container as image. Can also provide
    :param image_package: if provided, can be used instead of container

    ::notes
  
    The algorithm works as follows:
      1) first compare package to set of base OS (provided with shub)
      2) subtract the most similar os from image, leaving "custom" files
      3) organize custom files into dict based on folder name

    '''

    # Find the most similar os
    most_similar = estimate_os(image_package=image_package,
                               container=container)
    similar_package = "%s/docker-os/%s.img.zip" % (get_package_base(),
                                                   most_similar)

    comparison = compare_containers(image_package1=image_package,
                                    container1=container,
                                    image_package2=similar_package,
                                    by='files.txt')['files.txt']

    container_unique = comparison['unique1']

    # Try to organize files based on common folders:
    folders = dict()
    for file_path in container_unique:
        fileparts = file_path.split('/')
        if len(fileparts) >= 2:
            folder = fileparts[-2]
        else:
            folder = '/'
        filey = fileparts[-1]
        if folder in folders:
            folders[folder].append(filey)
        else:
            folders[folder] = [filey]

    return folders
Пример #6
0
def container_similarity(container1=None,container2=None,image_package1=None,
                         image_package2=None,comparison=None):
    '''container_sim will return a data structure to render an html tree 
    (graph) of the intersection (commonalities) between two images or packages
    :param container1: the first container object
    :param container2: the second container object if either not defined, need
    :param image_package1: a packaged container1 (produced by package)
    :param image_package2: a packaged container2 (produced by package)
    :param comparison: the comparison result object for the tree. If provided,
    will skip over function to obtain it.
    '''
    if comparison == None:
        comparison = compare_containers(container1=container1,
                                        container2=container2,
                                        image_package1=image_package1,
                                        image_package2=image_package2,
                                        by=['files.txt','folders.txt'])
    files = comparison["files.txt"]['intersect']
    folders = comparison['folders.txt']['intersect']
    tree = make_container_tree(folders=folders,
                               files=files)
    return tree