Exemple #1
0
def remove_pair():

    try:
        delkey = argv[2]
        for line in symget_basefunctions.file_reader(sym_map):
            if delkey == line.split(",")[0]:
                break
            else:
                continue
        else:
            print "Keyword not found in map"
            exit(0)

        print "Press enter to to delete \"{}\" from character map or ctrl-D to cancel.".format(delkey)
        raw_input(": ")

        symget_basefunctions.backup_map()

        # a generator expression that returns a tuple of items from generator file_reader
        # ... which returns lines sym_map
        key_value = ((line.split(",")[0],line.split(",")[1]) for line in symget_basefunctions.file_reader(sym_map))
        map_cache = dict(key_value)

        with open(sym_map, "w") as target:
            for key,value in map_cache.iteritems():
                if delkey != key:
                    target.write(key+","+value+"\n")
                else:
                    continue

        print "{} deleted from sym_map".format(delkey)

    except EOFError:
        exit(0)
Exemple #2
0
def print_map():
    # determines column length according to nr of items in map and prints formatted map

    col1 = []
    col2 = []
    col3 = []

    total_len = sum(1 for item in symget_basefunctions.file_reader(
        sym_map))  # total num of items in file

    # if not divisible by three, then +1 to col length
    if total_len % 3 == 0:
        col_len = total_len / 3
    else:
        col_len = (total_len / 3) + 1

    # fill column lists from by column length
    for num, item in enumerate(symget_basefunctions.file_reader(sym_map)):
        if num + 1 <= col_len:
            col1.append(item)
        elif col_len < num + 1 <= col_len * 2:
            col2.append(item)
        elif col_len * 2 < num + 1 <= col_len * 3:
            col3.append(item)
        else:
            raise IndexError
            exit(0)

    # filler for last column, zip requires equal length lists to display properly
    for num in range(len(col1) - len(col3)):
        col3.append("")

    columnified = zip(col1, col2, col3)

    # num for troubleshooting if not displaying correctly, probably not necessary
    for num, args in enumerate(columnified):
        print "{:<4}{:20}\t{:20}\t{:20}".format(num + 1, *args)
Exemple #3
0
def print_map():
    # determines column length according to nr of items in map and prints formatted map

    col1 = []
    col2 = []
    col3 = []

    total_len = sum(1 for item in symget_basefunctions.file_reader(sym_map)) # total num of items in file

    # if not divisible by three, then +1 to col length
    if total_len % 3 == 0:
        col_len = total_len/3
    else:
        col_len = (total_len/3)+1

    # fill column lists from by column length
    for num,item in enumerate(symget_basefunctions.file_reader(sym_map)):
        if num+1 <= col_len:
            col1.append(item)
        elif col_len < num+1 <= col_len*2:
            col2.append(item)
        elif col_len*2 < num+1 <= col_len*3:
            col3.append(item)
        else:
            raise IndexError
            exit(0)

    # filler for last column, zip requires equal length lists to display properly
    for num in range(len(col1)-len(col3)):
        col3.append("")

    columnified = zip(col1, col2, col3)

    # num for troubleshooting if not displaying correctly, probably not necessary
    for num,args in enumerate(columnified):
        print "{:<4}{:20}\t{:20}\t{:20}".format(num+1,*args)
Exemple #4
0
def remove_pair():

    try:
        delkey = argv[2]
        for line in symget_basefunctions.file_reader(sym_map):
            if delkey == line.split(",")[0]:
                break
            else:
                continue
        else:
            print "Keyword not found in map"
            exit(0)

        print "Press enter to to delete \"{}\" from character map or ctrl-D to cancel.".format(
            delkey)
        raw_input(": ")

        symget_basefunctions.backup_map()

        # a generator expression that returns a tuple of items from generator file_reader
        # ... which returns lines sym_map
        key_value = ((line.split(",")[0], line.split(",")[1])
                     for line in symget_basefunctions.file_reader(sym_map))
        map_cache = dict(key_value)

        with open(sym_map, "w") as target:
            for key, value in map_cache.iteritems():
                if delkey != key:
                    target.write(key + "," + value + "\n")
                else:
                    continue

        print "{} deleted from sym_map".format(delkey)

    except EOFError:
        exit(0)