aboutsummaryrefslogtreecommitdiff
path: root/paludis/environments
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2009-02-14 14:42:00 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2009-02-14 14:42:00 +0000
commite0f6f1ab615872a8fc75b6cc81bbf5712848cd86 (patch)
tree9666629f3ae431b78ffd522005d74f2ffd823725 /paludis/environments
parent0d1264a7740c448c6e50ce074e03ed294ae8be2b (diff)
downloadpaludis-e0f6f1ab615872a8fc75b6cc81bbf5712848cd86.tar.gz
paludis-e0f6f1ab615872a8fc75b6cc81bbf5712848cd86.tar.xz
Message output formatting
Diffstat (limited to 'paludis/environments')
-rw-r--r--paludis/environments/paludis/output_managers.cc78
-rw-r--r--paludis/environments/paludis/output_managers.hh9
-rw-r--r--paludis/environments/paludis/output_managers/keep_messages.conf5
3 files changed, 52 insertions, 40 deletions
diff --git a/paludis/environments/paludis/output_managers.cc b/paludis/environments/paludis/output_managers.cc
index 56563d503..b448da934 100644
--- a/paludis/environments/paludis/output_managers.cc
+++ b/paludis/environments/paludis/output_managers.cc
@@ -95,10 +95,11 @@ OutputManagers::create_named_output_manager(const std::string & s, const CreateO
if (i == _imp->store.end())
throw PaludisConfigError("No output manager named '" + s + "' exists");
+ std::tr1::shared_ptr<Map<std::string, std::string> > vars(vars_from_create_output_manager_info(n));
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::cref(n)),
- std::tr1::bind(&OutputManagers::replace_vars, this, std::tr1::placeholders::_1, std::tr1::cref(n))
+ std::tr1::bind(replace_percent_vars, std::tr1::placeholders::_1, vars, std::tr1::placeholders::_2)
);
}
@@ -114,59 +115,58 @@ namespace
struct CreateVarsFromInfo
{
- std::tr1::unordered_map<std::string, std::string> & m;
+ std::tr1::shared_ptr<Map<std::string, std::string> > m;
- CreateVarsFromInfo(std::tr1::unordered_map<std::string, std::string> & mm) :
+ CreateVarsFromInfo(std::tr1::shared_ptr<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));
+ m->insert("type", "repository");
+ m->insert("action", "sync");
+ m->insert("name", stringify(i.repository().name()));
+ m->insert("pid", stringify(getpid()));
+ m->insert("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()));
+ m->insert("type", "package");
+ m->insert("action", action_to_string(i.action()));
+ m->insert("name", stringify(i.package_id()->name()));
+ m->insert("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));
+ m->insert("slot", stringify(i.package_id()->slot_key()->value()));
+ m->insert("version", stringify(i.package_id()->version()));
+ m->insert("repository", stringify(i.package_id()->repository()->name()));
+ m->insert("category", stringify(i.package_id()->name().category()));
+ m->insert("package", stringify(i.package_id()->name().package()));
+ m->insert("pid", stringify(getpid()));
+ m->insert("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 std::tr1::shared_ptr<Map<std::string, std::string> >
+OutputManagers::vars_from_create_output_manager_info(
const CreateOutputManagerInfo & i) const
{
- Context context("When expanding variables in '" + s + "':");
+ std::tr1::shared_ptr<Map<std::string, std::string> > result(new Map<std::string, std::string>);
+ CreateVarsFromInfo v(result);
+ i.accept(v);
+ return result;
+}
- SimpleParser parser(s);
+const std::string
+paludis::paludis_environment::replace_percent_vars(
+ const std::string & s,
+ const std::tr1::shared_ptr<const Map<std::string, std::string> > & vars,
+ const std::tr1::shared_ptr<const Map<std::string, std::string> > & override_vars)
+{
std::string result, token;
- std::tr1::unordered_map<std::string, std::string> m;
- create_vars_from_info(i, m);
-
+ SimpleParser parser(s);
while (! parser.eof())
{
if (parser.consume((+simple_parser::any_except("%")) >> token))
@@ -177,11 +177,13 @@ OutputManagers::replace_vars(
((+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())
+ Map<std::string, std::string>::ConstIterator v(override_vars->find(token));
+ if (v == override_vars->end())
+ v = vars->find(token);
+ if (v == vars->end())
throw PaludisConfigError("No variable named '" + token + "' in var string '" + s + "'");
- else
- result.append(j->second);
+
+ result.append(v->second);
}
else
throw PaludisConfigError("Invalid var string '" + s + "'");
diff --git a/paludis/environments/paludis/output_managers.hh b/paludis/environments/paludis/output_managers.hh
index 106166587..80ad72300 100644
--- a/paludis/environments/paludis/output_managers.hh
+++ b/paludis/environments/paludis/output_managers.hh
@@ -24,6 +24,7 @@
#include <paludis/util/private_implementation_pattern.hh>
#include <paludis/util/instantiation_policy.hh>
#include <paludis/util/fs_entry-fwd.hh>
+#include <paludis/util/map-fwd.hh>
#include <paludis/output_manager-fwd.hh>
#include <paludis/create_output_manager_info-fwd.hh>
#include <tr1/memory>
@@ -34,6 +35,11 @@ namespace paludis
namespace paludis_environment
{
+ const std::string replace_percent_vars(
+ const std::string &,
+ const std::tr1::shared_ptr<const Map<std::string, std::string> > & vars,
+ const std::tr1::shared_ptr<const Map<std::string, std::string> > & override_vars);
+
class OutputManagers :
private PrivateImplementationPattern<OutputManagers>,
private InstantiationPolicy<OutputManagers, instantiation_method::NonCopyableTag>
@@ -56,8 +62,7 @@ namespace paludis
const std::string &,
const CreateOutputManagerInfo &) const;
- std::string replace_vars(
- const std::string &,
+ const std::tr1::shared_ptr<Map<std::string, std::string> > vars_from_create_output_manager_info(
const CreateOutputManagerInfo &) const;
};
}
diff --git a/paludis/environments/paludis/output_managers/keep_messages.conf b/paludis/environments/paludis/output_managers/keep_messages.conf
index 927124369..38f7505d6 100644
--- a/paludis/environments/paludis/output_managers/keep_messages.conf
+++ b/paludis/environments/paludis/output_managers/keep_messages.conf
@@ -2,4 +2,9 @@
handler = messages_to_stdout
child = keep_stdout_as_messages
+format_debug =
+format_info = --- %{message}
+format_warn = *** %{message}
+format_error = !!! %{message}
+format_log = +++ %{message}