예제 #1
0
def rm(rm_args=None):
    global c
    global evaledpaths
    args = ''
    paths = []
    evalpaths = []
    option_end = False
    if not rm_args:
        rm_args = argv[1:]
    for arg in rm_args:
        if arg == '--':
            option_end = True
        elif (arg.startswith("-") and not option_end) or arg in c.invalid:
            pass
        else:
            path = abspath(expv(expu(arg)))
            file_evalpaths = gen_evalpaths(path)
            evalpath = gen_eval(path)
            if c.suffix in arg:
                pprint(path + " is a protection file")
                if ask_in(q="Do you want to remove it? (y/n) ", a="Yesyes"):
                    args += arg + ' '
                else:
                    pprint(path + " will not be removed")
                continue
            if exists(evalpath):
                if ask(evalpath):
                    paths.append(path)
                    evalpaths.append(evalpath)
                else:
                    continue
            if not parent_clear(file_evalpaths, path):
                continue
            if isdir(path):
                find_exec = "find " + path + " -name " + "\".*" + c.suffix + "\"" + " -print"
                out, err = Popen(find_exec,
                                 shell=True,
                                 stdout=PIPE,
                                 stderr=PIPE,
                                 universal_newlines=True).communicate()
                for pfile in iter(out.splitlines()):
                    pprint("A protected file or directory is found inside " +
                           path)
                    if not ask(pfile):
                        pprint(
                            "Terminated due to potentially dangerous action")
                        exit(1)
        args += bash_path(arg) + ' '
    Popen("rm " + args, shell=True).wait()
    remove_protection_files = ''
    for evalpath, path in zip(evalpaths, paths):
        if exists(evalpath) and not exists(path):
            remove_protection_files += bash_path(evalpath) + ' '
    if remove_protection_files:
        Popen("rm " + remove_protection_files, shell=True).wait()
    evaledpaths = []
예제 #2
0
def protect(protect_args=None):
    c = Config()
    if not protect_args:
        protect_args = argv[1:]
    for arg in protect_args:
        if arg in c.invalid:
            print("\".\" and \"..\" may not be protected")
        else:
            path = abspath(expv(expu(arg)))
            evalpath = dirname(path) + "/." + basename(path) + c.suffix
            if not exists(path):
                print("Warning: " + path + " does not exist")
            with open(evalpath, "w") as f:
                question = input("Question for " + path + ": ")
                answer = input("Answer: ")
                f.write(question + "\n" + answer)
예제 #3
0
def protect(protect_args=None):
    global c
    flags = ''
    option_end = False
    if not protect_args:
        protect_args = argv[1:]
    for arg in protect_args:
        if arg == '--':
            option_end = True
        elif (arg.startswith("-") and not option_end):
            flags = flags + arg[arg.rfind('-') + 1:]
        elif arg in c.invalid:
            pprint('"." and ".." may not be protected')
        else:
            path = abspath(expv(expu(arg)))
            evalpath = dirname(path) + "/." + basename(path) + c.suffix
            if not exists(path):
                pprint("Warning: " + path + " does not exist")
            with open(evalpath, "w") as f:
                question = input("Question for " + path + ": ")
                answer = input("Answer: ")
                f.write(question + "\n" + answer + "\n" + flags.upper())