Ejemplo n.º 1
0
def setup_module():
    # Initialize test image paths/elements/associated crop boxes.
    global GH_IMAGE_FP, GH_FILE_ELEMENT, GH_CROPPED_IMAGE_FP, \
        GH_CROPPED_FILE_ELEMENT, GH_CROPPED_BBOX

    GH_IMAGE_FP = os.path.join(TEST_DATA_DIR, "grace_hopper.png")
    GH_FILE_ELEMENT = DataFileElement(GH_IMAGE_FP, readonly=True)
    assert GH_FILE_ELEMENT.content_type() == 'image/png'

    GH_CROPPED_IMAGE_FP = \
        os.path.join(TEST_DATA_DIR, 'grace_hopper.100x100+100+100.png')
    GH_CROPPED_FILE_ELEMENT = DataFileElement(GH_CROPPED_IMAGE_FP,
                                              readonly=True)
    assert GH_CROPPED_FILE_ELEMENT.content_type() == 'image/png'
    GH_CROPPED_BBOX = AxisAlignedBoundingBox([100, 100], [200, 200])
Ejemplo n.º 2
0
 def iter_valid_elements():
     for fp in file_paths:
         dfe = DataFileElement(fp)
         ct = dfe.content_type()
         if ct in generator.valid_content_types():
             valid_file_paths[fp] = ct
             yield dfe
         else:
             invalid_file_paths[fp] = ct
Ejemplo n.º 3
0
 def iter_valid_elements():
     for fp in file_paths:
         dfe = DataFileElement(fp)
         ct = dfe.content_type()
         if ct in generator.valid_content_types():
             valid_file_paths[fp] = ct
             yield dfe
         else:
             invalid_file_paths[fp] = ct
Ejemplo n.º 4
0
 def is_valid_element(fp):
     dfe = DataFileElement(fp)
     ct = dfe.content_type()
     if ct in generator.valid_content_types():
         if not check_image or test_image_load(dfe):
             return dfe
         else:
             return None
     else:
         log.debug(
             "Skipping file (invalid content) type for "
             "descriptor generator (fp='%s', ct=%s)", str(fp), ct)
         return None
Ejemplo n.º 5
0
 def is_valid_element(fp):
     dfe = DataFileElement(fp)
     ct = dfe.content_type()
     if ct in generator.valid_content_types():
         if not check_image or test_image_load(dfe):
             return dfe
         else:
             return None
     else:
         log.debug("Skipping file (invalid content) type for "
                   "descriptor generator (fp='%s', ct=%s)",
                   fp, ct)
         return None
Ejemplo n.º 6
0
        def iqr_ingest_file():
            """
            Ingest the file with the given UID, getting the path from the
            uploader.

            :return: string of data/descriptor element's UUID
            :rtype: str

            """
            # TODO: Add status dict with a "GET" method branch for getting that
            #       status information.

            fid = flask.request.form['fid']

            sid = self.get_current_iqr_session()

            self._log.debug(
                "[%s::%s] Getting temporary filepath from "
                "uploader module", sid, fid)
            upload_filepath = self.mod_upload.get_path_for_id(fid)
            self.mod_upload.clear_completed(fid)

            self._log.debug("[%s::%s] Moving uploaded file", sid, fid)
            sess_upload = osp.join(self._iqr_work_dirs[sid],
                                   osp.basename(upload_filepath))
            os.rename(upload_filepath, sess_upload)

            # Record uploaded data as user example data for this session.
            upload_data = DataFileElement(sess_upload)
            uuid = upload_data.uuid()
            self._iqr_example_data[sid][uuid] = upload_data

            # Extend session ingest -- modifying
            self._log.debug(
                "[%s::%s] Adding new data to session "
                "external positives", sid, fid)
            data_b64 = base64.b64encode(upload_data.get_bytes())
            data_ct = upload_data.content_type()
            r = self._iqr_service.post('add_external_pos',
                                       sid=sid,
                                       base64=data_b64,
                                       content_type=data_ct)
            r.raise_for_status()

            return str(uuid)
Ejemplo n.º 7
0
        def iqr_ingest_file():
            """
            Ingest the file with the given UID, getting the path from the
            uploader.

            :return: string of data/descriptor element's UUID
            :rtype: str

            """
            # TODO: Add status dict with a "GET" method branch for getting that
            #       status information.

            fid = flask.request.form['fid']

            sid = self.get_current_iqr_session()

            self._log.debug("[%s::%s] Getting temporary filepath from "
                            "uploader module", sid, fid)
            upload_filepath = self.mod_upload.get_path_for_id(fid)
            self.mod_upload.clear_completed(fid)

            self._log.debug("[%s::%s] Moving uploaded file",
                            sid, fid)
            sess_upload = osp.join(self._iqr_work_dirs[sid],
                                   osp.basename(upload_filepath))
            os.rename(upload_filepath, sess_upload)

            # Record uploaded data as user example data for this session.
            upload_data = DataFileElement(sess_upload)
            uuid = upload_data.uuid()
            self._iqr_example_data[sid][uuid] = upload_data

            # Extend session ingest -- modifying
            self._log.debug("[%s::%s] Adding new data to session "
                            "external positives", sid, fid)
            data_b64 = base64.b64encode(upload_data.get_bytes())
            data_ct = upload_data.content_type()
            r = self._iqr_service.post('add_external_pos', sid=sid,
                                       base64=data_b64, content_type=data_ct)
            r.raise_for_status()

            return str(uuid)
Ejemplo n.º 8
0
 def test_content_type_explicit_type(self):
     ex_type = 'image/png'
     d = DataFileElement('foo.txt', explicit_mimetype=ex_type)
     self.assertEqual(d.content_type(), ex_type)
Ejemplo n.º 9
0
 def test_content_type(self):
     d = DataFileElement('foo.txt')
     self.assertEqual(d.content_type(), 'text/plain')
Ejemplo n.º 10
0
 def test_content_type_explicit_type(self):
     ex_type = 'image/png'
     d = DataFileElement('foo.txt', explicit_mimetype=ex_type)
     self.assertEqual(d.content_type(), ex_type)
Ejemplo n.º 11
0
 def test_content_type(self):
     d = DataFileElement('foo.txt')
     self.assertEqual(d.content_type(), 'text/plain')
Ejemplo n.º 12
0
 def test_content_type(self):
     d = DataFileElement("foo.txt")
     ntools.assert_equal(d.content_type(), "text/plain")