File find.py of Package osc-plugin-find

# -*- coding: utf-8 -*-
# vim: ts=4 sw=4 sta ai:
# Find packages, with highlighting, a somewhat better and worse "osc search"
# Author: Pascal Bleser <pascal.bleser@opensuse.org>

@cmdln.alias('fi')
def do_find(self, subcmd, opts, *args):
    """${cmd_name}: show the most informative failed build

    ${cmd_usage}
    """

    search_term = None
    if len(args) > 1:
        raise oscerr.WrongArgs('Too many arguments.')
    elif len(args) < 1 and not for_user:
        raise oscerr.WrongArgs('Too few arguments.')
    elif len(args) == 1:
        search_term = args[0]
        pass

    result = search(conf.config['apiurl'], ['@name'], 'package', search_term)

    if result:
        # unfortunately, there is no sort support in the api.
        # we can do it here. Maybe it would be better done in osc.core.search() already.
        # hm... results is a flat list
        ## FIXME: this messes up with se -v .
        l = [ (j, i) for i, j in zip(*[iter(result)]*2) ]
        l.sort()
        result = []
        ##
        ## search used to report the table as
        ## 'package project', I see no reason for having package before project.
        ## But it definitly hinders copy-paste.
        ## Changed to more normal 'project package' ordering. 2009-10-05, jw
        ##
        for j, i in l:
            result.extend([j, i])
            pass
        hi = "\033[31;1m%s\033[0m" % (search_term)
        for prj, pkg in zip(result[0::2], result[1::2]):
            hipkg = pkg.replace(search_term, hi)
            print "%s/%s" % (prj, hipkg)
            pass
        #    pass
    else:
        print 'No matches found for \'%s\'' % (search_term)
        pass
    
    pass

openSUSE Build Service is sponsored by