diff options
author | 2010-12-31 02:08:00 +0000 | |
---|---|---|
committer | 2011-01-01 03:57:53 +0000 | |
commit | 79da6018d6c02a099af83ecd62e8858ead5f27db (patch) | |
tree | f97a0337777101f8c4a90257397e30196f798b92 /paludis/formatted_pretty_printer.cc | |
parent | 3dd53676acf85d7b3d9758f2def081d20c00b3b9 (diff) | |
download | paludis-79da6018d6c02a099af83ecd62e8858ead5f27db.tar.gz paludis-79da6018d6c02a099af83ecd62e8858ead5f27db.tar.xz |
Use pretty_print_value
Diffstat (limited to 'paludis/formatted_pretty_printer.cc')
-rw-r--r-- | paludis/formatted_pretty_printer.cc | 236 |
1 files changed, 236 insertions, 0 deletions
diff --git a/paludis/formatted_pretty_printer.cc b/paludis/formatted_pretty_printer.cc new file mode 100644 index 000000000..fbea1960a --- /dev/null +++ b/paludis/formatted_pretty_printer.cc @@ -0,0 +1,236 @@ +/* vim: set sw=4 sts=4 et foldmethod=syntax : */ + +/* + * Copyright (c) 2010 Ciaran McCreesh + * + * 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 <paludis/formatted_pretty_printer.hh> +#include <paludis/util/pimp-impl.hh> +#include <paludis/selection.hh> +#include <paludis/generator.hh> +#include <paludis/filtered_generator.hh> +#include <paludis/filter.hh> +#include <paludis/environment.hh> +#include <paludis/package_database.hh> +#include <paludis/metadata_key.hh> +#include <paludis/package_id.hh> + +using namespace paludis; + +namespace paludis +{ + template <> + struct Imp<FormattedPrettyPrinter> + { + const Environment * const env; + const std::shared_ptr<const PackageID> package_id; + + Imp(const Environment * const e, const std::shared_ptr<const PackageID> & i) : + env(e), + package_id(i) + { + } + }; +} + +FormattedPrettyPrinter::FormattedPrettyPrinter( + const Environment * const e, + const std::shared_ptr<const PackageID> & i) : + Pimp<FormattedPrettyPrinter>(e, i) +{ +} + +FormattedPrettyPrinter::~FormattedPrettyPrinter() = default; + +const std::string +FormattedPrettyPrinter::prettify(const PackageDepSpec & v) const +{ + if (_imp->env) + { + { + auto ids((*_imp->env)[selection::SomeArbitraryVersion(generator::Matches(v, { }) | + filter::InstalledAtRoot(_imp->env->preferred_root_key()->value()))]); + if (! ids->empty()) + return format_installed(stringify(v)); + } + { + auto ids((*_imp->env)[selection::SomeArbitraryVersion(generator::Matches(v, { }) | + filter::SupportsAction<InstallAction>() | filter::NotMasked())]); + if (! ids->empty()) + return format_installed(stringify(v)); + } + + return format_masked(stringify(v)); + } + else + return format_plain(stringify(v)); +} + +const std::string +FormattedPrettyPrinter::prettify(const BlockDepSpec & v) const +{ + if (_imp->env) + { + { + auto ids((*_imp->env)[selection::SomeArbitraryVersion(generator::Matches(v.blocking(), { }) | + filter::InstalledAtRoot(_imp->env->preferred_root_key()->value()))]); + if (! ids->empty()) + return format_masked(stringify(v)); + } + + return format_installable(stringify(v)); + } + else + return format_plain(stringify(v)); +} + +const std::string +FormattedPrettyPrinter::prettify(const ConditionalDepSpec & v) const +{ + if (_imp->env && _imp->package_id) + { + if (v.condition_met(_imp->env, _imp->package_id)) + return format_enabled(stringify(v)); + else + return format_disabled(stringify(v)); + } + else + return format_plain(stringify(v)); +} + +const std::string +FormattedPrettyPrinter::prettify(const NamedSetDepSpec & v) const +{ + return format_plain(stringify(v)); +} + +const std::string +FormattedPrettyPrinter::prettify(const SimpleURIDepSpec & v) const +{ + return format_plain(stringify(v)); +} + +const std::string +FormattedPrettyPrinter::prettify(const PlainTextDepSpec & v) const +{ + return format_plain(stringify(v)); +} + +const std::string +FormattedPrettyPrinter::prettify(const LicenseDepSpec & v) const +{ + if (_imp->env && _imp->package_id) + { + if (_imp->env->accept_license(v.text(), _imp->package_id)) + return format_enabled(stringify(v)); + else + return format_disabled(stringify(v)); + } + else + return format_plain(stringify(v)); +} + +const std::string +FormattedPrettyPrinter::prettify(const FetchableURIDepSpec & v) const +{ + return format_plain(stringify(v)); +} + +const std::string +FormattedPrettyPrinter::prettify(const URILabelsDepSpec & v) const +{ + return format_plain(stringify(v)); +} + +const std::string +FormattedPrettyPrinter::prettify(const DependenciesLabelsDepSpec & v) const +{ + return format_plain(stringify(v)); +} + +const std::string +FormattedPrettyPrinter::prettify(const PlainTextLabelDepSpec & v) const +{ + return format_plain(stringify(v)); +} + +const std::string +FormattedPrettyPrinter::prettify(const std::shared_ptr<const PackageID> & v) const +{ + if (_imp->env) + { + auto repo(_imp->env->package_database()->fetch_repository(v->repository_name())); + if (repo->installed_root_key()) + return format_installed(stringify(*v)); + else if (! v->masked()) + return format_installable(stringify(*v)); + else + return format_masked(stringify(*v)); + } + else + return format_plain(stringify(*v)); +} + +const std::string +FormattedPrettyPrinter::prettify(const bool v) const +{ + return format_plain(stringify(v)); +} + +const std::string +FormattedPrettyPrinter::prettify(const long v) const +{ + return format_plain(stringify(v)); +} + +const std::string +FormattedPrettyPrinter::prettify(const std::string & v) const +{ + return format_plain(stringify(v)); +} + +const std::string +FormattedPrettyPrinter::prettify(const std::pair<const std::string, std::string> & v) const +{ + if (v.first.empty()) + return format_plain(v.second); + else + return format_plain(v.first + ": " + v.second); +} + +const std::string +FormattedPrettyPrinter::prettify(const FSPath & v) const +{ + return format_plain(stringify(v)); +} + +const std::string +FormattedPrettyPrinter::prettify(const KeywordName & v) const +{ + if (_imp->env && _imp->package_id) + { + auto k(std::make_shared<KeywordNameSet>()); + k->insert(v); + + if (_imp->env->accept_keywords(k, _imp->package_id)) + return format_enabled(stringify(v)); + else + return format_disabled(stringify(v)); + } + else + return format_plain(stringify(v)); +} + |