예제 #1
0
def LoadByPackage(parent, query):
    """Offer list of ebuilds when given a package or filename on command line"""

    #TODO: This was all snarfed from an old version of etcat, which was split
    #      off into gentoolkit.py
    matches = gentoolkit.find_packages(query, masked=True)
    matches = gentoolkit.sort_package_list(matches)
    #if len(matches) > 1:
    #    print "More than one package matches that name. Use full category/packagename."
    #for pkg in matches:
    #    print pkg.get_category()+"/"+pkg.get_name()
    #return
    if len(matches):
        cat = matches[0].get_category()
        package = matches[0].get_name()
        pkgs = []

        #print "* " + matches[0].get_category()+"/"+matches[0].get_name()+ " :"
        for pkg in matches:

            state = []
            unstable = 0
            overlay = ""

            # check if masked
            if pkg.is_masked():
                state.append("M")
            else:
                state.append(" ")

            # check if in unstable
            kwd = pkg.get_env_var("KEYWORDS")
            if "~" + gentoolkit.settings["ARCH"] in kwd.split():
                state.append("~")
                unstable = 1
            else:
                state.append(" ")

            # check if installed
            if pkg.is_installed():
                state.append("I")
            else:
                state.append(" ")

            # check if this is a OVERLAY ebuild
            if pkg.is_overlay():
                overlay = " OVERLAY"

            ver = pkg.get_version()
            slot = pkg.get_env_var("SLOT")
            #print " "*8 + "[" + string.join(state,"") + "] " + ver + " (" + slot + ")" + overlay
            pkgs.append(ver + " (" + slot + ")" + overlay)

        dlg = wx.SingleChoiceDialog(parent, cat + "/" + package,
                                    'Ebuilds Available', pkgs,
                                    wx.OK | wx.CANCEL)
        if dlg.ShowModal() == wx.ID_OK:
            s = dlg.GetStringSelection().split(' ')
            version = s[0]

            if len(s) == 3:
                fname = '%s/%s/%s/%s-%s.ebuild' % \
                        (portdir_overlay, cat, package, package, version)
            else:
                fname = '%s/%s/%s/%s-%s.ebuild' % \
                        (portdir, cat, package, package, version)
            LoadEbuild(parent, fname)
    else:
        print "Package " + query + " not found. Use full category/package name."