def create_and_use(self, boxes, path):
     """Creates a new CookieCutter file that contains boxes, writes in to
     path and sets it to be the current choice
     """
     debug_print('CookieCutterChoice.create_and_use to [{0}]'.format(path))
     cookie_cutter = CookieCutter('', boxes)
     cookie_cutter.save(path)
     self.load(path)
示例#2
0
def ingest_from_directory(inbox, docs,
                          thumbnail_width_pixels=InselectDocument.THUMBNAIL_DEFAULT_WIDTH,
                          cookie_cutter=None):
    """Ingest images from the directory given by inbox to the directory given
    by docs
    """
    inbox, docs = Path(inbox), Path(docs)
    cookie_cutter = Path(cookie_cutter) if cookie_cutter else None
    if not inbox.is_dir():
        raise InselectError('Inbox directory [{0}] does not exist'.format(inbox))

    if not docs.is_dir():
        print('Create document directory [{0}]'.format(docs))
        docs.mkdir(parents=True)

    if cookie_cutter:
        cookie_cutter = CookieCutter.load(cookie_cutter)

    for source in (p for p in inbox.iterdir() if IMAGE_SUFFIXES_RE.match(p.name)):
        print('Ingesting [{0}]'.format(source))
        try:
            ingest_image(
                source, docs,
                thumbnail_width_pixels=thumbnail_width_pixels,
                cookie_cutter=cookie_cutter
            )
        except KeyboardInterrupt:
            raise
        except Exception:
            print('Error ingesting [{0}]'.format(source))
            traceback.print_exc()
        else:
            print('Ingested [{0}]'.format(source))
示例#3
0
    def test_save_to_cookie_cutter(self, mock_setvalue):
        "Create a new cookie cutter"
        w = self.window
        w.open_document(TESTDATA / 'test_segment.inselect')

        with temp_directory_with_files() as tempdir:
            path = tempdir / 'My new cookie cutter{0}'.format(
                CookieCutter.EXTENSION
            )
            retval = str(path), w.cookie_cutter_widget.FILE_FILTER
            with patch.object(QFileDialog, 'getSaveFileName', return_value=retval):
                w.save_to_cookie_cutter()

            cookie_cutter = CookieCutter.load(path)

        # The new cookie cutter should have been created with 5 boxes
        self.assertEqual(5, len(cookie_cutter.document_items))
        self.assertEqual(
            'My new cookie cutter (5 boxes)',
            cookie_cutter_choice().current.name
        )
    def test_save_to_cookie_cutter(self, mock_setvalue):
        "Create a new cookie cutter"
        w = self.window
        w.open_document(path=TESTDATA / 'shapes.inselect')

        with temp_directory_with_files() as tempdir:
            path = tempdir / 'My new cookie cutter{0}'.format(
                CookieCutter.EXTENSION
            )

            retval = str(path), w.cookie_cutter_widget.FILE_FILTER
            with patch.object(QFileDialog, 'getSaveFileName', return_value=retval):
                w.save_to_cookie_cutter()

            cookie_cutter = CookieCutter.load(path)

        # The new cookie cutter should have been created with 5 boxes
        self.assertEqual(5, len(cookie_cutter.document_items))
        self.assertEqual(
            'My new cookie cutter (5 boxes)',
            cookie_cutter_choice().current.name
        )
示例#5
0
def ingest_from_directory(
        inbox,
        docs,
        thumbnail_width_pixels=InselectDocument.THUMBNAIL_DEFAULT_WIDTH,
        cookie_cutter=None):
    """Ingest images from the directory given by inbox to the directory given
    by docs
    """
    inbox, docs = Path(inbox), Path(docs)
    cookie_cutter = Path(cookie_cutter) if cookie_cutter else None
    if not inbox.is_dir():
        raise InselectError(
            'Inbox directory [{0}] does not exist'.format(inbox))

    if not docs.is_dir():
        print('Create document directory [{0}]'.format(docs))
        docs.mkdir(parents=True)

    if cookie_cutter:
        cookie_cutter = CookieCutter.load(cookie_cutter)

    for source in (p for p in inbox.iterdir()
                   if IMAGE_SUFFIXES_RE.match(p.name)):
        print('Ingesting [{0}]'.format(source))
        try:
            ingest_image(source,
                         docs,
                         thumbnail_width_pixels=thumbnail_width_pixels,
                         cookie_cutter=cookie_cutter)
        except KeyboardInterrupt:
            raise
        except Exception:
            print('Error ingesting [{0}]'.format(source))
            traceback.print_exc()
        else:
            print('Ingested [{0}]'.format(source))
 def _load(self, path):
     "Loads the CookieCutter in path"
     debug_print('CookieCutterChoice._load [{0}]'.format(path))
     return CookieCutter.load(path)