Beispiel #1
0
def add_line(file, line, content):
    if (line < 0):
        exception_builder(3)
    fd = get_file(file)
    ln = get_line_number(fd)
    if (line > ln):
        fd.write(content)
        fd.write("\n")
    else:
        prec = get_line(file, 0, line - 1)
        rearc = get_line(file, line, 0)
        content = prec + content + "\n" + rearc
        close_file(fd)
        fd = get_clear_file(file)
        fd.write(content)

    return True
    close_file(fd)
Beispiel #2
0
def del_line(file, line):
    if (line < 0):
        exception_builder(3)
    fd = get_file(file)
    ln = get_line_number(fd)
    if (line > ln):
        exception_builder(3)
    else:
        prec = get_line(file, 0, line - 1)
        rearc = get_line(file, line + 1)
        content = prec + rearc
        close_file(fd)
        fd = get_clear_file(file)
        # print(content)
        # print('\n')
        fd.write(content)

    return True
    close_file(fd)
Beispiel #3
0
def del_gop(sharg):
    if (sharg == ""):
        exception_builder(0)

    # args = sharg.split(',', -1)
    # if (len(args) != 2) :
    #     exception_builder(0)
    print('func: del gopath shortcuts cmd "gop ' + sharg + '"')
    token = token_builder(sharg)
    if (get_token_line(gopathfile, token) != -1):
        #del line
        try:
            del_usage = get_token_line(gopathfile, token)
            print("... del usage to gopath script")
            del_line(gopathfile, del_usage)
            del_line(gopathfile, del_usage)

            del_dir = get_token_line(gopathfile, token)
            print("... del dir to gopath script")
            del_line(gopathfile, del_dir)
            del_line(gopathfile, del_dir)

            del_cmd = get_token_line(gopathfile, token)
            print("... del cmd to gopath script")
            del_line(gopathfile, del_cmd)
            del_line(gopathfile, del_cmd)
            del_line(gopathfile, del_cmd)
            del_line(gopathfile, del_cmd)
        except UserWarning:
            print(
                hint_builder("gopath file has been compromised",
                             "re-install or add token to source file"))

        #sync
        os.system("worker syncgop")
        print("gopath cmd \" gop " + sharg + "\" now is deleted")

    else:
        exception_builder(4)
Beispiel #4
0
def add_gop(sharg):
    if (sharg == ""):
        exception_builder(0)

    args = sharg.split(',', -1)
    print('func: add gopath shortcuts cmd "gop ' + args[0] +
          '" refer to gopath ' + args[1])
    if (len(args) != 2):
        exception_builder(0)
    if (os.path.exists(args[1])):
        #build input line
        # usage_line = " \t" + token_builder(args[0]) + "\n\techo \"" + args[0] + ": " + args[1] + "\""
        usage_line = " \t" + token_builder(
            args[0]) + "\n\techo \"" + args[0] + ": ${" + args[0] + "_dir}\""
        dir_line = token_builder(args[0]) + "\n" + args[0] + "_dir=" + args[1]
        cmd_line = token_builder(
            args[0]) + "\nelif [ $1 == \"" + args[0] + "\" ]; then\n\
\techo \"gopath " + args[1] + "\"\n\
\tcd ${" + args[0] + "_dir}"

        #insert line to gopathfile
        if (-1 == get_token_line(gopathfile, token_builder(args[0]))):
            try:
                print("... add usage to gopath script")
                add_line(gopathfile,
                         get_token_line(gopathfile, "#token_insert_usage"),
                         usage_line)
                print("... add dir to gopath script")
                add_line(gopathfile,
                         get_token_line(gopathfile, "#token_insert_dir"),
                         dir_line)
                print("... add cmd to gopath script")
                add_line(gopathfile,
                         get_token_line(gopathfile, "#token_insert_cmd"),
                         cmd_line)
            except UserWarning:
                print(
                    hint_builder("gopath file has been compromised",
                                 "re-install or add token to source file"))
        else:
            exception_builder(2)

        #sync
        os.system("worker syncgop")
        print("gopath cmd \" gop " + args[0] + "\" now is ready")

    else:
        exception_builder(1)