How to use the fabio.fabioutils.FilenameObject function in fabio

To help you get started, we’ve selected a few fabio examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github silx-kit / fabio / fabio / fabioutils.py View on Github external
def extract_filenumber(name):
    """ extract file number """
    fobj = FilenameObject(filename=name)
    return fobj.num
github silx-kit / fabio / fabio / app / convert.py View on Github external
# the upper case IMAGE is used for the --help auto-documentation
        args.images = expand_args(args.IMAGE)
        args.images.sort()

        if args.format is None or not args.format.endswith("image"):

            if args.format is None:
                if args.output is None:
                    raise argparse.ArgumentError(None, "No format specified. Use -F or -o.")
                dummy_filename = args.output
            else:
                # format looks to be an extension
                dummy_filename = "foo." + args.format

            # extract file format from file name
            filename = fabio.fabioutils.FilenameObject(filename=dummy_filename)

            if filename.format is None or len(filename.format) == 0:
                raise argparse.ArgumentError(None, "This file extension is unknown. You have also to specify a format using -F.")
            elif filename.format is None or len(filename.format) > 1:
                formats = [i + "image" for i in filename.format]
                formats = ', '.join(formats)
                raise argparse.ArgumentError(None, "This file extension correspond to different file formats: '%s'. You have to specify it using -F." % formats)
            args.format = filename.format[0] + "image"

        if not is_format_supported(args.format):
            raise argparse.ArgumentError(None, "Format '%s' is unknown. Use -l to list all available formats." % args.format)
    except argparse.ArgumentError as e:
        logger.error(e.message)
        logger.debug("Backtrace", exc_info=True)
        return EXIT_ARGUMENT_FAILURE
github silx-kit / fabio / fabio / openimage.py View on Github external
imo = FabioImage()
        with imo._open(actual_filename) as f:
            magic_bytes = f.read(18)
    except IOError:
        logger.debug("Backtrace", exc_info=True)
        raise
    else:
        imo = None

    filetype = None
    try:
        filetype = do_magic(magic_bytes, filename)
    except Exception:
        logger.debug("Backtrace", exc_info=True)
        try:
            file_obj = FilenameObject(filename=filename)
            if file_obj is None:
                raise Exception("Unable to deconstruct filename")
            if (file_obj.format is not None) and\
               len(file_obj.format) != 1 and \
               isinstance(file_obj.format, list):
                # one of OXD/ADSC - should have got in previous
                raise Exception("openimage failed on magic bytes & name guess")
            filetype = file_obj.format

        except Exception:
            logger.debug("Backtrace", exc_info=True)
            raise IOError("Fabio could not identify " + filename)

    if filetype is None:
        raise IOError("Fabio could not identify " + filename)
github silx-kit / fabio / fabio / fabioutils.py View on Github external
def next_filename(name, padding=True):
    """ increment number """
    fobj = FilenameObject(filename=name)
    fobj.num += 1
    if not padding:
        fobj.digits = 0
    return fobj.tostring()
github silx-kit / fabio / fabio / file_series.py View on Github external
def __init__(self, filename):
        """ create from a filename (String)"""
        if isinstance(filename, FilenameObject):
            self.obj = filename
        else:
            self.obj = FilenameObject(filename=filename)
github silx-kit / fabio / fabio / file_series.py View on Github external
def last_object(self):
        """
        Last image in a sequence

        :return: file_object

        """
        return FilenameObject(self.last())
github silx-kit / fabio / fabio / file_series.py View on Github external
def next_object(self):
        """
        Return the next image

        :return: file_object

        """
        return FilenameObject(self.next())