aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2009-02-12 12:57:51 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2009-02-12 12:57:51 +0000
commitd7e855600a8cf683ce9dfa9ff934270bb558c5db (patch)
treecd040b1ce91f14644cff38c5dd0109cb430635a2
parent9ed5246bdfa77faa81539a34f42823036e891b87 (diff)
downloadpaludis-d7e855600a8cf683ce9dfa9ff934270bb558c5db.tar.gz
paludis-d7e855600a8cf683ce9dfa9ff934270bb558c5db.tar.xz
Add file output manager
-rw-r--r--paludis/environments/paludis/output_conf.cc2
-rw-r--r--paludis/environments/paludis/output_managers.cc13
-rw-r--r--paludis/environments/paludis/output_managers.hh9
-rw-r--r--paludis/environments/paludis/paludis_environment.cc4
-rw-r--r--paludis/environments/paludis/paludis_environment.hh4
-rw-r--r--paludis/file_output_manager-fwd.hh28
-rw-r--r--paludis/file_output_manager.cc118
-rw-r--r--paludis/file_output_manager.hh63
-rw-r--r--paludis/files.m41
-rw-r--r--paludis/output_manager_factory.cc7
-rw-r--r--paludis/output_manager_factory.hh14
-rw-r--r--paludis/standard_output_manager.cc4
-rw-r--r--paludis/standard_output_manager.hh3
-rw-r--r--paludis/tee_output_manager.cc3
-rw-r--r--paludis/tee_output_manager.hh3
15 files changed, 260 insertions, 16 deletions
diff --git a/paludis/environments/paludis/output_conf.cc b/paludis/environments/paludis/output_conf.cc
index bcef89f..4ba7ae9 100644
--- a/paludis/environments/paludis/output_conf.cc
+++ b/paludis/environments/paludis/output_conf.cc
@@ -308,7 +308,7 @@ OutputConf::create_output_manager(const CreateOutputManagerInfo & i) const
for (RuleList::const_reverse_iterator r(_imp->rules.rbegin()), r_end(_imp->rules.rend()) ;
r != r_end ; ++r)
if (match_rule(_imp->env, *r, i))
- return _imp->env->create_named_output_manager(r->manager());
+ return _imp->env->create_named_output_manager(r->manager(), i);
throw PaludisConfigError("No matching output manager rule specified");
}
diff --git a/paludis/environments/paludis/output_managers.cc b/paludis/environments/paludis/output_managers.cc
index b5d29d8..9df4432 100644
--- a/paludis/environments/paludis/output_managers.cc
+++ b/paludis/environments/paludis/output_managers.cc
@@ -78,7 +78,7 @@ OutputManagers::add(const FSEntry & filename)
}
const std::tr1::shared_ptr<OutputManager>
-OutputManagers::create_named_output_manager(const std::string & s) const
+OutputManagers::create_named_output_manager(const std::string & s, const CreateOutputManagerInfo & n) const
{
Context context("When creating output manager named '" + s + "':");
@@ -88,10 +88,19 @@ OutputManagers::create_named_output_manager(const std::string & s) const
return OutputManagerFactory::get_instance()->create(
std::tr1::bind(&from_kv, i->second, std::tr1::placeholders::_1),
- std::tr1::bind(&OutputManagers::create_named_output_manager, this, std::tr1::placeholders::_1)
+ std::tr1::bind(&OutputManagers::create_named_output_manager, this, std::tr1::placeholders::_1, std::tr1::cref(n)),
+ std::tr1::bind(&OutputManagers::replace_vars, this, std::tr1::placeholders::_1, std::tr1::cref(n))
);
}
+std::string
+OutputManagers::replace_vars(
+ const std::string & s,
+ const CreateOutputManagerInfo &) const
+{
+ return s;
+}
+
template class PrivateImplementationPattern<paludis_environment::OutputManagers>;
diff --git a/paludis/environments/paludis/output_managers.hh b/paludis/environments/paludis/output_managers.hh
index ff69c6b..1061665 100644
--- a/paludis/environments/paludis/output_managers.hh
+++ b/paludis/environments/paludis/output_managers.hh
@@ -25,6 +25,7 @@
#include <paludis/util/instantiation_policy.hh>
#include <paludis/util/fs_entry-fwd.hh>
#include <paludis/output_manager-fwd.hh>
+#include <paludis/create_output_manager_info-fwd.hh>
#include <tr1/memory>
namespace paludis
@@ -51,7 +52,13 @@ namespace paludis
*/
void add(const FSEntry &);
- const std::tr1::shared_ptr<OutputManager> create_named_output_manager(const std::string &) const;
+ const std::tr1::shared_ptr<OutputManager> create_named_output_manager(
+ const std::string &,
+ const CreateOutputManagerInfo &) const;
+
+ std::string replace_vars(
+ const std::string &,
+ const CreateOutputManagerInfo &) const;
};
}
diff --git a/paludis/environments/paludis/paludis_environment.cc b/paludis/environments/paludis/paludis_environment.cc
index 36b2dcb..95fc295 100644
--- a/paludis/environments/paludis/paludis_environment.cc
+++ b/paludis/environments/paludis/paludis_environment.cc
@@ -560,8 +560,8 @@ PaludisEnvironment::create_output_manager(const CreateOutputManagerInfo & i) con
}
const std::tr1::shared_ptr<OutputManager>
-PaludisEnvironment::create_named_output_manager(const std::string & s) const
+PaludisEnvironment::create_named_output_manager(const std::string & s, const CreateOutputManagerInfo & i) const
{
- return _imp->config->output_managers()->create_named_output_manager(s);
+ return _imp->config->output_managers()->create_named_output_manager(s, i);
}
diff --git a/paludis/environments/paludis/paludis_environment.hh b/paludis/environments/paludis/paludis_environment.hh
index 2eb79f3..70b45e8 100644
--- a/paludis/environments/paludis/paludis_environment.hh
+++ b/paludis/environments/paludis/paludis_environment.hh
@@ -166,7 +166,9 @@ namespace paludis
virtual const std::tr1::shared_ptr<OutputManager> create_output_manager(
const CreateOutputManagerInfo &) const;
- const std::tr1::shared_ptr<OutputManager> create_named_output_manager(const std::string &) const;
+ const std::tr1::shared_ptr<OutputManager> create_named_output_manager(
+ const std::string &,
+ const CreateOutputManagerInfo &) const;
};
}
#endif
diff --git a/paludis/file_output_manager-fwd.hh b/paludis/file_output_manager-fwd.hh
new file mode 100644
index 0000000..007ad64
--- /dev/null
+++ b/paludis/file_output_manager-fwd.hh
@@ -0,0 +1,28 @@
+/* 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_FILE_OUTPUT_MANAGER_FWD_HH
+#define PALUDIS_GUARD_PALUDIS_FILE_OUTPUT_MANAGER_FWD_HH 1
+
+namespace paludis
+{
+ class FileOutputManager;
+}
+
+#endif
diff --git a/paludis/file_output_manager.cc b/paludis/file_output_manager.cc
new file mode 100644
index 0000000..3eae2d1
--- /dev/null
+++ b/paludis/file_output_manager.cc
@@ -0,0 +1,118 @@
+/* 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/file_output_manager.hh>
+#include <paludis/util/private_implementation_pattern-impl.hh>
+#include <paludis/util/safe_ofstream.hh>
+#include <paludis/util/set.hh>
+#include <paludis/util/wrapped_forward_iterator.hh>
+#include <paludis/util/make_shared_ptr.hh>
+#include <paludis/util/destringify.hh>
+#include <paludis/util/fs_entry.hh>
+
+using namespace paludis;
+
+namespace paludis
+{
+ template <>
+ struct Implementation<FileOutputManager>
+ {
+ std::tr1::shared_ptr<SafeOFStream> stdout_stream;
+ std::tr1::shared_ptr<SafeOFStream> stderr_stream;
+ const bool keep_on_success;
+
+ Implementation(
+ const FSEntry & o,
+ const FSEntry & e,
+ const bool k
+ ) :
+ stdout_stream(new SafeOFStream(o)),
+ keep_on_success(k)
+ {
+ if (o == e)
+ stderr_stream = stdout_stream;
+ else
+ stderr_stream.reset(new SafeOFStream(e));
+ }
+ };
+}
+
+FileOutputManager::FileOutputManager(const FSEntry & o, const FSEntry & e, const bool k) :
+ PrivateImplementationPattern<FileOutputManager>(new Implementation<FileOutputManager>(o, e, k))
+{
+}
+
+FileOutputManager::~FileOutputManager()
+{
+}
+
+std::ostream &
+FileOutputManager::stdout_stream()
+{
+ return *_imp->stdout_stream;
+}
+
+std::ostream &
+FileOutputManager::stderr_stream()
+{
+ return *_imp->stderr_stream;
+}
+
+void
+FileOutputManager::succeeded()
+{
+}
+
+void
+FileOutputManager::message(const MessageType, const std::string &)
+{
+}
+
+const std::tr1::shared_ptr<const Set<std::string> >
+FileOutputManager::factory_managers()
+{
+ std::tr1::shared_ptr<Set<std::string> > result(new Set<std::string>);
+ result->insert("file");
+ return result;
+}
+
+const std::tr1::shared_ptr<OutputManager>
+FileOutputManager::factory_create(
+ const OutputManagerFactory::KeyFunction & key_func,
+ const OutputManagerFactory::CreateChildFunction &,
+ const OutputManagerFactory::ReplaceVarsFunc & replace_vars_func)
+{
+ std::string o_s(key_func("stdout")), e_s(key_func("stderr")), k_s(key_func("keep_on_success"));
+
+ if (o_s.empty())
+ throw ConfigurationError("Key 'stdout' not specified when creating a file output manager");
+ o_s = replace_vars_func(o_s);
+
+ if (e_s.empty())
+ throw ConfigurationError("Key 'stderr' not specified when creating a file output manager");
+ e_s = replace_vars_func(e_s);
+
+ if (k_s.empty())
+ throw ConfigurationError("Key 'keep_on_success' not specified when creating a file output manager");
+
+ return make_shared_ptr(new FileOutputManager(FSEntry(o_s), FSEntry(e_s), destringify<bool>(k_s)));
+}
+
+template class PrivateImplementationPattern<FileOutputManager>;
+
diff --git a/paludis/file_output_manager.hh b/paludis/file_output_manager.hh
new file mode 100644
index 0000000..e8ffa8c
--- /dev/null
+++ b/paludis/file_output_manager.hh
@@ -0,0 +1,63 @@
+/* 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_FILE_OUTPUT_MANAGER_HH
+#define PALUDIS_GUARD_PALUDIS_FILE_OUTPUT_MANAGER_HH 1
+
+#include <paludis/file_output_manager-fwd.hh>
+#include <paludis/output_manager.hh>
+#include <paludis/output_manager_factory.hh>
+#include <paludis/util/set-fwd.hh>
+#include <paludis/util/private_implementation_pattern.hh>
+#include <paludis/util/fs_entry-fwd.hh>
+#include <tr1/memory>
+#include <tr1/functional>
+
+namespace paludis
+{
+ class PALUDIS_VISIBLE FileOutputManager :
+ private PrivateImplementationPattern<FileOutputManager>,
+ public OutputManager
+ {
+ public:
+ FileOutputManager(const FSEntry &, const FSEntry &, const bool keep_on_success);
+ ~FileOutputManager();
+
+ virtual std::ostream & stdout_stream() PALUDIS_ATTRIBUTE((warn_unused_result));
+ virtual std::ostream & stderr_stream() PALUDIS_ATTRIBUTE((warn_unused_result));
+
+ virtual void succeeded();
+ virtual void message(const MessageType, const std::string &);
+
+ static const std::tr1::shared_ptr<const Set<std::string> > factory_managers()
+ PALUDIS_ATTRIBUTE((warn_unused_result));
+
+ static const std::tr1::shared_ptr<OutputManager> factory_create(
+ const OutputManagerFactory::KeyFunction &,
+ const OutputManagerFactory::CreateChildFunction &,
+ const OutputManagerFactory::ReplaceVarsFunc &)
+ PALUDIS_ATTRIBUTE((warn_unused_result));
+ };
+
+#ifdef PALUDIS_HAVE_EXTERN_TEMPLATE
+ extern template class PrivateImplementationPattern<FileOutputManager>;
+#endif
+}
+
+#endif
diff --git a/paludis/files.m4 b/paludis/files.m4
index a9ca87f..61a1b69 100644
--- a/paludis/files.m4
+++ b/paludis/files.m4
@@ -31,6 +31,7 @@ add(`elike_use_requirement', `hh', `cc', `fwd', `se', `test')
add(`environment', `hh', `fwd', `cc')
add(`environment_factory', `hh', `fwd', `cc')
add(`environment_implementation', `hh', `cc')
+add(`file_output_manager', `hh', `cc', `fwd')
add(`filter', `hh', `cc', `fwd', `test')
add(`filter_handler', `hh', `cc', `fwd')
add(`filtered_generator', `hh', `cc', `fwd', `test')
diff --git a/paludis/output_manager_factory.cc b/paludis/output_manager_factory.cc
index 1c8c903..1afed72 100644
--- a/paludis/output_manager_factory.cc
+++ b/paludis/output_manager_factory.cc
@@ -34,6 +34,7 @@
#include <tr1/unordered_map>
#include <list>
+#include <paludis/file_output_manager.hh>
#include <paludis/standard_output_manager.hh>
#include <paludis/tee_output_manager.hh>
@@ -84,6 +85,7 @@ OutputManagerFactory::OutputManagerFactory() :
PrivateImplementationPattern<OutputManagerFactory>(new Implementation<OutputManagerFactory>)
{
/* we might want to make this plugin loadable at some point */
+ add_manager(FileOutputManager::factory_managers(), FileOutputManager::factory_create);
add_manager(StandardOutputManager::factory_managers(), StandardOutputManager::factory_create);
add_manager(TeeOutputManager::factory_managers(), TeeOutputManager::factory_create);
}
@@ -95,11 +97,12 @@ OutputManagerFactory::~OutputManagerFactory()
const std::tr1::shared_ptr<OutputManager>
OutputManagerFactory::create(
const KeyFunction & key_function,
- const CreateChildFunction & create_child_function
+ const CreateChildFunction & create_child_function,
+ const ReplaceVarsFunc & replace_vars_func
) const
{
Context context("When creating output manager:");
- return fetch(_imp->keys, key_function("handler")).create_function()(key_function, create_child_function);
+ return fetch(_imp->keys, key_function("handler")).create_function()(key_function, create_child_function, replace_vars_func);
}
OutputManagerFactory::ConstIterator
diff --git a/paludis/output_manager_factory.hh b/paludis/output_manager_factory.hh
index ca8e045..eb653d7 100644
--- a/paludis/output_manager_factory.hh
+++ b/paludis/output_manager_factory.hh
@@ -44,12 +44,16 @@ namespace paludis
public:
typedef std::tr1::function<std::string (const std::string &)> KeyFunction;
+
typedef std::tr1::function<const std::tr1::shared_ptr<OutputManager> (
const std::string &)> CreateChildFunction;
+ typedef std::tr1::function<std::string (const std::string &)> ReplaceVarsFunc;
+
typedef std::tr1::function<const std::tr1::shared_ptr<OutputManager>(
const KeyFunction &,
- const CreateChildFunction &
+ const CreateChildFunction &,
+ const ReplaceVarsFunc &
)> CreateFunction;
/**
@@ -63,10 +67,16 @@ namespace paludis
* \param create_child_function is used by, for example,
* TeeOutputManager to create child streams. Given a single string,
* this function returns the appropriate child.
+ *
+ * \param replace_vars_func should replace '%{vars}' with their
+ * expanded forms. Variables include 'name', 'action' etc. This is
+ * used by, for example, FileOutputManager to allow the user to
+ * specify the output file names.
*/
const std::tr1::shared_ptr<OutputManager> create(
const KeyFunction & key_function,
- const CreateChildFunction & create_child_function
+ const CreateChildFunction & create_child_function,
+ const ReplaceVarsFunc & replace_vars_func
) const PALUDIS_ATTRIBUTE((warn_unused_result));
/**
diff --git a/paludis/standard_output_manager.cc b/paludis/standard_output_manager.cc
index cc6a305..881ffdd 100644
--- a/paludis/standard_output_manager.cc
+++ b/paludis/standard_output_manager.cc
@@ -65,8 +65,8 @@ StandardOutputManager::factory_managers()
const std::tr1::shared_ptr<OutputManager>
StandardOutputManager::factory_create(
const OutputManagerFactory::KeyFunction &,
- const OutputManagerFactory::CreateChildFunction &
- )
+ const OutputManagerFactory::CreateChildFunction &,
+ const OutputManagerFactory::ReplaceVarsFunc &)
{
return make_shared_ptr(new StandardOutputManager);
}
diff --git a/paludis/standard_output_manager.hh b/paludis/standard_output_manager.hh
index 0926d6f..5d2cf46 100644
--- a/paludis/standard_output_manager.hh
+++ b/paludis/standard_output_manager.hh
@@ -47,7 +47,8 @@ namespace paludis
static const std::tr1::shared_ptr<OutputManager> factory_create(
const OutputManagerFactory::KeyFunction &,
- const OutputManagerFactory::CreateChildFunction &)
+ const OutputManagerFactory::CreateChildFunction &,
+ const OutputManagerFactory::ReplaceVarsFunc &)
PALUDIS_ATTRIBUTE((warn_unused_result));
};
}
diff --git a/paludis/tee_output_manager.cc b/paludis/tee_output_manager.cc
index 2624029..167c11c 100644
--- a/paludis/tee_output_manager.cc
+++ b/paludis/tee_output_manager.cc
@@ -101,7 +101,8 @@ TeeOutputManager::factory_managers()
const std::tr1::shared_ptr<OutputManager>
TeeOutputManager::factory_create(
const OutputManagerFactory::KeyFunction & key_func,
- const OutputManagerFactory::CreateChildFunction & create_child)
+ const OutputManagerFactory::CreateChildFunction & create_child,
+ const OutputManagerFactory::ReplaceVarsFunc &)
{
std::tr1::shared_ptr<OutputManagerSequence> children(new OutputManagerSequence);
diff --git a/paludis/tee_output_manager.hh b/paludis/tee_output_manager.hh
index 6003c55..2a47bfb 100644
--- a/paludis/tee_output_manager.hh
+++ b/paludis/tee_output_manager.hh
@@ -50,7 +50,8 @@ namespace paludis
static const std::tr1::shared_ptr<OutputManager> factory_create(
const OutputManagerFactory::KeyFunction &,
- const OutputManagerFactory::CreateChildFunction &)
+ const OutputManagerFactory::CreateChildFunction &,
+ const OutputManagerFactory::ReplaceVarsFunc &)
PALUDIS_ATTRIBUTE((warn_unused_result));
};