aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-07-06 17:27:04 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-07-06 17:27:04 +0000
commit52ccce101356097665123dce14ecde9e65f2181f (patch)
tree182426b67ec75e5ca6cf598453c0ba4ebf2f6a58
parent4af774d445f228bd2dd6e481185e2de74be4ba80 (diff)
downloadpaludis-52ccce101356097665123dce14ecde9e65f2181f.tar.gz
paludis-52ccce101356097665123dce14ecde9e65f2181f.tar.xz
Change how repository information is handled. Add --info support. Update --list-repositories to the new repository information interface.
-rw-r--r--paludis/fake_repository.cc5
-rw-r--r--paludis/nothing_repository.cc11
-rw-r--r--paludis/portage_repository.cc109
-rw-r--r--paludis/portage_repository.hh2
-rw-r--r--paludis/repository.cc28
-rw-r--r--paludis/repository.hh89
-rw-r--r--paludis/vdb_repository.cc14
-rw-r--r--src/command_line.cc1
-rw-r--r--src/command_line.hh3
-rw-r--r--src/list.cc16
-rw-r--r--src/paludis.cc137
11 files changed, 317 insertions, 98 deletions
diff --git a/paludis/fake_repository.cc b/paludis/fake_repository.cc
index 38f5b85..59d4365 100644
--- a/paludis/fake_repository.cc
+++ b/paludis/fake_repository.cc
@@ -83,7 +83,10 @@ FakeRepository::FakeRepository(const RepositoryName & name) :
Repository::UseInterface(),
PrivateImplementationPattern<FakeRepository>(new Implementation<FakeRepository>)
{
- _info.insert(std::make_pair(std::string("format"), std::string("fake")));
+ RepositoryInfoSection config_info("Configuration information");
+ config_info.add_kv("format", "fake");
+
+ _info->add_section(config_info);
}
FakeRepository::~FakeRepository()
diff --git a/paludis/nothing_repository.cc b/paludis/nothing_repository.cc
index 9bfc68b..e776999 100644
--- a/paludis/nothing_repository.cc
+++ b/paludis/nothing_repository.cc
@@ -98,11 +98,12 @@ NothingRepository::NothingRepository(const NothingRepositoryParams & p) try :
))),
PrivateImplementationPattern<NothingRepository>(new Implementation<NothingRepository>(p))
{
- if (! _imp->sync.empty())
- _info.insert(std::make_pair(std::string("sync"), _imp->sync));
- if (! _imp->sync_exclude.empty())
- _info.insert(std::make_pair(std::string("sync_exclude"), _imp->sync_exclude));
- _info.insert(std::make_pair(std::string("location"), stringify(_imp->location)));
+ RepositoryInfoSection config_info("Configuration information");
+ config_info.add_kv("sync", _imp->sync);
+ config_info.add_kv("sync_exclude", _imp->sync_exclude);
+ config_info.add_kv("location", stringify(_imp->location));
+
+ _info->add_section(config_info);
}
catch (const NameError & e)
{
diff --git a/paludis/portage_repository.cc b/paludis/portage_repository.cc
index 24ecdd9..e0cac00 100644
--- a/paludis/portage_repository.cc
+++ b/paludis/portage_repository.cc
@@ -559,24 +559,27 @@ PortageRepository::PortageRepository(const PortageRepositoryParams & p) :
))),
PrivateImplementationPattern<PortageRepository>(new Implementation<PortageRepository>(p))
{
- _info.insert(std::make_pair(std::string("location"), stringify(_imp->location)));
- _info.insert(std::make_pair(std::string("profiles"), join(_imp->profiles->begin(),
- _imp->profiles->end(), " ")));
- _info.insert(std::make_pair(std::string("eclassdirs"), join(_imp->eclassdirs->begin(),
- _imp->eclassdirs->end(), " ")));
- _info.insert(std::make_pair(std::string("cache"), stringify(_imp->cache)));
- _info.insert(std::make_pair(std::string("distdir"), stringify(_imp->distdir)));
- _info.insert(std::make_pair(std::string("securitydir"), stringify(_imp->securitydir)));
- _info.insert(std::make_pair(std::string("setsdir"), stringify(_imp->setsdir)));
- _info.insert(std::make_pair(std::string("newsdir"), stringify(_imp->newsdir)));
- _info.insert(std::make_pair(std::string("format"), std::string("portage")));
- _info.insert(std::make_pair(std::string("root"), stringify(_imp->root)));
- _info.insert(std::make_pair(std::string("buildroot"), stringify(_imp->buildroot)));
- if (! _imp->sync.empty())
- _info.insert(std::make_pair(std::string("sync"), _imp->sync));
- if (! _imp->sync_exclude.empty())
- _info.insert(std::make_pair(std::string("sync_exclude"), _imp->sync_exclude));
-
+ // the info_vars and info_pkgs info is only added on demand, since it's
+ // fairly slow to calculate.
+ RepositoryInfoSection config_info("Configuration information");
+
+ config_info.add_kv("location", stringify(_imp->location));
+ config_info.add_kv("profiles", join(_imp->profiles->begin(),
+ _imp->profiles->end(), " "));
+ config_info.add_kv("eclassdirs", join(_imp->eclassdirs->begin(),
+ _imp->eclassdirs->end(), " "));
+ config_info.add_kv("cache", stringify(_imp->cache));
+ config_info.add_kv("distdir", stringify(_imp->distdir));
+ config_info.add_kv("securitydir", stringify(_imp->securitydir));
+ config_info.add_kv("setsdir", stringify(_imp->setsdir));
+ config_info.add_kv("newsdir", stringify(_imp->newsdir));
+ config_info.add_kv("format", "portage");
+ config_info.add_kv("root", stringify(_imp->root));
+ config_info.add_kv("buildroot", stringify(_imp->buildroot));
+ config_info.add_kv("sync", _imp->sync);
+ config_info.add_kv("sync_exclude", _imp->sync_exclude);
+
+ _info->add_section(config_info);
}
PortageRepository::~PortageRepository()
@@ -2180,3 +2183,73 @@ PortageRepository::get_environment_variable(
return cmd.result();
}
+RepositoryInfo::ConstPointer
+PortageRepository::info(bool verbose) const
+{
+ RepositoryInfo::ConstPointer result_non_verbose(Repository::info(verbose));
+ if (! verbose)
+ return result_non_verbose;
+
+ RepositoryInfo::Pointer result(new RepositoryInfo);
+
+ for (RepositoryInfo::SectionIterator s(result_non_verbose->begin_sections()),
+ s_end(result_non_verbose->end_sections()) ; s != s_end ; ++s)
+ result->add_section(*s);
+
+ std::set<std::string> info_pkgs;
+ if ((_imp->location / "profiles" / "info_pkgs").exists())
+ {
+ LineConfigFile vars(_imp->location / "profiles" / "info_pkgs");
+ info_pkgs.insert(vars.begin(), vars.end());
+ }
+
+ if (! info_pkgs.empty())
+ {
+ RepositoryInfoSection package_info("Package information");
+ for (std::set<std::string>::const_iterator i(info_pkgs.begin()),
+ i_end(info_pkgs.end()) ; i != i_end ; ++i)
+ {
+ PackageDatabaseEntryCollection::ConstPointer q(_imp->env->package_database()->query(
+ PackageDepAtom::ConstPointer(new PackageDepAtom(*i)), is_installed_only));
+ if (q->empty())
+ package_info.add_kv(*i, "(none)");
+ else
+ {
+ std::set<VersionSpec> versions;
+ std::transform(q->begin(), q->end(), std::inserter(versions, versions.end()),
+ std::mem_fun_ref(&PackageDatabaseEntry::get<pde_version>));
+ package_info.add_kv(*i, join(versions.begin(), versions.end(), ", "));
+ }
+ }
+
+ result->add_section(package_info);
+ }
+
+ std::set<std::string> info_vars;
+ if ((_imp->location / "profiles" / "info_vars").exists())
+ {
+ LineConfigFile vars(_imp->location / "profiles" / "info_vars");
+ info_vars.insert(vars.begin(), vars.end());
+ }
+
+ if (! info_vars.empty() && ! info_pkgs.empty() &&
+ ! version_specs(QualifiedPackageName(*info_pkgs.begin()))->empty())
+ {
+ PackageDatabaseEntry e(QualifiedPackageName(*info_pkgs.begin()),
+ *version_specs(QualifiedPackageName(*info_pkgs.begin()))->last(),
+ name());
+ RepositoryInfoSection variable_info("Variable information");
+ for (std::set<std::string>::const_iterator i(info_vars.begin()),
+ i_end(info_vars.end()) ; i != i_end ; ++i)
+ variable_info.add_kv(*i, get_environment_variable(e, *i));
+
+ result->add_section(variable_info);
+ }
+ else if (! info_vars.empty())
+ Log::get_instance()->message(ll_warning, lc_no_context,
+ "Skipping info_vars for '" + stringify(name()) +
+ "' because info_pkgs is not usable");
+
+ return result;
+}
+
diff --git a/paludis/portage_repository.hh b/paludis/portage_repository.hh
index 8401a2d..63d4544 100644
--- a/paludis/portage_repository.hh
+++ b/paludis/portage_repository.hh
@@ -173,6 +173,8 @@ namespace paludis
virtual bool do_sync() const;
public:
+ virtual RepositoryInfo::ConstPointer info(bool verbose) const;
+
/**
* Constructor.
*/
diff --git a/paludis/repository.cc b/paludis/repository.cc
index 8831de1..284249e 100644
--- a/paludis/repository.cc
+++ b/paludis/repository.cc
@@ -31,7 +31,8 @@ Repository::Repository(
const RepositoryName & name,
const RepositoryCapabilities & caps) :
_name(name),
- _caps(caps)
+ _caps(caps),
+ _info(new RepositoryInfo)
{
}
@@ -75,3 +76,28 @@ PackageUninstallActionError::PackageUninstallActionError(const std::string & msg
{
}
+RepositoryInfo &
+RepositoryInfo::add_section(const RepositoryInfoSection & s)
+{
+ _sections.push_back(s);
+ return *this;
+}
+
+RepositoryInfoSection::RepositoryInfoSection(const std::string & heading) :
+ _heading(heading)
+{
+}
+
+RepositoryInfoSection &
+RepositoryInfoSection::add_kv(const std::string & k, const std::string & v)
+{
+ _kvs.insert(std::make_pair(k, v));
+ return *this;
+}
+
+RepositoryInfo::ConstPointer
+Repository::info(bool) const
+{
+ return _info;
+}
+
diff --git a/paludis/repository.hh b/paludis/repository.hh
index fb0b366..f418405 100644
--- a/paludis/repository.hh
+++ b/paludis/repository.hh
@@ -129,6 +129,68 @@ namespace paludis
};
/**
+ * A section of information about a Repository.
+ *
+ * \see RepositoryInfo
+ * \ingroup grprepository
+ */
+ class RepositoryInfoSection
+ {
+ private:
+ std::string _heading;
+ std::map<std::string, std::string> _kvs;
+
+ public:
+ RepositoryInfoSection(const std::string & heading);
+
+ std::string heading() const
+ {
+ return _heading;
+ }
+
+ typedef std::map<std::string, std::string>::const_iterator KeyValueIterator;
+
+ KeyValueIterator begin_kvs() const
+ {
+ return _kvs.begin();
+ }
+
+ KeyValueIterator end_kvs() const
+ {
+ return _kvs.end();
+ }
+
+ RepositoryInfoSection & add_kv(const std::string &, const std::string &);
+ };
+
+ /**
+ * Information about a Repository, for the end user.
+ *
+ * \ingroup grprepository
+ */
+ class RepositoryInfo :
+ public InternalCounted<RepositoryInfo>
+ {
+ private:
+ std::list<RepositoryInfoSection> _sections;
+
+ public:
+ typedef std::list<RepositoryInfoSection>::const_iterator SectionIterator;
+
+ SectionIterator begin_sections() const
+ {
+ return _sections.begin();
+ }
+
+ SectionIterator end_sections() const
+ {
+ return _sections.end();
+ }
+
+ RepositoryInfo & add_section(const RepositoryInfoSection &);
+ };
+
+ /**
* A Repository provides a representation of a physical repository to a
* PackageDatabase.
*
@@ -194,9 +256,9 @@ namespace paludis
protected:
/**
- * Our repository information.
+ * Our information.
*/
- std::map<std::string, std::string> _info;
+ mutable RepositoryInfo::Pointer _info;
/**
* Constructor.
@@ -264,6 +326,8 @@ namespace paludis
///}
public:
+ virtual RepositoryInfo::ConstPointer info(bool verbose) const;
+
///\name Interface queries
///{
@@ -360,27 +424,6 @@ namespace paludis
}
/**
- * Iterator to information about our repository.
- */
- typedef std::map<std::string, std::string>::const_iterator InfoIterator;
-
- /**
- * Start of repository information.
- */
- InfoIterator begin_info() const
- {
- return _info.begin();
- }
-
- /**
- * Past the end of repository information.
- */
- InfoIterator end_info() const
- {
- return _info.end();
- }
-
- /**
* Query whether the specified item is a licence.
*/
bool is_license(const std::string & u) const
diff --git a/paludis/vdb_repository.cc b/paludis/vdb_repository.cc
index ea1384a..396d5d1 100644
--- a/paludis/vdb_repository.cc
+++ b/paludis/vdb_repository.cc
@@ -401,11 +401,15 @@ VDBRepository::VDBRepository(const VDBRepositoryParams & p) :
))),
PrivateImplementationPattern<VDBRepository>(new Implementation<VDBRepository>(p))
{
- _info.insert(std::make_pair(std::string("location"), stringify(_imp->location)));
- _info.insert(std::make_pair(std::string("root"), stringify(_imp->root)));
- _info.insert(std::make_pair(std::string("format"), std::string("vdb")));
- _info.insert(std::make_pair(std::string("world"), stringify(_imp->world_file)));
- _info.insert(std::make_pair(std::string("buildroot"), stringify(_imp->buildroot)));
+ RepositoryInfoSection config_info("Configuration information");
+
+ config_info.add_kv("location", stringify(_imp->location));
+ config_info.add_kv("root", stringify(_imp->root));
+ config_info.add_kv("format", "vdb");
+ config_info.add_kv("world", stringify(_imp->world_file));
+ config_info.add_kv("buildroot", stringify(_imp->buildroot));
+
+ _info->add_section(config_info);
}
VDBRepository::~VDBRepository()
diff --git a/src/command_line.cc b/src/command_line.cc
index 87072a9..db8ad4a 100644
--- a/src/command_line.cc
+++ b/src/command_line.cc
@@ -33,6 +33,7 @@ CommandLine::CommandLine() :
a_contents(&action_args, "contents", 'k', "Display contents of a package"),
a_owner(&action_args, "owner", 'o', "Display the owner of a file"),
a_version(&action_args, "version", 'V', "Display program version"),
+ a_info(&action_args, "info", 'I', "Display program version and system information"),
a_help(&action_args, "help", 'h', "Display program help"),
action_args_internal(this, "More actions (mostly for internal / script use)"),
diff --git a/src/command_line.hh b/src/command_line.hh
index 2d9315e..3609b7d 100644
--- a/src/command_line.hh
+++ b/src/command_line.hh
@@ -80,6 +80,9 @@ class CommandLine :
/// --version
paludis::args::SwitchArg a_version;
+ /// --info
+ paludis::args::SwitchArg a_info;
+
/// --help
paludis::args::SwitchArg a_help;
diff --git a/src/list.cc b/src/list.cc
index d1072b6..40c1efa 100644
--- a/src/list.cc
+++ b/src/list.cc
@@ -52,11 +52,17 @@ do_list_repositories()
std::cout << "* " << colour(cl_package_name, r->name()) << std::endl;
- for (p::Repository::InfoIterator i(r->begin_info()), i_end(r->end_info()) ; i != i_end ; ++i)
- std::cout << " " << std::setw(22) << std::left << (p::stringify(i->first) + ":")
- << std::setw(0) << " " << i->second << std::endl;
-
- std::cout << std::endl;
+ p::RepositoryInfo::ConstPointer ii(r->info(false));
+ for (p::RepositoryInfo::SectionIterator i(ii->begin_sections()),
+ i_end(ii->end_sections()) ; i != i_end ; ++i)
+ {
+ std::cout << " " << colour(cl_heading, i->heading() + ":") << std::endl;
+ for (p::RepositoryInfoSection::KeyValueIterator k(i->begin_kvs()),
+ k_end(i->end_kvs()) ; k != k_end ; ++k)
+ std::cout << " " << std::setw(22) << std::left << (p::stringify(k->first) + ":")
+ << std::setw(0) << " " << k->second << std::endl;
+ std::cout << std::endl;
+ }
}
return ret_code;
diff --git a/src/paludis.cc b/src/paludis.cc
index 2daf286..9069c0e 100644
--- a/src/paludis.cc
+++ b/src/paludis.cc
@@ -34,6 +34,7 @@
#include <paludis/util/util.hh>
#include <iostream>
+#include <iomanip>
#include <string>
#include <cstdlib>
@@ -53,6 +54,71 @@ struct DoVersion
};
#endif
+namespace
+{
+ void display_version()
+ {
+ cout << PALUDIS_PACKAGE << " " << PALUDIS_VERSION_MAJOR << "."
+ << PALUDIS_VERSION_MINOR << "." << PALUDIS_VERSION_MICRO;
+ if (! std::string(PALUDIS_SUBVERSION_REVISION).empty())
+ cout << " svn " << PALUDIS_SUBVERSION_REVISION;
+ cout << endl << endl;
+ cout << "Built by " << PALUDIS_BUILD_USER << "@" << PALUDIS_BUILD_HOST
+ << " on " << PALUDIS_BUILD_DATE << endl;
+ cout << "CXX: " << PALUDIS_BUILD_CXX
+#if defined(__ICC)
+ << " " << __ICC
+#elif defined(__VERSION__)
+ << " " << __VERSION__
+#endif
+ << endl;
+ cout << "CXXFLAGS: " << PALUDIS_BUILD_CXXFLAGS << endl;
+ cout << "LDFLAGS: " << PALUDIS_BUILD_LDFLAGS << endl;
+ cout << "SYSCONFDIR: " << SYSCONFDIR << endl;
+ cout << "LIBEXECDIR: " << LIBEXECDIR << endl;
+ cout << "stdlib: "
+#if defined(__GLIBCXX__)
+# define XSTRINGIFY(x) #x
+# define STRINGIFY(x) XSTRINGIFY(x)
+ << "GNU libstdc++ " << STRINGIFY(__GLIBCXX__)
+#endif
+ << endl;
+
+ cout << "libebt: " << LIBEBT_VERSION_MAJOR << "." << LIBEBT_VERSION_MINOR
+ << "." << LIBEBT_VERSION_MICRO << endl;
+#if HAVE_SANDBOX
+ cout << "sandbox: enabled" << endl;
+#else
+ cout << "sandbox: disabled" << endl;
+#endif
+ }
+
+ void display_info()
+ {
+ p::Environment * const env(p::DefaultEnvironment::get_instance());
+
+ for (p::IndirectIterator<p::PackageDatabase::RepositoryIterator, const p::Repository>
+ r(env->package_database()->begin_repositories()), r_end(env->package_database()->end_repositories()) ;
+ r != r_end ; ++r)
+ {
+ cout << "Repository " << colour(cl_package_name, r->name()) << ":" << endl;
+
+ p::RepositoryInfo::ConstPointer ii(r->info(true));
+ for (p::RepositoryInfo::SectionIterator i(ii->begin_sections()),
+ i_end(ii->end_sections()) ; i != i_end ; ++i)
+ {
+ cout << " " << colour(cl_heading, i->heading() + ":") << endl;
+ for (p::RepositoryInfoSection::KeyValueIterator k(i->begin_kvs()),
+ k_end(i->end_kvs()) ; k != k_end ; ++k)
+ cout << " " << std::setw(22) << std::left << (p::stringify(k->first) + ":")
+ << std::setw(0) << " " << k->second << endl;
+ cout << endl;
+ }
+ }
+
+ }
+}
+
int
main(int argc, char *argv[])
{
@@ -102,6 +168,7 @@ main(int argc, char *argv[])
CommandLine::get_instance()->a_has_version.specified() +
CommandLine::get_instance()->a_update_news.specified() +
CommandLine::get_instance()->a_environment_variable.specified() +
+ CommandLine::get_instance()->a_info.specified() +
CommandLine::get_instance()->a_best_version.specified()))
{
if ((1 == std::distance(CommandLine::get_instance()->begin_parameters(),
@@ -162,15 +229,37 @@ main(int argc, char *argv[])
/* these actions do need DefaultConfig */
- std::string paludis_command(argv[0]);
- if (CommandLine::get_instance()->a_config_suffix.specified())
+ try
+ {
+ std::string paludis_command(argv[0]);
+ if (CommandLine::get_instance()->a_config_suffix.specified())
+ {
+ p::DefaultConfig::set_config_suffix(CommandLine::get_instance()->a_config_suffix.argument());
+ paludis_command.append(" --config-suffix " +
+ CommandLine::get_instance()->a_config_suffix.argument());
+ }
+ paludis_command.append(" --log-level " + CommandLine::get_instance()->a_log_level.argument());
+ p::DefaultConfig::get_instance()->set_paludis_command(paludis_command);
+ }
+ catch (const p::DefaultConfigError & e)
+ {
+ if (CommandLine::get_instance()->a_info.specified())
+ {
+ display_version();
+ cout << endl;
+ cout << "Cannot complete --info output due to configuration exception" << endl;
+ }
+ throw;
+ }
+
+ if (CommandLine::get_instance()->a_info.specified())
{
- p::DefaultConfig::set_config_suffix(CommandLine::get_instance()->a_config_suffix.argument());
- paludis_command.append(" --config-suffix " +
- CommandLine::get_instance()->a_config_suffix.argument());
+ display_version();
+ cout << endl;
+ display_info();
+ cout << endl;
+ return EXIT_SUCCESS;
}
- paludis_command.append(" --log-level " + CommandLine::get_instance()->a_log_level.argument());
- p::DefaultConfig::get_instance()->set_paludis_command(paludis_command);
if (CommandLine::get_instance()->a_query.specified())
{
@@ -280,39 +369,7 @@ main(int argc, char *argv[])
}
catch (const DoVersion &)
{
- cout << PALUDIS_PACKAGE << " " << PALUDIS_VERSION_MAJOR << "."
- << PALUDIS_VERSION_MINOR << "." << PALUDIS_VERSION_MICRO;
- if (! std::string(PALUDIS_SUBVERSION_REVISION).empty())
- cout << " svn " << PALUDIS_SUBVERSION_REVISION;
- cout << endl << endl;
- cout << "Built by " << PALUDIS_BUILD_USER << "@" << PALUDIS_BUILD_HOST
- << " on " << PALUDIS_BUILD_DATE << endl;
- cout << "CXX: " << PALUDIS_BUILD_CXX
-#if defined(__ICC)
- << " " << __ICC
-#elif defined(__VERSION__)
- << " " << __VERSION__
-#endif
- << endl;
- cout << "CXXFLAGS: " << PALUDIS_BUILD_CXXFLAGS << endl;
- cout << "LDFLAGS: " << PALUDIS_BUILD_LDFLAGS << endl;
- cout << "SYSCONFDIR: " << SYSCONFDIR << endl;
- cout << "LIBEXECDIR: " << LIBEXECDIR << endl;
- cout << "stdlib: "
-#if defined(__GLIBCXX__)
-# define XSTRINGIFY(x) #x
-# define STRINGIFY(x) XSTRINGIFY(x)
- << "GNU libstdc++ " << STRINGIFY(__GLIBCXX__)
-#endif
- << endl;
-
- cout << "libebt: " << LIBEBT_VERSION_MAJOR << "." << LIBEBT_VERSION_MINOR
- << "." << LIBEBT_VERSION_MICRO << endl;
-#if HAVE_SANDBOX
- cout << "sandbox: enabled" << endl;
-#else
- cout << "sandbox: disabled" << endl;
-#endif
+ display_version();
cout << endl;
cout << "Paludis comes with ABSOLUTELY NO WARRANTY. Paludis is free software, and you" << endl;
cout << "are welcome to redistribute it under the terms of the GNU General Public" << endl;