Ejemplo n.º 1
0
def stab_sw_type(x):
    x = int(x)
    if not 5 <= x <= 150:
        raise ArgumentTypeError(
            "Stabilization search width must be between 5 and 150 pixels")
    return x
def email_argument(email):
    try:
        validate_email(email)
    except ValidationError:
        raise ArgumentTypeError(f"'{email}' n'est pas une adresse email valide.")
    return email
def handle_action(op, args, kwargs, only_validate=False):
    fn = getattr(action_handlers, op, None)
    if fn is None:
        raise ArgumentTypeError("Action %r is not found in %r" %
                                (op, ACTION_DIR))
    yield from fn(*args, **kwargs, only_validate=only_validate)
Ejemplo n.º 4
0
import zipfile

from argparse import ArgumentParser, ArgumentTypeError

from src import settings
from src.logic.loader import Loader

if __name__ == '__main__':
    parser = ArgumentParser(description="Process import arguments")
    parser.add_argument('model', action='store', help="Model name")
    parser.add_argument('connection', action='store', help="Database connection URI")
    parser.add_argument('name', action='store', help="Name json file to be imported")

    args = parser.parse_args()
    if '.' in args.name and 'json' not in args.name.split('.'):
        raise ArgumentTypeError("Only json is currently supported for the import! Use a json format")

    name = args.name
    if '.json' not in args.name:
        name += '.json'
    # unzip fake_profiles.zip
    path = settings.BASEPATH + '/assets/%s' % name.replace('.json', '.zip')
    if os.path.isfile(path):
        with zipfile.ZipFile(path, 'r') as zipped:
            zipped.extractall(settings.BASEPATH + '/assets')
        os.remove(path)

    # this class make as assumption the fact that a csv columns
    # corresponds to a model class, if a csv maps more models
    # all together I need to change it
    Loader(args.model, args.connection, '/assets/%s' % name).execute()
Ejemplo n.º 5
0
 def wrapper(input: str) -> Any:
     try:
         return inner(input)
     except ValueError as e:
         raise ArgumentTypeError(e)
Ejemplo n.º 6
0
def currency_type(value):
    if not re.match("^[a-z]{3}$", value, re.IGNORECASE):
        raise ArgumentTypeError("Invalid currency code '{}'".format(value))

    return value.upper()
Ejemplo n.º 7
0
Archivo: display.py Proyecto: zhu/eyeD3
 def filename(fn):
     if not os.path.exists(fn):
         raise ArgumentTypeError("The file %s does not exist!" % fn)
     return fn
Ejemplo n.º 8
0
def normalize_bco_type(x):
    x = int(x)
    if not 0 <= x <= 40:
        raise ArgumentTypeError(
            "Normalization black cut-off must be between 0 and 40")
    return x
Ejemplo n.º 9
0
def chkpath(path):
    if os.path.exists(path):
        return os.path.abspath(path)

    raise ArgumentTypeError(f"{path} does not exist.")
Ejemplo n.º 10
0
def align_min_bright_type(x):
    x = int(x)
    if not 2 <= x <= 50:
        raise ArgumentTypeError(
            "Alignment point minimum brightness must be between 2 and 50")
    return x
Ejemplo n.º 11
0
def stack_number_type(x):
    x = int(x)
    if not 1 <= x:
        raise ArgumentTypeError(
            "Number of best frames to be stacked must be greater or equal 1")
    return x
Ejemplo n.º 12
0
def align_min_struct_type(x):
    x = float(x)
    if not 0.01 <= x <= 0.30:
        raise ArgumentTypeError(
            "Alignment point minimum structure must be between 0.01 and 0.30")
    return x
Ejemplo n.º 13
0
def align_search_width_type(x):
    x = int(x)
    if not 6 <= x <= 30:
        raise ArgumentTypeError(
            "Alignment point search width must be between 6 and 30 pixels")
    return x
Ejemplo n.º 14
0
def align_box_width_type(x):
    x = int(x)
    if not 20 <= x <= 140:
        raise ArgumentTypeError(
            "Alignment point box width must be between 20 and 140 pixels")
    return x
Ejemplo n.º 15
0
def yyyy_mm_dd_date(string: str) -> date:
    try:
        return datetime.strptime(string, "%Y-%m-%d").date()
    except ValueError:
        raise ArgumentTypeError('Can not parse date: "{}". Make sure it is in '
                                "YYYY-MM-DD format.".format(string))
Ejemplo n.º 16
0
def isDirPath(path):
    if os.path.isdir(path):
        return path
    else:
        raise ArgumentTypeError(f"invalid dir path: {path}")
Ejemplo n.º 17
0
    def __call__(self, string):
        values = set(filter(lambda v: v.strip(), string.split(',')))
        if not values:
            raise ArgumentTypeError("List is empty")

        return values
Ejemplo n.º 18
0
def isFilePath(path):
    if os.path.isfile(path):
        return path
    else:
        raise ArgumentTypeError(f"invalid file path: {path}")
def log_level_to_int(log_level_string):
    if log_level_string not in log_levels:
        message = 'invalid choice: {0} (choose from {1})'.format(log_level_string, log_levels)
        raise ArgumentTypeError(message)

    return getattr(logging, log_level_string, logging.ERROR)
Ejemplo n.º 20
0
def isValidPrefix(prefix):
    if re.compile(r"^[a-zA-Z0-9_-]+$").match(prefix):
        return prefix
    else:
        raise ArgumentTypeError(f"invalid output file prefix: {prefix}")
Ejemplo n.º 21
0
 def __init__(self, regex, path_context=None):
     if not regex:
         raise ArgumentTypeError("filter cannot be empty")
     super(NonEmptyFilterOption, self).__init__(regex, path_context)
Ejemplo n.º 22
0
def check_supported_json_format(value):
    if value and not value in SUPPORTED_JSON_REPORT_FORMATS:
        raise ArgumentTypeError(f'JSON report type must be one of the following types: '
                                + ', '.join(SUPPORTED_JSON_REPORT_FORMATS))
    return value
Ejemplo n.º 23
0
def existing_file(fname):
    if not os.path.isfile(fname):
        raise ArgumentTypeError(
            "'{}' does not refer to an existing file".format(fname))
    return fname
Ejemplo n.º 24
0
 def parse_float(s):
     try:
         return float(s)
     except ValueError:
         raise ArgumentTypeError(f'invalid float value: {s}')
Ejemplo n.º 25
0
 def __valid_dir_path(file_path: str) -> str:
     '''Verifies that specified file path exists.'''
     file_path = path.abspath(file_path)
     if not path.isdir(file_path):
         raise ArgumentTypeError('{} does not exist.'.format(file_path))
     return file_path
Ejemplo n.º 26
0
def _parse_timestamp(arg):
    try:
        return T(arg)
    except Exception:
        raise ArgumentTypeError(
            "%r is not in the format 'YYYY-MM-DD HH:MM:SS.SSS +ZZ:ZZ'" % arg)
    def cursor_motion(*,
                      path,
                      steps,
                      radius=100,
                      repeat=1,
                      only_validate=False):
        """
        path: The path type to use in ('CIRCLE').
        steps: The number of events to generate.
        radius: The radius in pixels.
        repeat: Number of times to repeat the cursor rotation.
        """

        import time
        from math import sin, cos, pi

        valid_items = range(1, sys.maxsize)
        if steps not in valid_items:
            raise ArgumentTypeError("'steps' argument %r not in %r" %
                                    (steps, valid_items))

        valid_items = range(1, sys.maxsize)
        if radius not in valid_items:
            raise ArgumentTypeError("'radius' argument %r not in %r" %
                                    (steps, valid_items))

        valid_items = ('CIRCLE', )
        if path not in valid_items:
            raise ArgumentTypeError("'path' argument %r not in %r" %
                                    (path, valid_items))

        valid_items = range(1, sys.maxsize)
        if repeat not in valid_items:
            raise ArgumentTypeError("'repeat' argument %r not in %r" %
                                    (repeat, valid_items))
        del valid_items

        if only_validate:
            return

        x_init, y_init = mouse_location_get()

        y_init_ofs = y_init + radius

        yield dict(type='MOUSEMOVE', value='NOTHING', x=x_init, y=y_init_ofs)

        print("\n" "Times for: %s" % os.path.basename(bpy.data.filepath))

        t = time.time()
        step_total = 0

        if path == 'CIRCLE':
            for _ in range(repeat):
                for i in range(1, steps + 1):
                    phi = (i / steps) * 2.0 * pi
                    x_ofs = -radius * sin(phi)
                    y_ofs = +radius * cos(phi)
                    step_total += 1
                    yield dict(
                        type='MOUSEMOVE',
                        value='NOTHING',
                        x=int(x_init + x_ofs),
                        y=int(y_init + y_ofs),
                    )

        delta = time.time() - t
        delta_step = delta / step_total
        print(
            "Average:",
            ("%.6f FPS" % (1 / delta_step)).rjust(10),
        )

        yield dict(type='MOUSEMOVE', value='NOTHING', x=x_init, y=y_init)
Ejemplo n.º 28
0
def percent(string):
    val = float(string)
    if val < 0 or val > 1:
        raise ArgumentTypeError("'" + string + "' is not a fraction between 0 and 1.)")
    return val
Ejemplo n.º 29
0
 def _checker(value):
     if int(value) >= lower and int(value) < upper:
         return int(value)
     raise ArgumentTypeError('Must be greater >= {} and < {}'.format(
         lower, upper))
Ejemplo n.º 30
0
def stab_size_type(x):
    x = int(x)
    if not 5 <= x <= 80:
        raise ArgumentTypeError(
            "Stabilization patch size must be between 5% and 80%")
    return x