Пример #1
0
    def test_filename_is_unique(self):

        fns = {
            'test-123':
            'test-124',
            'test 0800 great':
            'test 0801 great',
            'test-%s-1' % time.strftime('%Y%m%d'):
            'test-%s-2' % time.strftime('%Y%m%d'),
            'booo':
            'booo-001',
        }

        for fn, new_fn in fns.items():
            ext = '.0.ome.tiff'
            # Create file
            open('./%s%s' % (fn, ext), "w+").close()
            ptn, cnt = guess_pattern(fn)
            new_fullfn = os.path.join('.', new_fn) + ext
            next_fullfn = create_filename('.', ptn, ext, cnt)
            self.assertEqual(next_fullfn, new_fullfn)
            os.remove('./%s%s' % (fn, ext))

        # Check what happens is next proposed file is also already in directory
        open('./test-123.tiff', "w+").close()
        open('./test-124.tiff', "w+").close()

        ptn, cnt = guess_pattern('./test-123')
        new_fullfn = os.path.join('.', 'test-125.tiff')
        self.assertEqual(create_filename('.', ptn, '.tiff', cnt), new_fullfn)

        os.remove('./test-123.tiff')
        os.remove('./test-124.tiff')
Пример #2
0
    def test_guess_pattern(self):
        fn_ptns = {
            'test-123': ('test-{cnt}', '123'),
            '%stest-123' % date: ('{datelng}test-{cnt}', '123'),
            '123-test-%s' % date: ('{cnt}-test-{datelng}', '123'),
            'test-123-%s' % timeshrt: ('test-{cnt}-{timeshrt}', '123'),
            'test-123-%s' % timeshrt_colon:
            ('test-{cnt}-{timeshrt_colon}', '123'),
            '%s%s-acquisition' % (date, timelng):
            ('{datelng}{timelng}-acquisition', '001'),
            'test-0070':
            ('test-{cnt}',
             '0070'),  # test-0000 gives the wrong result at midnight
            '4580-test-%s' % dshrtrev: ('{cnt}-test-{dshrtrev}', '4580'),
            '4580-test:%s' % dshrtrev_hyphen:
            ('{cnt}-test:{dshrtrev_hyphen}', '4580'),
            '%s%s' % (daterev, timelng): ('{daterev}{timelng}', '001'),
            'test2-45': ('test2-{cnt}', '45'),
            'test 1980-08-23': ('test 1980-08-{cnt}',
                                '23'),  # a date, but not *now*
            'test': ('test-{cnt}', '001'),
            'test%s' % timeshrt: ('test{timelng}', '001'),
            '%s-cell5' % current_year: ('{year}-cell{cnt}', '5'),
            '%s-{cell}{cnt}' % current_year: ('{year}-{{cell}}{{cnt}}', '001')
        }

        for fn, ptn in fn_ptns.items():
            for ext in EXTS:
                self.assertEqual(guess_pattern(fn), ptn)
                fullfn = os.path.join(PATH, fn) + ext
                self.assertEqual(guess_pattern(fullfn), ptn)
Пример #3
0
    def test_guess_pattern(self):
        fn_ptns = {
            'test-123': ('test-{cnt}', '123'),
            '%stest-123' % date: ('{datelng}test-{cnt}', '123'),
            '123-test-%s' % date: ('{cnt}-test-{datelng}', '123'),
            # This doesn't work "23-%s" % timelng_hyphen, but it's fine, as it's too much a corner case to be sure it was time
            'test-123 %s--' % timelng_hyphen:
            ('test-{cnt} {timelng_hyphen}--', '123'),
            'test-123-%s' % timeshrt_colon:
            ('test-{cnt}-{timeshrt_colon}', '123'),
            'test-%s-123-' % timelng_colon:
            ('test-{timelng_colon}-{cnt}-', '123'),
            '%s%s-acquisition' % (date, timelng):
            ('{datelng}{timelng}-acquisition', '001'),
            'test-0070': ('test-{cnt}', '0070'),
            '4580-test-%s' % dshrtrev: ('{cnt}-test-{dshrtrev}', '4580'),
            '4580-test:%s' % dshrtrev_hyphen: ('{cnt}-test:{dshrtrev_hyphen}',
                                               '4580'),
            '%s%s' % (daterev, timelng): ('{daterev}{timelng}', '001'),
            'test2-45': ('test2-{cnt}', '45'),
            'test 1980-08-23': ('test 1980-08-{cnt}',
                                '23'),  # a date, but not *now*
            'test': ('test-{cnt}', '001'),
            '%s-cell5' % current_year: ('{year}-cell{cnt}', '5'),
            '%s-{cell}{cnt}' % current_year: ('{year}-{{cell}}{{cnt}}', '001')
        }

        for fn, ptn in fn_ptns.items():
            for ext in EXTS:
                self.assertEqual(guess_pattern(fn), ptn)
                fullfn = os.path.join(PATH, fn) + ext
                self.assertEqual(guess_pattern(fullfn), ptn)
Пример #4
0
    def _on_filename(self, fn):
        """
        Store path and pattern in conf file.
        :param fn: (str) The filename to be stored.
        """
        # Store the directory so that next filename is in the same place
        p, bn = os.path.split(fn)
        if p:
            self.conf.last_path = p

        # Save pattern
        self.conf.fn_ptn, self.conf.fn_count = guess_pattern(fn)
Пример #5
0
    def test_guess_pattern(self):
        fn_ptns = {
                   'test-123': ('test-{cnt}', '123'),
                   '%stest-123' % date: ('{datelng}test-{cnt}', '123'),
                   '123-test-%s' % date: ('{cnt}-test-{datelng}', '123'),
                   'test-123-%s' % timeshrt: ('test-{cnt}-{timeshrt}', '123'),
                   'test-123-%s' % timeshrt_colon: ('test-{cnt}-{timeshrt_colon}', '123'),
                   '%s%s-acquisition' % (date, timelng): ('{datelng}{timelng}-acquisition', '001'),
                   'test-0000': ('test-{cnt}', '0000'),
                   '%s%s' % (daterev, timelng): ('{daterev}{timelng}', '001'),
                   'test2-45': ('test2-{cnt}', '45'),
                   'test': ('test-{cnt}', '001'),
                   'test%s' % timeshrt: ('test{timelng}', '001'),
                   '%s-cell5' % current_year: ('{year}-cell{cnt}', '5'),
                   '%s-{cell}{cnt}' % current_year: ('{year}-{{cell}}{{cnt}}', '001')
                    }

        for fn, ptn in fn_ptns.items():
            for ext in EXTS:
                self.assertEqual(guess_pattern(fn), ptn)
                fullfn = os.path.join(PATH, fn) + ext
                self.assertEqual(guess_pattern(fullfn), ptn)
Пример #6
0
    def _on_filename(self, fn):
        """
        Warn if extension not .png, store path and pattern in conf file
        """
        bn, ext = splitext(fn)
        if not ext.endswith(".png") and not ALLOW_SAVE:
            logging.warning("Only PNG format is recommended to use")

        # Store the directory so that next filename is in the same place
        p, bn = os.path.split(fn)
        if p:
            self.conf.last_path = p

        # Save pattern
        self.conf.fn_ptn, self.conf.fn_count = guess_pattern(fn)
Пример #7
0
 def on_change_file(self, evt):
     """
     Shows a dialog to change the path, name, and format of the acquisition
     file.
     returns nothing, but updates .filename and .conf
     """
     # Update .filename with new filename instead of input name so the right
     # time is used
     fn = create_filename(self.conf.last_path, self.conf.fn_ptn,
                          self.conf.last_extension, self.conf.fn_count)
     new_name = ShowAcquisitionFileDialog(self._tab_panel, fn)
     if new_name is not None:
         self.filename.value = new_name
         self.conf.fn_ptn, self.conf.fn_count = guess_pattern(new_name)
         logging.debug("Generated filename pattern '%s'", self.conf.fn_ptn)
Пример #8
0
 def on_change_file(self, evt):
     """
     Shows a dialog to change the path, name, and format of the acquisition
     file.
     returns nothing, but updates .filename and .conf
     """
     # Update .filename with new filename instead of input name so the right
     # time is used
     fn = create_filename(self.conf.last_path, self.conf.fn_ptn,
                          self.conf.last_extension, self.conf.fn_count)
     new_name = ShowAcquisitionFileDialog(self._tab_panel, fn)
     if new_name is not None:
         self.filename.value = new_name
         self.conf.fn_ptn, self.conf.fn_count = guess_pattern(new_name)
         logging.debug("Generated filename pattern '%s'", self.conf.fn_ptn)
Пример #9
0
    def _on_filename(self, fn):
        """
        Warn if extension not .png, store path and pattern in conf file
        """
        bn, ext = splitext(fn)
        if not ext.endswith(".png") and not ALLOW_SAVE:
            logging.warning("Only PNG format is recommended to use")

        # Store the directory so that next filename is in the same place
        p, bn = os.path.split(fn)
        if p:
            self.conf.last_path = p

        # Save pattern
        self.conf.fn_ptn, self.conf.fn_count = guess_pattern(fn)
Пример #10
0
 def on_change_file(self, evt):
     """
     Shows a dialog to change the path, name, and format of the acquisition
     file.
     returns nothing, but updates .filename and .conf
     """
     fn = create_filename(self.conf.last_path, self.conf.fn_ptn,
                          self.conf.last_extension, self.conf.fn_count)
     new_name = ShowAcquisitionFileDialog(self, fn)
     if new_name is not None:
         self.filename.value = new_name
         self.conf.fn_ptn, self.conf.fn_count = guess_pattern(new_name)
         logging.debug("Generated filename pattern '%s'", self.conf.fn_ptn)
         # It means the user wants to do a new acquisition
         self.btn_secom_acquire.SetLabel("START")
         self.last_saved_file = None
Пример #11
0
 def on_change_file(self, evt):
     """
     Shows a dialog to change the path, name, and format of the acquisition
     file.
     returns nothing, but updates .filename and .conf
     """
     fn = create_filename(self.conf.last_path, self.conf.fn_ptn,
                          self.conf.last_extension, self.conf.fn_count)
     new_name = ShowAcquisitionFileDialog(self, fn)
     if new_name is not None:
         self.filename.value = new_name
         self.conf.fn_ptn, self.conf.fn_count = guess_pattern(new_name)
         logging.debug("Generated filename pattern '%s'", self.conf.fn_ptn)
         # It means the user wants to do a new acquisition
         self.btn_secom_acquire.SetLabel("START")
         self.last_saved_file = None