summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Dolbec <dolsen@gentoo.org>2012-03-18 23:47:38 -0700
committerBrian Dolbec <dolsen@gentoo.org>2012-03-18 23:47:38 -0700
commit167e4c05ba1057eac50cfadee3c074a2edda1fe8 (patch)
treec71dfcc76333067724457c50113360f67ad8f038
parent2b73c56a831e188b1780f0749564dad8af8d13f8 (diff)
downloadgentoolkit-167e4c05ba1057eac50cfadee3c074a2edda1fe8.tar.gz
add an ebuild listing option to equery which as requested by Calchan and ryao.
-rw-r--r--pym/gentoolkit/equery/which.py23
1 files changed, 19 insertions, 4 deletions
diff --git a/pym/gentoolkit/equery/which.py b/pym/gentoolkit/equery/which.py
index 5259d46..da60a1b 100644
--- a/pym/gentoolkit/equery/which.py
+++ b/pym/gentoolkit/equery/which.py
@@ -30,7 +30,10 @@ from gentoolkit.query import Query
# Globals
# =======
-QUERY_OPTS = {"include_masked": False}
+QUERY_OPTS = {
+ "include_masked": False,
+ "ebuild":False
+ }
# =========
# Functions
@@ -51,9 +54,17 @@ def print_help(with_description=True):
print(pp.command("options"))
print(format_options((
(" -h, --help", "display this help message"),
- (" -m, --include-masked", "return highest version ebuild available")
+ (" -m, --include-masked", "return highest version ebuild available"),
+ (" -e, --ebuild", "print the ebuild")
)))
+def print_ebuild(ebuild_path):
+ """Output the ebuild to std_out"""
+ with open(ebuild_path) as f:
+ lines = f.readlines()
+ print("\n\n")
+ print("".join(lines))
+ print("\n")
def parse_module_options(module_opts):
"""Parse module options and update QUERY_OPTS"""
@@ -65,13 +76,15 @@ def parse_module_options(module_opts):
sys.exit(0)
elif opt in ('-m', '--include-masked'):
QUERY_OPTS['include_masked'] = True
+ elif opt in ('-e', '--ebuild'):
+ QUERY_OPTS['ebuild'] = True
def main(input_args):
"""Parse input and run the program"""
- short_opts = "hm"
- long_opts = ('help', 'include-masked')
+ short_opts = "hme"
+ long_opts = ('help', 'include-masked', 'ebuild')
try:
module_opts, queries = gnu_getopt(input_args, short_opts, long_opts)
@@ -97,6 +110,8 @@ def main(input_args):
ebuild_path = pkg.ebuild_path()
if ebuild_path:
pp.uprint(os.path.normpath(ebuild_path))
+ if QUERY_OPTS['ebuild']:
+ print_ebuild(ebuild_path)
else:
sys.stderr.write(
pp.warn("No ebuilds to satisfy %s" % pkg.cpv)