Esempio n. 1
0
def pre_build():
    import sys
    sys.path += ['']
    from lib.dumper import dump
    dump()
    #Do whatever you want before the _site is built
    pass
Esempio n. 2
0
def main():
    parser = OptionParser()
    parser.add_option("-r", "--range", dest="numrange",
                      help="input int numrange")
    parser.add_option("-d", "--debug", dest="debug",
                      default = 0,
                      help="turn debugging on/off")

    (options, args) = parser.parse_args()

    if (options.numrange is None):
        raise ex.exceptions.NoArgError("no numrange provided")

    numrange = options.numrange
    one_idx = lib.utils.chk_pow_2(numrange)
    if one_idx == -1:
        raise ex.exceptions.BadArgError("numrange should be power of 2");
    bitlen = one_idx

    global DEBUG
    DEBUG = options.debug
    
    try:
        numrange = lib.utils.xform_elem(numrange, int)
    except ex.exceptions.ValidationError as e:
        raise ex.exceptions.ValidationError(e.message)
        return(2)

    try:
        list_data = prepare_list(numrange, bitlen)
    except ex.exceptions.ValidationError as e:
        raise ex.exceptions.ValidationError(e.message)
        return(2)

    try:
        missing_elem_data = remove_elem(list_data['numlist_bin'])
    except ex.exceptions.ValidationError as e:
        raise ex.exceptions.ValidationError(e.message)
        return(2)

    print "STATUS: excluding " +\
          str(missing_elem_data['exclude_int']) +\
          " => " + missing_elem_data['exclude_int_bin']

    if DEBUG:
        print "Randomly shuffled search list: "
        print(dumper.dump(list_data['numlist_bin']))

    found_missing_elem = find_missing_elem(list_data['numlist_bin'])
    found_missing_elem = lib.utils.bin2dec(found_missing_elem)

    if missing_elem_data['exclude_int'] != found_missing_elem:
        print "FAILURE: Target " +\
              str(missing_elem_data['exclude_int']) +\
              " != Found " + str(found_missing_elem)
    else:
        print "SUCCESS: Target " +\
              str(missing_elem_data['exclude_int']) +\
              " == Found " + str(found_missing_elem)
def main():
    parser = OptionParser()
    parser.add_option("-t", "--target", dest="target", help="the target to convert")
    parser.add_option("-s", "--src", dest="src", help="target source")
    parser.add_option("-d", "--dest", dest="dest", help="target dest")
    parser.add_option("-l", "--list", dest="list", default=False, help="list out the valid conversions")

    (options, args) = parser.parse_args()

    valid_conversions = lib.utils.get_valid_num_conversions()

    if options.list is not False:
        print "valid number conversions are:"
        print (dumper.dump(valid_conversions))
        return 0

    if options.target is None:
        raise ex.exceptions.NoArgError("no target provided")

    target = options.target

    if options.src is None:
        raise ex.exceptions.NoArgError("no src provided")
    if options.src not in valid_conversions:
        raise ex.exceptions.BadArgError("invalid source " + options.src)

    src = options.src

    if options.dest is None:
        raise ex.exceptions.NoArgError("no dest provided")

    valid_dests = valid_conversions[src].keys()

    if not options.dest in valid_dests:
        raise ex.exceptions.NoArgError("invalid dest " + options.dest)

    dest = options.dest
    callback = valid_conversions[src][dest]["converter"]
    try:
        converted_src = callback(target)
        if "formatter" in valid_conversions[src][dest]:
            formatter = valid_conversions[src][dest]["formatter"]
            converted_src = formatter(converted_src)
        print converted_src
    except ex.exceptions.ValidationError as e:
        print e
        return 2
Esempio n. 4
0
def find_missing_elem(numlist_bin, curr_bit = 0, elem_bit_str = ''):
    if DEBUG:
        print "----------------"
        print(dumper.dump(numlist_bin))
        print "dataset_size      " + str(len(numlist_bin))
        print "curr_bit          " + str(curr_bit)
        print "curr_elem_bit_str " + elem_bit_str

    if (len(numlist_bin) == 1):
        working_bit = len(numlist_bin[0]) - curr_bit - 1
        missing_elem_bit = int(numlist_bin[0][working_bit]) ^ 1;
        elem_bit_str = str(missing_elem_bit) + elem_bit_str 
        return elem_bit_str

    zero_list = []
    one_list = []
    working_bit = len(numlist_bin[0]) - curr_bit - 1

    for elem in numlist_bin:
        if (elem[working_bit] == '0'):
            zero_list.append(elem)
        else:
            one_list.append(elem)

    missing_elem_bit = -1
    if (len(zero_list) > len(one_list)):
        missing_elem_bit = 1
        if DEBUG:
            print "Deleting zeros list"
        [ numlist_bin.remove(x) for x in zero_list ]
    else:
        missing_elem_bit = 0
        if DEBUG:
            print "Deleting ones list"
        [ numlist_bin.remove(x) for x in one_list ]
    
    elem_bit_str = str(missing_elem_bit) + elem_bit_str
    elem_bit_str = find_missing_elem(numlist_bin, 
                                     curr_bit + 1, 
                                     elem_bit_str)
    return elem_bit_str