def tags_handler(ctx, param, value):
    """Get tags from a template file or command line."""
    retval = options.from_like_context(ctx, param, value)
    if retval is None and value:
        try:
            retval = dict(p.split('=') for p in value)
        except:
            raise click.BadParameter(
                "'%s' contains a malformed tag." % value,
                param=param, param_hint='transform')
    return retval
def transform_handler(ctx, param, value):
    """Get transform value from a template file or command line."""
    retval = options.from_like_context(ctx, param, value)
    if retval is None and value:
        try:
            value = json.loads(value)
        except ValueError:
            pass
        try:
            retval = guard_transform(value)
        except:
            raise click.BadParameter(
                "'%s' is not recognized as an Affine array." % value,
                param=param, param_hint='transform')
    return retval
Exemple #3
0
def crs_handler(ctx, param, value):
    """Get crs value from a template file or command line."""
    retval = options.from_like_context(ctx, param, value)
    if retval is None and value:
        try:
            retval = json.loads(value)
        except ValueError:
            retval = value
        try:
            if isinstance(retval, dict):
                retval = CRS(retval)
            else:
                retval = CRS.from_string(retval)
        except CRSError:
            raise click.BadParameter(
                "'%s' is not a recognized CRS." % retval,
                param=param, param_hint='crs')
    return retval
def crs_handler(ctx, param, value):
    """Get crs value from a template file or command line."""
    retval = options.from_like_context(ctx, param, value)
    if retval is None and value:
        try:
            retval = json.loads(value)
        except ValueError:
            retval = value
        try:
            if isinstance(retval, dict):
                retval = CRS(retval)
            else:
                retval = CRS.from_string(retval)
        except CRSError:
            raise click.BadParameter(
                "'%s' is not a recognized CRS." % retval,
                param=param, param_hint='crs')
    return retval
Exemple #5
0
def colorinterp_handler(ctx, param, value):
    """Validate a string like ``red,green,blue,alpha`` and convert to
    a tuple.  Also handle ``RGB`` and ``RGBA``.
    """

    if value is None:
        return value
    # Using '--like'
    elif value.lower() == 'like':
        return options.from_like_context(ctx, param, value)
    elif value.lower() == 'rgb':
        return ColorInterp.red, ColorInterp.green, ColorInterp.blue
    elif value.lower() == 'rgba':
        return ColorInterp.red, ColorInterp.green, ColorInterp.blue, ColorInterp.alpha
    else:
        colorinterp = tuple(value.split(','))
        for ci in colorinterp:
            if ci not in ColorInterp.__members__:
                raise click.BadParameter(
                    "color interpretation '{ci}' is invalid.  Must be one of: "
                    "{valid}".format(ci=ci,
                                     valid=', '.join(ColorInterp.__members__)))
        return tuple(ColorInterp[ci] for ci in colorinterp)
Exemple #6
0
def colorinterp_handler(ctx, param, value):

    """Validate a string like ``red,green,blue,alpha`` and convert to
    a tuple.  Also handle ``RGB`` and ``RGBA``.
    """

    if value is None:
        return value
    # Using '--like'
    elif value.lower() == 'like':
        return options.from_like_context(ctx, param, value)
    elif value.lower() == 'rgb':
        return ColorInterp.red, ColorInterp.green, ColorInterp.blue
    elif value.lower() == 'rgba':
        return ColorInterp.red, ColorInterp.green, ColorInterp.blue, ColorInterp.alpha
    else:
        colorinterp = tuple(value.split(','))
        for ci in colorinterp:
            if ci not in ColorInterp.__members__:
                raise click.BadParameter(
                    "color interpretation '{ci}' is invalid.  Must be one of: "
                    "{valid}".format(
                        ci=ci, valid=', '.join(ColorInterp.__members__)))
        return tuple(ColorInterp[ci] for ci in colorinterp)