Beispiel #1
0
def enforce_duplicate_policy(name, category):
    from shared import opt
    import sys

    dup = get_duplicate_policy(category)
    if dup == '0' and item_exists(name):
        existing_category = get_category_from_title(name)
        existing_duplicate = get_duplicate_policy(existing_category)
        if existing_duplicate not in ["1", "2"]:
            text_warning("Item already exists in category '%s'. Use (--force, -f) to add anyway." % c(existing_category))
            if not opt.get('force'):
                sys.exit(1)

    # need to check both
    if dup == '1' and title_exists(category, name):
        text_warning(Misc.ERROR["itemexists"] % c(category))
        if not opt.get('force'):
            sys.exit(1)
    return
Beispiel #2
0
def is_valid_id(id):
    from sire.printer import text_error
    id = str(id)
    if id[0] == '%':
        if not is_valid_id_number(id[1:]):
            if config_value('warn.id') in [None, 1]:
                text_warning(Misc.ERROR['bad_id'] % c(id))
            return False

    if '-' in id:
        idrange = id.split('-')
        if not is_valid_id_number(idrange[0]) or not is_valid_id_number(idrange[1]) or (int(idrange[0]) > int(idrange[1])):
            if config_value('warn.range') in [None, 1]:
                text_warning(Misc.ERROR['bad_range'] % c(id))
            return False

    elif not is_valid_id_number(id):
        if config_value('warn.id') in [None, 1]:
            text_warning(Misc.ERROR['bad_id'] % c(id))
        return False
    return True
Beispiel #3
0
def get_info_from_id(id):
    from printer import text_warning
    result = dbman.get_item_with_id(str(id))
    if not result and config_value('warn.range') in [None, 1]:
        text_warning(Misc.ERROR["item"] % c(id))
    return result