def add_images_from_csv_to_mock(path):
     """Add images to the mock, reading the csv files saved by the backup
      tool.
     :param path: The directory where the csv files are.
     :return: This method does not return nothing.
     Each file in path has this pattern: backup_<regionname>.csv.
     """
     for file in glob.glob(path + '/*.csv'):
         region_name = os.path.basename(file)[7:-4]
         if region_name not in ServersFacade.images:
             if ServersFacade.use_persistence:
                 ServersFacade.images[region_name] =\
                     shelve.open(ServersFacade.dir_persist + '/_persist_' +
                                 region_name)
             else:
                 ServersFacade.images[region_name] = dict()
         with open(file) as f:
             for row in csv.reader(f):
                 # ignore blank lines
                 if len(row) == 0:
                     continue
                 image = GlanceSyncImage.from_field_list(row)
                 ServersFacade.images[region_name][image.id] = image
         if ServersFacade.use_persistence:
             ServersFacade.images[region_name].sync()
 def add_images_from_csv_to_mock(path):
     """Add images to the mock, reading the csv files saved by the backup
      tool.
     :param path: The directory where the csv files are.
     :return: This method does not return nothing.
     Each file in path has this pattern: backup_<regionname>.csv.
     """
     for file in glob.glob(path + '/*.csv'):
         region_name = os.path.basename(file)[7:-4]
         if region_name not in ServersFacade.images:
             if ServersFacade.use_persistence:
                 ServersFacade.images[region_name] =\
                     shelve.open(ServersFacade.dir_persist + '/_persist_' +
                                 region_name)
             else:
                 ServersFacade.images[region_name] = dict()
         with open(file) as f:
             for row in csv.reader(f):
                 # ignore blank lines
                 if len(row) == 0:
                     continue
                 image = GlanceSyncImage.from_field_list(row)
                 ServersFacade.images[region_name][image.id] = image
         if ServersFacade.use_persistence:
             ServersFacade.images[region_name].sync()
    def add_image_to_mock(image):
        """Add the image to the mock
        :param image: The image to add. If can be a GlanceSyncImage or a list
        :return: This method does not return nothing.
        """
        if type(image) == list:
            image = GlanceSyncImage.from_field_list(image)
        else:
            image = copy.deepcopy(image)

        if image.region not in ServersFacade.images:
            if ServersFacade.use_persistence:
                ServersFacade.images[image.region] =\
                    shelve.open(ServersFacade.dir_persist + '/_persist_' +
                                image.region)
            else:
                ServersFacade.images[image.region] = dict()
        ServersFacade.images[image.region][image.id] = image
        if ServersFacade.use_persistence:
            ServersFacade.images[image.region].sync()
    def add_image_to_mock(image):
        """Add the image to the mock
        :param image: The image to add. If can be a GlanceSyncImage or a list
        :return: This method does not return nothing.
        """
        if type(image) == list:
            image = GlanceSyncImage.from_field_list(image)
        else:
            image = copy.deepcopy(image)

        if image.region not in ServersFacade.images:
            if ServersFacade.use_persistence:
                ServersFacade.images[image.region] =\
                    shelve.open(ServersFacade.dir_persist + '/_persist_' +
                                image.region)
            else:
                ServersFacade.images[image.region] = dict()
        ServersFacade.images[image.region][image.id] = image
        if ServersFacade.use_persistence:
            ServersFacade.images[image.region].sync()