gentoo-tools

Some Gentoo helper tools
git clone git://r-36.net/gentoo-tools
Log | Files | Refs | LICENSE

commit 78bc0e05d951a2eee5f6169443c47c281df05e95
parent 2bc2d9a37d89529c37a013e89809a66f9dfad0b2
Author: Christoph Lohmann <20h@r-36.net>
Date:   Sat, 27 Dec 2014 11:02:08 +0100

Adding three new tools: edepclean, euseflags and eworld

Diffstat:
bin/edepclean | 4++++
bin/euseflags | 98+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
bin/eworld | 4++++
3 files changed, 106 insertions(+), 0 deletions(-)

diff --git a/bin/edepclean b/bin/edepclean @@ -0,0 +1,4 @@ +#!/bin/sh + +emerge --depclean + diff --git a/bin/euseflags b/bin/euseflags @@ -0,0 +1,98 @@ +#!/usr/bin/env python +# coding=utf-8 +# +# Copy me if you can. +# by 20h +# + +import os +import sys +import getopt +import requests +from lxml import etree +import io +from termcolor import colored + +def xmlhtml(fd): + return etree.parse(io.StringIO(fd.text), etree.HTMLParser()) + +def usage(app): + app = os.path.basename(app) + sys.stderr.write("usage: %s [-hc] [-b baseuri] [useflag]\n" % (app)) + sys.exit(1) + +def main(args): + try: + opts, largs = getopt.getopt(args[1:], "hb:cl") + except getopt.GetoptError as err: + print(str(err)) + usage(args[0]) + + baseuri = "http://www.gentoo.org/dyn/use-index.xml" + docolor = False + dolist = False + for o, a in opts: + if o == "-h": + usage(args[0]) + elif o == "-b": + baseuri = a + elif o == "-c": + docolor = True + elif o == "-l": + dolist = True + else: + assert False, "unhandled option" + + suseflag = None + if len(largs) > 0: + suseflag = largs[0] + + xml = xmlhtml(requests.get(baseuri)) + + table = xml.xpath("//table[@class=\"ntable\"]") + if len(table) < 1: + return 1 + + useflags = {} + + trs = table[0].xpath("./tr") + if len(trs) < 2: + return 1 + + for tr in trs[1:]: + tds = tr.xpath("./td") + if len(tds) < 2: + continue + + useflag = ("".join(tds[0].itertext())).strip() + text = ("".join(tds[1].itertext())).strip() + + useflags[useflag] = text + + if dolist == True: + for k in sorted(useflags.keys()): + print("%s" % (k)) + else: + if docolor == True: + color = "yellow" + else: + color = None + + if suseflag != None: + if not suseflag in useflags: + sys.stderr.write("'%s' not found.\n" % \ + (suseflag)) + return 1 + iuseflags = [suseflag] + else: + iuseflags = sorted(useflags.keys()) + + for useflag in iuseflags: + print("%s %s" % (colored("%15s" % (useflag), color=color),\ + useflags[useflag])) + + return 0 + +if __name__ == "__main__": + sys.exit(main(sys.argv)) + diff --git a/bin/eworld b/bin/eworld @@ -0,0 +1,4 @@ +#!/bin/sh + +emerge "$@" @world +