aboutsummaryrefslogtreecommitdiff
path: root/src/clients/adjutrix/what_needs_keywording.cc
blob: 2e0a45f7dc8e40df935f76a17483e310fff800dc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/* vim: set sw=4 sts=4 et foldmethod=syntax : */

/*
 * Copyright (c) 2007 Ciaran McCreesh <ciaranm@ciaranm.org>
 *
 * This file is part of the Paludis package manager. Paludis is free software;
 * you can redistribute it and/or modify it under the terms of the GNU General
 * Public License version 2, as published by the Free Software Foundation.
 *
 * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
 * details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
 * Place, Suite 330, Boston, MA  02111-1307  USA
 */

#include "what_needs_keywording.hh"
#include "command_line.hh"

#include <paludis/util/tokeniser.hh>
#include <paludis/util/compare.hh>
#include <paludis/util/strip.hh>
#include <paludis/repositories/gentoo/portage_repository.hh>
#include <paludis/repositories/fake/fake_installed_repository.hh>
#include <paludis/dep_list/exceptions.hh>
#include <paludis/dep_list/dep_list.hh>

#include <set>
#include <map>
#include <list>
#include <iostream>
#include <iomanip>

using namespace paludis;
using std::cout;
using std::cerr;
using std::endl;

int do_what_needs_keywording(NoConfigEnvironment & env)
{
    int return_code(0);

    Context context("When performing what-needs-keywording action:");

    if (env.default_destinations()->empty())
    {
        std::tr1::shared_ptr<Repository> fake_destination(new FakeInstalledRepository(&env,
                    RepositoryName("fake_destination")));
        env.package_database()->add_repository(1, fake_destination);
    }

    KeywordName target_keyword(*CommandLine::get_instance()->begin_parameters());
    UseFlagName target_arch(strip_leading_string(
                *CommandLine::get_instance()->begin_parameters(), "~"));

    env.portage_repository()->set_profile_by_arch(target_arch);
    env.set_accept_unstable('~' == stringify(target_keyword).at(0));

    DepListOptions d_options;
    d_options.circular = dl_circular_discard_silently;
    d_options.use = dl_use_deps_take_all;
    d_options.blocks = dl_blocks_discard_completely;
    d_options.override_masks.set(dl_override_tilde_keywords);
    d_options.override_masks.set(dl_override_unkeyworded);
    d_options.override_masks.set(dl_override_repository_masks);
    d_options.override_masks.set(dl_override_profile_masks);

    DepList d(&env, d_options);

    for (CommandLine::ParametersIterator p(next(CommandLine::get_instance()->begin_parameters())),
            p_end(CommandLine::get_instance()->end_parameters()) ; p != p_end ; ++p)
    {
        if (std::string::npos == p->find('/'))
            d.add(std::tr1::shared_ptr<PackageDepSpec>(new PackageDepSpec(
                            env.package_database()->fetch_unique_qualified_package_name(PackageNamePart(*p)))),
                    env.default_destinations());
        else
            d.add(std::tr1::shared_ptr<PackageDepSpec>(new PackageDepSpec(*p)),
                    env.default_destinations());
    }

    cout << std::setw(30) << std::left << "Package";
    cout << std::setw(20) << std::left << "Version";
    cout << std::setw(18) << std::left << "Current Keywords";
    cout << std::setw(10) << std::left << "Masks";
    cout << endl;

    cout << std::string(29, '=') << " " << std::string(19, '=') << " "
        << std::string(17, '=') << " " << std::string(9, '=') << endl;

    bool none(true);
    for (DepList::Iterator p(d.begin()), p_end(d.end()) ; p != p_end ; ++p)
        if (dlk_masked == p->kind)
        {
            none = false;
            cout << std::setw(30) << std::left << stringify(p->package.name);
            cout << std::setw(20) << std::left << stringify(p->package.version);

            std::string current;

            std::tr1::shared_ptr<const VersionMetadata> m(env.package_database()->fetch_repository(
                        p->package.repository)->version_metadata(p->package.name,
                            p->package.version));
            if (m->ebuild_interface)
            {
                std::set<std::string> keywords;
                WhitespaceTokeniser::get_instance()->tokenise(m->ebuild_interface->keywords,
                        std::inserter(keywords, keywords.end()));
                for (std::set<std::string>::const_iterator k(keywords.begin()), k_end(keywords.end()) ;
                        k != k_end ; ++k)
                    if (*k == "-*"
                            || *k == stringify(target_keyword)
                            || k->substr(1) == stringify(target_arch))
                        current.append(stringify(*k) + " ");
            }

            cout << std::setw(18) << std::left << current;

            std::string masks;

            MaskReasons r(env.mask_reasons(p->package));
            if (r.test(mr_repository_mask))
                    masks.append("R");
            if (r.test(mr_profile_mask))
                    masks.append("P");

            cout << std::setw(10) << std::left << masks;

            cout << endl;
        }

    if (none)
    {
        cerr << "The specified package is already at the target keyword level. Perhaps" << endl;
        cerr << "you need to specify a versioned target ('>=cat/pkg-1.23')." << endl;
        return 4;
    }


    return return_code;
}