commit b5a82979325358bb132222d9a7b0ddf279395cb4
parent 5a7fa31bc9270ab2a03c635cfacd525ddaa53414
Author: Christoph Lohmann <20h@r-36.net>
Date: Sun, 28 Aug 2022 20:50:28 +0200
Change euseflags to use equery.
Thanks Spenser Truex <truex@equwal.com> for the hint!
Diffstat:
M | bin/euseflags | | | 98 | ++----------------------------------------------------------------------------- |
1 file changed, 2 insertions(+), 96 deletions(-)
diff --git a/bin/euseflags b/bin/euseflags
@@ -1,98 +1,4 @@
-#!/usr/bin/env python
-# coding=utf-8
-#
-# Copy me if you can.
-# by 20h
-#
+#!/bin/sh
-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))
+equery u "$@"