Пример #1
0
 def _decorator(fn):
     if not fs.which(fpath):
         print("Error: {f} doesn't exist".format(f=fpath))
         print("Traceback: {func}() in {src}".format(func=fn.__name__,
                                                     src=__file__))
         my_exit(1)
     #
     def step_func(*args, **kwargs):
         return fn(*args, **kwargs)
     return step_func
Пример #2
0
def cache_pygmentize():
    """
    The first call of pygmentize is slow, thus we call it upon
    startup in the background.
    """
    fname = "{root}/assets/alap.py".format(root=cfg.ROOT)
    if fs.which("pygmentize") and os.path.isfile(fname):
        with open(os.devnull, 'w') as devnull:
            cmd = pcat.format(cfg.colors[cfg.g.BACKGROUND]["pygmentize_style"], fname)
            args = shlex.split(cmd)
            call(args, stdout=devnull, stderr=devnull)
Пример #3
0
def to_clipboards(key):
    if fs.which("xsel"):
        o = hdict[key]
        #
        action = o["action"]
        verb = action[0]
        if verb == 'cat':
            with open("data/" + action[1]) as f:
                text_to_clipboards(f.read().rstrip("\n"))
    else:
        print("Warning: xsel is not installed, cannot copy to clipboards.")
Пример #4
0
def path_to_clipboards(key):
    if fs.which("xsel"):
        o = hdict[key]
        #
        action = o["action"]
        verb = action[0]
        if verb == 'cat':
            f = os.path.abspath("data/" + action[1])
            print('#', f)
            text_to_clipboards(f)
    else:
        print("Warning: xsel is not installed, cannot copy to clipboards.")
Пример #5
0
def cat(fname, o, search_term=""):
    """
    Show file content on stdout.

    If pygmentize is available, show a syntax-highlighted output.
    Otherwise fall back to a normal "cat".
    """
    print(bold("-" * 78))
    doc = o["doc"]
    if doc:
        print(bold(doc))
        print(bold("-" * 78))
    if fs.which("pygmentize"):
        print_pcat(fname, search_term)
    else:
        with open(fname) as f:
            for line in f:
                if search_term in line:
                    print(line, end='')
    print()
Пример #6
0
def cat(fname, o):
    """
    Show file content on stdout.

    If pygmentize is available, show a syntax-highlighted output.
    Otherwise fall back to a normal "cat".
    """
    fname = "data/" + fname
    #
    print(bold("-" * 78))
    doc = o["doc"]
    if doc:
        print(bold(doc))
        print(bold("-" * 78))
    if fs.which("pygmentize"):
        os.system(pcat.format(cfg.colors[cfg.g.BACKGROUND]["pygmentize_style"], fname))
    else:
        with open(fname) as f:
            for line in f:
                print(line, end=' ')
    print()
    #
    process_extras(fname, o)
Пример #7
0
def cat(fname, o, search_term=""):
    """
    Show file content on stdout.

    If pygmentize is available, show a syntax-highlighted output.
    Otherwise fall back to a normal "cat".
    """
    p = Path(fname)
    ext = p.suffix

    print(bold("-" * 78))
    doc = o["doc"]
    if doc:
        print(bold(doc))
        print(bold("-" * 78))
    if fs.which("pygmentize") and ext != ".txt":    # .txt files were colored incorrectly, so let's switch coloring off for .txt files
        print_pcat(fname, search_term)
    else:
        with open(fname) as f:
            for line in f:
                if search_term in line:
                    print(line, end='')
    print()
Пример #8
0
def check_dependencies():
    for prg in dependencies:
        if not fs.which(prg):
            print("Warning: {0} is not available.".format(prg))
            print("tip: {0}".format(dependencies[prg]))