Ejemplo n.º 1
0
def man_upd(argv, childs, last_upd):
    """Manual update based on args.

    First it checks all args and only if all are correct are they processed.
    """
    arg_nok = ''
    args_ok = False

    # check args
    for arg in argv:
        if '-' in arg:
            child, days = str.lower(arg).split('-')
        elif '+' in arg:
            child, days = str.lower(arg).split('+')
        else:
            arg_nok = arg
            args_ok = False
            break

        try:
            days = int(days)
        except ValueError:  # as error:
            arg_nok = arg
            args_ok = False
            break

        if ((child in childs) and
           (-shrd.MAX_DAYS <= days <= shrd.MAX_DAYS)):
            args_ok = True
        else:
            arg_nok = arg
            args_ok = False
            break

    if args_ok:  # process args
        print_state(childs, last_upd)
        for arg in argv:
            if '-' in arg:
                child, days = str.lower(arg).split('-')
                days = -int(days)
            elif '+' in arg:
                child, days = str.lower(arg).split('+')
                days = int(days)

            childs[child] += days
            if childs[child] > 0:
                childs[child] = min(shrd.MAX_DAYS, childs[child])
            else:
                childs[child] = max(0, childs[child])
        last_upd = dt.date.today()
        shrd.update_file(childs, last_upd)
        print_state(childs, last_upd)
    else:
        print(clrm.Fore.RED + lcl.WRONG_ARG + arg_nok + '\n')
        print(clrm.Fore.RESET + common.usage())
Ejemplo n.º 2
0
    def set_upd_btn(upd):
        """Set or update selected child's grounded days."""
        global last_upd

        try:
            int(days_var.get())
        except ValueError:  # as error:
            days_var.set(0)

        if 0 <= int(days_var.get()) <= shrd.MAX_DAYS:
            childs[childs_combo.get()] = int(days_var.get())
            if upd:
                last_upd = shrd.auto_upd_datafile(childs, last_upd)
            else:
                last_upd = dt.date.today()
                shrd.update_file(childs, last_upd)
            last_upd_var.set(value=str(last_upd))
        else:
            tk_msg_box.showwarning(lcl.WARNING,
                                   lcl.DAYS_RANGE + shrd.MAX_DAYS_STR)
Ejemplo n.º 3
0
    def set_upd_btn(upd):
        """Set or update selected child's grounded days."""
        global last_upd

        try:
            int(days_var.get())
        except ValueError:  # as error:
            days_var.set(0)

        if 0 <= int(days_var.get()) <= shrd.MAX_DAYS:
            childs[childs_combo.get()] = int(days_var.get())
            if upd:
                last_upd = shrd.auto_upd_datafile(childs, last_upd)
            else:
                last_upd = dt.date.today()
                shrd.update_file(childs, last_upd)
            last_upd_var.set(value=str(last_upd))
        else:
            tk_msg_box.showwarning(lcl.WARNING, lcl.DAYS_RANGE +
                                   shrd.MAX_DAYS_STR)