Esempio n. 1
0
 def create_figure(operation_id, user_id, project_id, session_name=None, 
                   name=None, path=None, file_format='PNG'):
     """
     :returns: the `model.ResultFigure` for a result with the given specifications
     """
     figure = model.ResultFigure(operation_id, user_id, project_id, 
                                 session_name, name, path, file_format)
     return dao.store_entity(figure)
Esempio n. 2
0
 def create_figure(operation_id,
                   user_id,
                   project_id,
                   session_name=None,
                   name=None,
                   path=None,
                   file_format=None):
     figure = model.ResultFigure(operation_id, user_id, project_id,
                                 session_name, name, path, file_format)
     return dao.store_entity(figure)
Esempio n. 3
0
    def store_result_figure(self,
                            project,
                            user,
                            img_type,
                            export_data,
                            image_name=None,
                            operation_id=None):
        """
        Store into a file, Result Image and reference in DB.
        """
        store_path, file_name = self._image_path(project.name, img_type)

        if img_type == FigureService._TYPE_PNG:  # PNG file from canvas
            self._write_png(store_path, export_data)
        elif img_type == FigureService._TYPE_SVG:  # SVG file from svg viewer
            self._write_svg(store_path, export_data)

        if operation_id:
            operation = dao.get_operation_by_id(operation_id)
        else:
            operation = None
            operation_id = None

        image_name = self._generate_image_name(project, user, operation,
                                               image_name)

        # Store entity into DB
        entity = model.ResultFigure(operation_id, user.id, project.id,
                                    FigureService._DEFAULT_SESSION_NAME,
                                    image_name, file_name, img_type)
        entity = dao.store_entity(entity)

        # Load instance from DB to have lazy fields loaded
        figure = dao.load_figure(entity.id)
        # Write image meta data to disk
        self.file_helper.write_image_metadata(figure)

        if operation:
            # Force writing operation meta data on disk.
            # This is important later for operation import
            self.file_helper.write_operation_metadata(operation)
Esempio n. 4
0
    def store_result_figure(self, project, user, img_type, operation_id, export_data):
        """
        Store into a file, Result Image and reference in DB.
        """
        session_name = "Default"
        file_name = "snapshot." + img_type

        # Generate path where to store image
        store_path = self.file_helper.get_images_folder(project.name, operation_id)
        store_path = utils.get_unique_file_name(store_path, file_name)[0]
        file_name = os.path.split(store_path)[1]

        if img_type == "jpg":  # JPG file from canvas
            # Store image
            img_data = base64.b64decode(export_data)
            dest = open(store_path, 'wb')
            dest.write(img_data)
            dest.close()
        elif img_type == 'svg':  # SVG file from svg viewer
            # Generate path where to store image
            dest = open(store_path, 'w')
            dest.write(export_data)
            dest.close()

        # Store entity into DB
        entity = model.ResultFigure(operation_id, user.id, project.id, session_name,
                                    "Snapshot-" + operation_id, file_name)
        entity = dao.store_entity(entity)

        # Load instance from DB to have lazy fields loaded
        figure = dao.load_figure(entity.id)
        # Write image meta data to disk  
        self.file_helper.write_image_metadata(figure)

        # Force writing operation meta data on disk. 
        # This is important later for operation import
        operation = dao.get_operation_by_id(operation_id)
        self.file_helper.write_operation_metadata(operation)