aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2009-02-12 16:38:20 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2009-02-12 16:38:20 +0000
commit234d67465e0aae7b1e2e34c8c520609c6bd80789 (patch)
tree1f90f2deefd40db6d5ec612d540676976deade61
parentdae574c8eeadfbb35a7d8369197fdde2ea61d017 (diff)
downloadpaludis-234d67465e0aae7b1e2e34c8c520609c6bd80789.tar.gz
paludis-234d67465e0aae7b1e2e34c8c520609c6bd80789.tar.xz
Make file output manager more useful
-rw-r--r--paludis/environments/paludis/Makefile.am1
-rw-r--r--paludis/environments/paludis/action_to_string.cc77
-rw-r--r--paludis/environments/paludis/action_to_string.hh34
-rw-r--r--paludis/environments/paludis/output_conf.cc50
-rw-r--r--paludis/environments/paludis/output_managers.cc94
-rw-r--r--paludis/file_output_manager.cc9
6 files changed, 213 insertions, 52 deletions
diff --git a/paludis/environments/paludis/Makefile.am b/paludis/environments/paludis/Makefile.am
index 31f16a8..0798a66 100644
--- a/paludis/environments/paludis/Makefile.am
+++ b/paludis/environments/paludis/Makefile.am
@@ -11,6 +11,7 @@ DEFS= \
-DSHAREDIR=\"$(sharedir)\"
libpaludispaludisenvironment_@PALUDIS_PC_SLOT@_la_SOURCES = \
+ action_to_string.cc action_to_string.hh \
bashable_conf.cc bashable_conf.hh \
keywords_conf.cc keywords_conf.hh \
licenses_conf.cc licenses_conf.hh \
diff --git a/paludis/environments/paludis/action_to_string.cc b/paludis/environments/paludis/action_to_string.cc
new file mode 100644
index 0000000..2058c5d
--- /dev/null
+++ b/paludis/environments/paludis/action_to_string.cc
@@ -0,0 +1,77 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2009 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/environments/paludis/action_to_string.hh>
+#include <paludis/action.hh>
+
+using namespace paludis;
+
+namespace
+{
+ struct ActionToString
+ {
+ std::string visit(const InstallAction &) const
+ {
+ return "install";
+ }
+
+ std::string visit(const PretendFetchAction &) const
+ {
+ return "pretend-fetch";
+ }
+
+ std::string visit(const UninstallAction &) const
+ {
+ return "uninstall";
+ }
+
+ std::string visit(const FetchAction &) const
+ {
+ return "fetch";
+ }
+
+ std::string visit(const PretendAction &) const
+ {
+ return "pretend";
+ }
+
+ std::string visit(const InfoAction &) const
+ {
+ return "info";
+ }
+
+ std::string visit(const ConfigAction &) const
+ {
+ return "config";
+ }
+
+ std::string visit(const InstalledAction &) const
+ {
+ return "installed";
+ }
+ };
+}
+
+const std::string
+paludis::paludis_environment::action_to_string(const Action & a)
+{
+ ActionToString v;
+ return a.accept_returning<std::string>(v);
+}
+
diff --git a/paludis/environments/paludis/action_to_string.hh b/paludis/environments/paludis/action_to_string.hh
new file mode 100644
index 0000000..a2049ef
--- /dev/null
+++ b/paludis/environments/paludis/action_to_string.hh
@@ -0,0 +1,34 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2009 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
+ */
+
+#ifndef PALUDIS_GUARD_PALUDIS_ENVIRONMENTS_PALUDIS_ACTION_TO_STRING_HH
+#define PALUDIS_GUARD_PALUDIS_ENVIRONMENTS_PALUDIS_ACTION_TO_STRING_HH 1
+
+#include <string>
+#include <paludis/action-fwd.hh>
+
+namespace paludis
+{
+ namespace paludis_environment
+ {
+ const std::string action_to_string(const Action & a);
+ }
+}
+
+#endif
diff --git a/paludis/environments/paludis/output_conf.cc b/paludis/environments/paludis/output_conf.cc
index 4ba7ae9..feee537 100644
--- a/paludis/environments/paludis/output_conf.cc
+++ b/paludis/environments/paludis/output_conf.cc
@@ -21,6 +21,7 @@
#include <paludis/environments/paludis/bashable_conf.hh>
#include <paludis/environments/paludis/paludis_config.hh>
#include <paludis/environments/paludis/paludis_environment.hh>
+#include <paludis/environments/paludis/action_to_string.hh>
#include <paludis/util/log.hh>
#include <paludis/util/private_implementation_pattern-impl.hh>
#include <paludis/util/tokeniser.hh>
@@ -113,55 +114,6 @@ namespace
throw PaludisConfigError("Unknown rule '" + k + "'");
}
- struct ActionToString
- {
- std::string visit(const InstallAction &) const
- {
- return "install";
- }
-
- std::string visit(const PretendFetchAction &) const
- {
- return "pretend-fetch";
- }
-
- std::string visit(const UninstallAction &) const
- {
- return "uninstall";
- }
-
- std::string visit(const FetchAction &) const
- {
- return "fetch";
- }
-
- std::string visit(const PretendAction &) const
- {
- return "pretend";
- }
-
- std::string visit(const InfoAction &) const
- {
- return "info";
- }
-
- std::string visit(const ConfigAction &) const
- {
- return "config";
- }
-
- std::string visit(const InstalledAction &) const
- {
- return "installed";
- }
- };
-
- std::string action_to_string(const Action & a)
- {
- ActionToString v;
- return a.accept_returning<std::string>(v);
- }
-
struct MatchRuleVisitor
{
const Environment * const env;
diff --git a/paludis/environments/paludis/output_managers.cc b/paludis/environments/paludis/output_managers.cc
index 9df4432..56563d5 100644
--- a/paludis/environments/paludis/output_managers.cc
+++ b/paludis/environments/paludis/output_managers.cc
@@ -21,13 +21,22 @@
#include <paludis/environments/paludis/bashable_conf.hh>
#include <paludis/environments/paludis/paludis_config.hh>
#include <paludis/environments/paludis/paludis_environment.hh>
+#include <paludis/environments/paludis/action_to_string.hh>
#include <paludis/util/private_implementation_pattern-impl.hh>
#include <paludis/util/config_file.hh>
#include <paludis/util/wrapped_forward_iterator.hh>
#include <paludis/util/map.hh>
#include <paludis/util/strip.hh>
+#include <paludis/util/simple_parser.hh>
#include <paludis/output_manager_factory.hh>
+#include <paludis/create_output_manager_info.hh>
+#include <paludis/package_id.hh>
+#include <paludis/metadata_key.hh>
+#include <algorithm>
#include <tr1/unordered_map>
+#include <sys/types.h>
+#include <unistd.h>
+#include <time.h>
using namespace paludis;
using namespace paludis::paludis_environment;
@@ -93,14 +102,93 @@ OutputManagers::create_named_output_manager(const std::string & s, const CreateO
);
}
+namespace
+{
+ std::string escape(const std::string & s)
+ {
+ std::string result(s);
+ std::replace(result.begin(), result.end(), ' ', '_');
+ std::replace(result.begin(), result.end(), '/', '_');
+ return result;
+ }
+
+ struct CreateVarsFromInfo
+ {
+ std::tr1::unordered_map<std::string, std::string> & m;
+
+ CreateVarsFromInfo(std::tr1::unordered_map<std::string, std::string> & mm) :
+ m(mm)
+ {
+ }
+
+ void visit(const CreateOutputManagerForRepositorySyncInfo & i)
+ {
+ m["type"] = "repository";
+ m["action"] = "sync";
+ m["name"] = stringify(i.repository().name());
+ m["pid"] = stringify(getpid());
+ m["time"] = stringify(time(0));
+ }
+
+ void visit(const CreateOutputManagerForPackageIDActionInfo & i)
+ {
+ m["type"] = "package";
+ m["action"] = action_to_string(i.action());
+ m["name"] = stringify(i.package_id()->name());
+ m["id"] = escape(stringify(*i.package_id()));
+ if (i.package_id()->slot_key())
+ m["slot"] = stringify(i.package_id()->slot_key()->value());
+ m["version"] = stringify(i.package_id()->version());
+ m["repository"] = stringify(i.package_id()->repository()->name());
+ m["category"] = stringify(i.package_id()->name().category());
+ m["package"] = stringify(i.package_id()->name().package());
+ m["pid"] = stringify(getpid());
+ m["time"] = stringify(time(0));
+ }
+ };
+
+ void create_vars_from_info(const CreateOutputManagerInfo & i,
+ std::tr1::unordered_map<std::string, std::string> & m)
+ {
+ CreateVarsFromInfo v(m);
+ i.accept(v);
+ }
+}
+
std::string
OutputManagers::replace_vars(
const std::string & s,
- const CreateOutputManagerInfo &) const
+ const CreateOutputManagerInfo & i) const
{
- return s;
+ Context context("When expanding variables in '" + s + "':");
+
+ SimpleParser parser(s);
+ std::string result, token;
+ std::tr1::unordered_map<std::string, std::string> m;
+ create_vars_from_info(i, m);
+
+ while (! parser.eof())
+ {
+ if (parser.consume((+simple_parser::any_except("%")) >> token))
+ result.append(token);
+ else if (parser.consume(simple_parser::exact("%%")))
+ result.append("%");
+ else if (parser.consume(simple_parser::exact("%{") &
+ ((+simple_parser::any_except("} \t\r\n%")) >> token) &
+ simple_parser::exact("}")))
+ {
+ std::tr1::unordered_map<std::string, std::string>::const_iterator j(m.find(token));
+ if (j == m.end())
+ throw PaludisConfigError("No variable named '" + token + "' in var string '" + s + "'");
+ else
+ result.append(j->second);
+ }
+ else
+ throw PaludisConfigError("Invalid var string '" + s + "'");
+ }
+
+ return result;
}
template class PrivateImplementationPattern<paludis_environment::OutputManagers>;
-
diff --git a/paludis/file_output_manager.cc b/paludis/file_output_manager.cc
index 3eae2d1..8b5aeb3 100644
--- a/paludis/file_output_manager.cc
+++ b/paludis/file_output_manager.cc
@@ -33,6 +33,8 @@ namespace paludis
template <>
struct Implementation<FileOutputManager>
{
+ FSEntry stdout_file;
+ FSEntry stderr_file;
std::tr1::shared_ptr<SafeOFStream> stdout_stream;
std::tr1::shared_ptr<SafeOFStream> stderr_stream;
const bool keep_on_success;
@@ -42,6 +44,8 @@ namespace paludis
const FSEntry & e,
const bool k
) :
+ stdout_file(o),
+ stderr_file(e),
stdout_stream(new SafeOFStream(o)),
keep_on_success(k)
{
@@ -77,6 +81,11 @@ FileOutputManager::stderr_stream()
void
FileOutputManager::succeeded()
{
+ if (! _imp->keep_on_success)
+ {
+ _imp->stdout_file.unlink();
+ _imp->stderr_file.unlink();
+ }
}
void