Revert: Use join() rather than string printing.
[gentoolkit.git] / pym / gentoolkit / eshowkw / __init__.py
index efcbfb97ed1baec654bb108d6065a834912d0d6a..cb957a34109d6a374d8f5959e95ba2289b67e8da 100644 (file)
@@ -1,8 +1,10 @@
+#      vim:fileencoding=utf-8
 # Copyright 2010 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
-__package__ = 'eshowkw'
-__version__ = '0.5'
+__package__ = 'gentoolkit.eshowkw'
+__version__ = 'svn'
+__author__ = "Tomáš Chvátal <scarabeus@gentoo.org>"
 
 import portage
 
@@ -14,10 +16,10 @@ from portage import config as portc
 from portage import portdbapi as portdbapi
 from portage import db as portdb
 
-from keywords_header import keywords_header
-from keywords_content import keywords_content
-from display_pretty import string_rotator
-from display_pretty import display
+from .keywords_header import keywords_header
+from .keywords_content import keywords_content
+from .display_pretty import string_rotator
+from .display_pretty import display
 
 ignore_slots = False
 bold = False
@@ -36,7 +38,7 @@ def process_display(package, keywords, dbapi):
                header_length = portdata.version_length
                content_length = keywords.length
        else:
-               header = string_rotator().rotateContent(portdata.content, portdata.content_length, order, bold)
+               header = string_rotator().rotateContent(portdata.content, portdata.content_length, bold)
                content = keywords.content
                sep = [''.ljust(keywords.length) for x in range(portdata.slot_length-1)]
                content.extend(sep)
@@ -73,9 +75,9 @@ def process_args(argv):
        parser.add_argument('-S', '--ignore-slot', action='store_true', default=False,
                help='Treat slots as irelevant during detection of redundant pacakges.')
 
-       return parser.parse_args(args=argv[1:])
+       return parser.parse_args(args=argv)
 
-def main(argv):
+def main(argv, indirect = False):
        global ignore_slots, bold, order, topper
 
        #opts parsing
@@ -92,6 +94,12 @@ def main(argv):
        prefix = opts.prefix
        color = opts.color
        package = opts.package
+
+       # equery support
+       if indirect and len(package) <= 0:
+               msg_err = 'No packages specified'
+               raise SystemExit(msg_err)
+
        # disable colors when redirected and they are not forced on
        if not color and not sys.stdout.isatty():
                # disable colors
@@ -104,16 +112,16 @@ def main(argv):
                map(lambda x: process_display(x, keywords, dbapi), package)
        else:
                currdir = os.getcwd()
-               package=os.path.basename(currdir)
                # check if there are actualy some ebuilds
                ebuilds = ['%s' % x for x in os.listdir(currdir)
-                       if fnmatch.fnmatch(file, '*.ebuild')]
+                       if fnmatch.fnmatch(x, '*.ebuild')]
                if len(ebuilds) <= 0:
                        msg_err = 'No ebuilds at "%s"' % currdir
                        raise SystemExit(msg_err)
+               package= '%s/%s' % (os.path.basename(os.path.abspath('../')), os.path.basename(currdir))
                ourtree = os.path.abspath('../../')
-
-               mysettings = portc(env={'PORTDIR_OVERLAY': os.path.abspath('../../')})
+               overlays = '%s %s' % (ports['PORTDIR_OVERLAY'], ourtree)
+               mysettings = portc(env={'PORTDIR_OVERLAY': overlays})
                dbapi = portdbapi(mysettings=mysettings)
                # specify that we want just our nice tree we are in cwd
                dbapi.porttrees = [ourtree]
@@ -121,4 +129,4 @@ def main(argv):
        return 0
 
 if __name__ == '__main__':
-       sys.exit(main(sys.argv))
+       sys.exit(main(sys.argv[1:]))