aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-04-03 22:59:38 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-04-03 22:59:38 +0000
commitf1b17a783b5a1094ff1baad368b17e34ab5cb706 (patch)
tree8ac7c334d612dd30dd3628b2e14b9ada40e422e9
parentb6f74117d4190c9c309d02410e230a187d0ea4c8 (diff)
downloadpaludis-f1b17a783b5a1094ff1baad368b17e34ab5cb706.tar.gz
paludis-f1b17a783b5a1094ff1baad368b17e34ab5cb706.tar.xz
has_version, best_version
-rw-r--r--ebuild/portage_stubs.bash15
-rw-r--r--src/Makefile.am1
-rw-r--r--src/applets.cc70
-rw-r--r--src/applets.hh36
-rw-r--r--src/command_line.cc2
-rw-r--r--src/command_line.hh6
-rw-r--r--src/paludis.cc23
7 files changed, 149 insertions, 4 deletions
diff --git a/ebuild/portage_stubs.bash b/ebuild/portage_stubs.bash
index b7f7303..6d74d7b 100644
--- a/ebuild/portage_stubs.bash
+++ b/ebuild/portage_stubs.bash
@@ -23,12 +23,13 @@
has_version()
{
-# die "has_version not implemented"
- false
+ # \todo Don't hardcode paludis, config dirs etc
+ paludis --has-version "$@"
}
portageq()
{
+ # \todo Make this suck less...
if [[ "$1" == "has_version" ]] ; then
if [[ "$2" != "$ROOT" ]] ; then
die "portageq has_version emulation only works on current ROOT"
@@ -36,6 +37,13 @@ portageq()
shift ; shift
has_version "$@"
fi
+ elif [[ "$1" == "best_version" ]] ; then
+ if [[ "$2" != "$ROOT" ]] ; then
+ die "portageq best_version emulation only works on current ROOT"
+ else
+ shift ; shift
+ best_version "$@"
+ fi
else
die "portageq emulation for $1 not implemented"
fi
@@ -43,7 +51,8 @@ portageq()
best_version()
{
- die "best_version not implemented"
+ # \todo Don't hardcode paludis, config dirs etc
+ paludis --best-version "$@"
}
check_KV()
diff --git a/src/Makefile.am b/src/Makefile.am
index b846da5..381580d 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -10,6 +10,7 @@ SUBDIRS = . qualudis
bin_PROGRAMS = paludis
paludis_SOURCES = \
+ applets.hh applets.cc \
command_line.hh command_line.cc \
colour.hh colour.cc \
install.hh install.cc \
diff --git a/src/applets.cc b/src/applets.cc
new file mode 100644
index 0000000..be395f3
--- /dev/null
+++ b/src/applets.cc
@@ -0,0 +1,70 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2006 Ciaran McCreesh <ciaranm@gentoo.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 "src/applets.hh"
+#include <functional>
+#include <iomanip>
+#include <iostream>
+#include <paludis/paludis.hh>
+#include <string>
+
+/** \file
+ * Handle the --has-version and --best-version actions for the main paludis
+ * program.
+ */
+
+namespace p = paludis;
+
+int do_has_version()
+{
+ int return_code(0);
+
+ p::Context context("When performing has-version action from command line:");
+ p::Environment * const env(p::DefaultEnvironment::get_instance());
+
+ std::string query(*CommandLine::get_instance()->begin_parameters());
+ p::PackageDepAtom::Pointer atom(new p::PackageDepAtom(query));
+ p::PackageDatabaseEntryCollection::ConstPointer entries(env->package_database()->query(
+ atom, p::is_installed_only));
+ if (entries->empty())
+ return_code = 1;
+
+ return return_code;
+}
+
+int do_best_version()
+{
+ int return_code(0);
+
+ p::Context context("When performing best-version action from command line:");
+ p::Environment * const env(p::DefaultEnvironment::get_instance());
+
+ std::string query(*CommandLine::get_instance()->begin_parameters());
+ p::PackageDepAtom::Pointer atom(new p::PackageDepAtom(query));
+ p::PackageDatabaseEntryCollection::ConstPointer entries(env->package_database()->query(
+ atom, p::is_installed_only));
+ if (entries->empty())
+ return_code = 1;
+ else
+ std::cout << *(entries->last()) << std::endl;
+
+ return return_code;
+}
+
+
diff --git a/src/applets.hh b/src/applets.hh
new file mode 100644
index 0000000..442a2d4
--- /dev/null
+++ b/src/applets.hh
@@ -0,0 +1,36 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2006 Ciaran McCreesh <ciaranm@gentoo.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
+ */
+
+#ifndef PALUDIS_GUARD_SRC_APPLETS_HH
+#define PALUDIS_GUARD_SRC_APPLETS_HH 1
+
+#include "src/command_line.hh"
+
+/** \file
+ * Declaration for the do_has_version and do_best_version functions.
+ */
+
+/// Handle --has-version.
+int do_has_version();
+
+/// Handle --best-version.
+int do_best_version();
+
+#endif
+
diff --git a/src/command_line.cc b/src/command_line.cc
index 9231f08..6065afb 100644
--- a/src/command_line.cc
+++ b/src/command_line.cc
@@ -28,6 +28,8 @@ CommandLine::CommandLine() :
a_list_repositories(&action_args, "list-repositories", '\0', "List available repositories"),
a_list_categories(&action_args, "list-categories", '\0', "List available categories"),
a_list_packages(&action_args, "list-packages", '\0', "List available packages"),
+ a_has_version(&action_args, "has-version", '\0', "Check whether the specified atom is installed"),
+ a_best_version(&action_args, "best-version", '\0', "Display the best version of the specified atom"),
a_version(&action_args, "version", 'V', "Display program version"),
a_help(&action_args, "help", 'h', "Display program help"),
diff --git a/src/command_line.hh b/src/command_line.hh
index 70c19d9..a047e20 100644
--- a/src/command_line.hh
+++ b/src/command_line.hh
@@ -65,6 +65,12 @@ class CommandLine :
/// --list-packages
paludis::args::SwitchArg a_list_packages;
+ /// --has-version
+ paludis::args::SwitchArg a_has_version;
+
+ /// --best-version
+ paludis::args::SwitchArg a_best_version;
+
/// --version
paludis::args::SwitchArg a_version;
diff --git a/src/paludis.cc b/src/paludis.cc
index 303bf09..75e1407 100644
--- a/src/paludis.cc
+++ b/src/paludis.cc
@@ -21,6 +21,7 @@
#include "src/install.hh"
#include "src/list.hh"
#include "src/query.hh"
+#include "src/applets.hh"
#include <paludis/paludis.hh>
#include <paludis/util/util.hh>
@@ -86,7 +87,9 @@ main(int argc, char *argv[])
CommandLine::get_instance()->a_install.specified() +
CommandLine::get_instance()->a_list_repositories.specified() +
CommandLine::get_instance()->a_list_categories.specified() +
- CommandLine::get_instance()->a_list_packages.specified()))
+ CommandLine::get_instance()->a_list_packages.specified() +
+ CommandLine::get_instance()->a_has_version.specified() +
+ CommandLine::get_instance()->a_best_version.specified()))
throw DoHelp("you should specify exactly one action");
if (CommandLine::get_instance()->a_version.specified())
@@ -132,6 +135,24 @@ main(int argc, char *argv[])
return do_list_packages();
}
+ if (CommandLine::get_instance()->a_has_version.specified())
+ {
+ if (1 != std::distance(CommandLine::get_instance()->begin_parameters(),
+ CommandLine::get_instance()->end_parameters()))
+ throw DoHelp("has-version action takes exactly one parameter");
+
+ return do_has_version();
+ }
+
+ if (CommandLine::get_instance()->a_best_version.specified())
+ {
+ if (1 != std::distance(CommandLine::get_instance()->begin_parameters(),
+ CommandLine::get_instance()->end_parameters()))
+ throw DoHelp("best-version action takes exactly one parameter");
+
+ return do_best_version();
+ }
+
throw p::InternalError(__PRETTY_FUNCTION__, "no action?");
}
catch (const DoVersion &)