Commit ef76dda0 authored by Seblu's avatar Seblu
Browse files

find-libdeps: Colored output

parent 3205edaf
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -7,7 +7,8 @@ pkgdesc='Seblu Archlinux Utils'
arch=('any')
url='https://github.com/seblu/archutils'
license=('GPL2')
depends=('python' 'bash' 'zsh' 'file' 'grep' 'pyalpm' 'python-pyelftools')
depends=('python' 'bash' 'zsh' 'file' 'grep' 'pyalpm' 'python-pyelftools'
         'python-pygments')
provides=('archutils' 'kernel-reinstall')
replaces=('kernel-reinstall')
conflicts=('archutils' 'kernel-reinstall')
+28 −10
Original line number Diff line number Diff line
@@ -24,15 +24,32 @@ from elftools.elf.dynamic import DynamicSection, DynamicSegment
from elftools.elf.elffile import ELFFile
from os import walk, environ, getcwd, chdir, access, R_OK
from os.path import join, exists, isdir, isfile, normpath, realpath
from pprint import pprint
from pprint import pformat
from pycman import config
from pygments import highlight
from pygments.formatters import TerminalFormatter, NullFormatter
from pygments.lexers import PythonLexer
from shlex import split
from sys import stderr
from sys import stdout, stderr
from tarfile import open as tar
from tempfile import TemporaryDirectory

PACKAGES = None

def msg(message):
    '''display arch linux message'''
    if stdout.isatty():
        stdout.write("\033[1;32m==> \033[1;37m%s\033[m\n" % message)
    else:
        stdout.write("==> %s\n" % message)

def err(message):
    '''display colored error'''
    if stderr.isatty():
        stderr.write("\033[1;31mERROR: \033[1;37m%s\033[m\n" % message)
    else:
        stderr.write("ERROR: %s\n" % message)

def missing_pkginfo(path, deps):
    '''show deps against path'''
    fpath = join(path, ".PKGINFO")
@@ -41,10 +58,7 @@ def missing_pkginfo(path, deps):
    pkginfo = parse_pkginfo(fpath)
    if "depend" not in pkginfo:
        return
    diff = set(deps.keys() - set(pkginfo["depend"]))
    if len(diff) > 0:
        print("\n:: Missing in .PKGINFO")
        pprint(diff)
    return(set(deps.keys() - set(pkginfo["depend"])))

def parse_pkginfo(path):
    '''parse a .PKGINFO file'''
@@ -123,13 +137,17 @@ def main():
        args.path = pkgdir.name
    if isdir(args.path):
        deps = find_deps(args.path)
        mdeps = missing_pkginfo(args.path, deps)
        # display deps
        print(":: Found deps")
        pprint(deps)
        msg("Found deps")
        formater = TerminalFormatter() if stdout.isatty() else NullFormatter()
        stdout.write(highlight(pformat(deps), PythonLexer(), formater))
        # show missing deps in .PKGINFO
        missing_pkginfo(args.path, deps)
        if len(mdeps) > 0:
            msg("Missing in .PKGINFO")
            stdout.write(highlight(pformat(mdeps), PythonLexer(), formater))
    else:
        stderr.write("Unsupported file type\n")
        err("Unsupported file type")
        return 2
    return 0