aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2007-11-09 00:03:32 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2007-11-09 00:03:32 +0000
commit0ecc1a49b0669525af75525e9b91e19f99ef04be (patch)
tree0faecb7e94df2a1e0836e2f01780c8b03d71db9d
parent42df6101694290420b1641d4a4f03816150fcc7b (diff)
downloadpaludis-0ecc1a49b0669525af75525e9b91e19f99ef04be.tar.gz
paludis-0ecc1a49b0669525af75525e9b91e19f99ef04be.tar.xz
Better formatting
-rw-r--r--paludis/repositories/unpackaged/dep_printer.cc105
-rw-r--r--paludis/repositories/unpackaged/dep_printer.hh3
-rw-r--r--paludis/repositories/unpackaged/installed_id.cc31
-rw-r--r--paludis/repositories/unpackaged/unpackaged_id.cc4
-rw-r--r--paludis/repositories/unpackaged/unpackaged_key.cc13
-rw-r--r--paludis/repositories/unpackaged/unpackaged_key.hh3
6 files changed, 90 insertions, 69 deletions
diff --git a/paludis/repositories/unpackaged/dep_printer.cc b/paludis/repositories/unpackaged/dep_printer.cc
index 501a71f..af114bd 100644
--- a/paludis/repositories/unpackaged/dep_printer.cc
+++ b/paludis/repositories/unpackaged/dep_printer.cc
@@ -20,6 +20,9 @@
#include <paludis/repositories/unpackaged/dep_printer.hh>
#include <paludis/util/visitor-impl.hh>
#include <paludis/util/private_implementation_pattern-impl.hh>
+#include <paludis/environment.hh>
+#include <paludis/package_database.hh>
+#include <paludis/query.hh>
#include <sstream>
using namespace paludis;
@@ -30,21 +33,31 @@ namespace paludis
template <>
struct Implementation<DepPrinter>
{
- const DependencySpecTree::ItemFormatter & formatter;
+ std::stringstream s;
+ const Environment * const env;
+ DependencySpecTree::ItemFormatter formatter;
+ const unsigned indent;
const bool flat;
- std::stringstream result;
+ bool need_comma;
- Implementation(const DependencySpecTree::ItemFormatter & f,
+ Implementation(
+ const Environment * const e,
+ const DependencySpecTree::ItemFormatter & f,
+ const unsigned u,
const bool b) :
+ env(e),
formatter(f),
- flat(b)
+ indent(u),
+ flat(b),
+ need_comma(false)
{
}
};
}
-DepPrinter::DepPrinter(const DependencySpecTree::ItemFormatter & f, const bool b) :
- PrivateImplementationPattern<DepPrinter>(new Implementation<DepPrinter>(f, b))
+DepPrinter::DepPrinter(const Environment * const e,
+ const DependencySpecTree::ItemFormatter & f, const bool flat) :
+ PrivateImplementationPattern<DepPrinter>(new Implementation<DepPrinter>(e, f, 0, flat))
{
}
@@ -52,65 +65,63 @@ DepPrinter::~DepPrinter()
{
}
-const std::string
-DepPrinter::result() const
-{
- return _imp->result.str();
-}
-
void
-DepPrinter::visit_leaf(const PackageDepSpec & s)
+DepPrinter::visit_leaf(const PackageDepSpec & p)
{
- if (! _imp->result.str().empty())
+ if (! _imp->flat)
+ _imp->s << _imp->formatter.indent(_imp->indent);
+ else if (_imp->need_comma)
+ _imp->s << ", ";
+ else
+ _imp->need_comma = true;
+
+ if (_imp->env)
{
- if (! _imp->flat)
- _imp->result << _imp->formatter.indent(1);
+ if (! _imp->env->package_database()->query(query::Matches(p) &
+ query::InstalledAtRoot(_imp->env->root()), qo_whatever)->empty())
+ _imp->s << _imp->formatter.format(p, format::Installed());
+ else if (! _imp->env->package_database()->query(query::Matches(p) &
+ query::SupportsAction<InstallAction>() & query::NotMasked(), qo_whatever)->empty())
+ _imp->s << _imp->formatter.format(p, format::Installable());
else
- _imp->result << ", ";
+ _imp->s << _imp->formatter.format(p, format::Plain());
}
+ else
+ _imp->s << _imp->formatter.format(p, format::Plain());
- _imp->result << s;
+ if (! _imp->flat)
+ _imp->s << _imp->formatter.newline();
}
void
-DepPrinter::visit_leaf(const NamedSetDepSpec & s)
+DepPrinter::visit_leaf(const BlockDepSpec &)
{
- if (! _imp->result.str().empty())
- {
- if (! _imp->flat)
- _imp->result << _imp->formatter.indent(1);
- else
- _imp->result << ", ";
- }
-
- _imp->result << s;
}
void
-DepPrinter::visit_leaf(const BlockDepSpec & s)
+DepPrinter::visit_leaf(const DependencyLabelsDepSpec &)
{
- if (! _imp->result.str().empty())
- {
- if (! _imp->flat)
- _imp->result << _imp->formatter.indent(1);
- else
- _imp->result << ", ";
- }
-
- _imp->result << s;
}
void
-DepPrinter::visit_leaf(const DependencyLabelsDepSpec & s)
+DepPrinter::visit_leaf(const NamedSetDepSpec & p)
{
- if (! _imp->result.str().empty())
- {
- if (! _imp->flat)
- _imp->result << _imp->formatter.indent(1);
- else
- _imp->result << ", ";
- }
+ if (! _imp->flat)
+ _imp->s << _imp->formatter.indent(_imp->indent);
+ else if (_imp->need_comma)
+ _imp->s << ", ";
+ else
+ _imp->need_comma = true;
+
+ _imp->s << _imp->formatter.format(p, format::Plain());
- _imp->result << s;
+ if (! _imp->flat)
+ _imp->s << _imp->formatter.newline();
+}
+
+const std::string
+DepPrinter::result() const
+{
+ return _imp->s.str();
}
diff --git a/paludis/repositories/unpackaged/dep_printer.hh b/paludis/repositories/unpackaged/dep_printer.hh
index 1385a14..a60626e 100644
--- a/paludis/repositories/unpackaged/dep_printer.hh
+++ b/paludis/repositories/unpackaged/dep_printer.hh
@@ -24,6 +24,7 @@
#include <paludis/util/private_implementation_pattern.hh>
#include <paludis/dep_tree.hh>
#include <paludis/formatter.hh>
+#include <paludis/environment-fwd.hh>
namespace paludis
{
@@ -37,7 +38,7 @@ namespace paludis
private PrivateImplementationPattern<DepPrinter>
{
public:
- DepPrinter(const DependencySpecTree::ItemFormatter &, const bool);
+ DepPrinter(const Environment * const, const DependencySpecTree::ItemFormatter &, const bool);
~DepPrinter();
const std::string result() const;
diff --git a/paludis/repositories/unpackaged/installed_id.cc b/paludis/repositories/unpackaged/installed_id.cc
index d5dc39f..9e20f67 100644
--- a/paludis/repositories/unpackaged/installed_id.cc
+++ b/paludis/repositories/unpackaged/installed_id.cc
@@ -144,8 +144,8 @@ namespace
const FSEntry _f;
public:
- InstalledUnpackagedStringKey(const std::string & r, const std::string & h, const FSEntry & f) :
- MetadataStringKey(r, h, mkt_normal),
+ InstalledUnpackagedStringKey(const std::string & r, const std::string & h, const FSEntry & f, const MetadataKeyType t) :
+ MetadataStringKey(r, h, t),
_f(f)
{
}
@@ -171,13 +171,16 @@ namespace
public MetadataSpecTreeKey<DependencySpecTree>
{
private:
+ const Environment * const _env;
mutable tr1::shared_ptr<const DependencySpecTree::ConstItem> _v;
mutable Mutex _mutex;
const FSEntry _f;
public:
- InstalledUnpackagedDependencyKey(const std::string & r, const std::string & h, const FSEntry & f) :
- MetadataSpecTreeKey<DependencySpecTree>(r, h, mkt_normal),
+ InstalledUnpackagedDependencyKey(const Environment * const e,
+ const std::string & r, const std::string & h, const FSEntry & f, const MetadataKeyType t) :
+ MetadataSpecTreeKey<DependencySpecTree>(r, h, t),
+ _env(e),
_f(f)
{
}
@@ -202,7 +205,7 @@ namespace
std::string
pretty_print(const DependencySpecTree::ItemFormatter & f) const
{
- DepPrinter p(f, false);
+ DepPrinter p(_env, f, false);
value()->accept(p);
return p.result();
}
@@ -210,7 +213,7 @@ namespace
std::string
pretty_print_flat(const DependencySpecTree::ItemFormatter & f) const
{
- DepPrinter p(f, true);
+ DepPrinter p(_env, f, true);
value()->accept(p);
return p.result();
}
@@ -265,21 +268,23 @@ namespace paludis
}
if ((l / "source_repository").exists())
- source_origin_key.reset(new InstalledUnpackagedStringKey("source_repository", "Source repository", l / "source_repository"));
+ source_origin_key.reset(new InstalledUnpackagedStringKey("source_repository", "Source repository", l / "source_repository",
+ mkt_normal));
if ((l / "binary_repository").exists())
- binary_origin_key.reset(new InstalledUnpackagedStringKey("binary_repository", "Binary repository", l / "binary_repository"));
+ binary_origin_key.reset(new InstalledUnpackagedStringKey("binary_repository", "Binary repository", l / "binary_repository",
+ mkt_normal));
if ((l / "description").exists())
- description_key.reset(new InstalledUnpackagedStringKey("description", "Description", l / "description"));
+ description_key.reset(new InstalledUnpackagedStringKey("description", "Description", l / "description", mkt_significant));
if ((l / "build_dependencies").exists())
- build_dependencies_key.reset(new InstalledUnpackagedDependencyKey(
- "build_dependencies", "Build dependencies", l / "build_dependencies"));
+ build_dependencies_key.reset(new InstalledUnpackagedDependencyKey(env,
+ "build_dependencies", "Build dependencies", l / "build_dependencies", mkt_dependencies));
if ((l / "run_dependencies").exists())
- run_dependencies_key.reset(new InstalledUnpackagedDependencyKey(
- "run_dependencies", "Run dependencies", l / "run_dependencies"));
+ run_dependencies_key.reset(new InstalledUnpackagedDependencyKey(env,
+ "run_dependencies", "Run dependencies", l / "run_dependencies", mkt_dependencies));
}
};
}
diff --git a/paludis/repositories/unpackaged/unpackaged_id.cc b/paludis/repositories/unpackaged/unpackaged_id.cc
index 5ca67b3..237592a 100644
--- a/paludis/repositories/unpackaged/unpackaged_id.cc
+++ b/paludis/repositories/unpackaged/unpackaged_id.cc
@@ -68,8 +68,8 @@ namespace paludis
slot(s),
repository_name(n),
fs_location_key(new UnpackagedFSEntryKey("location", "Location", mkt_normal, l)),
- build_dependencies_key(new UnpackagedDependencyKey("build_dependencies", "Build dependencies", mkt_dependencies, b)),
- run_dependencies_key(new UnpackagedDependencyKey("run_dependencies", "Run dependencies", mkt_dependencies, r)),
+ build_dependencies_key(new UnpackagedDependencyKey(env, "build_dependencies", "Build dependencies", mkt_dependencies, b)),
+ run_dependencies_key(new UnpackagedDependencyKey(env, "run_dependencies", "Run dependencies", mkt_dependencies, r)),
description_key(new UnpackagedStringKey("description", "Description", mkt_significant, d))
{
}
diff --git a/paludis/repositories/unpackaged/unpackaged_key.cc b/paludis/repositories/unpackaged/unpackaged_key.cc
index b25499e..1c107ca 100644
--- a/paludis/repositories/unpackaged/unpackaged_key.cc
+++ b/paludis/repositories/unpackaged/unpackaged_key.cc
@@ -95,19 +95,22 @@ namespace paludis
template <>
struct Implementation<UnpackagedDependencyKey>
{
+ const Environment * const env;
const tr1::shared_ptr<const DependencySpecTree::ConstItem> value;
- Implementation(const std::string & v) :
+ Implementation(const Environment * const e, const std::string & v) :
+ env(e),
value(DepParser::parse(v))
{
}
};
}
-UnpackagedDependencyKey::UnpackagedDependencyKey(const std::string & r, const std::string & h, const MetadataKeyType t,
+UnpackagedDependencyKey::UnpackagedDependencyKey(const Environment * const env,
+ const std::string & r, const std::string & h, const MetadataKeyType t,
const std::string & v) :
MetadataSpecTreeKey<DependencySpecTree>(r, h, t),
- PrivateImplementationPattern<UnpackagedDependencyKey>(new Implementation<UnpackagedDependencyKey>(v)),
+ PrivateImplementationPattern<UnpackagedDependencyKey>(new Implementation<UnpackagedDependencyKey>(env, v)),
_imp(PrivateImplementationPattern<UnpackagedDependencyKey>::_imp.get())
{
}
@@ -125,7 +128,7 @@ UnpackagedDependencyKey::value() const
std::string
UnpackagedDependencyKey::pretty_print(const DependencySpecTree::ItemFormatter & f) const
{
- DepPrinter p(f, false);
+ DepPrinter p(_imp->env, f, false);
_imp->value->accept(p);
return p.result();
}
@@ -133,7 +136,7 @@ UnpackagedDependencyKey::pretty_print(const DependencySpecTree::ItemFormatter &
std::string
UnpackagedDependencyKey::pretty_print_flat(const DependencySpecTree::ItemFormatter & f) const
{
- DepPrinter p(f, true);
+ DepPrinter p(_imp->env, f, true);
_imp->value->accept(p);
return p.result();
}
diff --git a/paludis/repositories/unpackaged/unpackaged_key.hh b/paludis/repositories/unpackaged/unpackaged_key.hh
index e52fd0c..8d4e506 100644
--- a/paludis/repositories/unpackaged/unpackaged_key.hh
+++ b/paludis/repositories/unpackaged/unpackaged_key.hh
@@ -63,7 +63,8 @@ namespace paludis
Implementation<UnpackagedDependencyKey> * const _imp;
public:
- UnpackagedDependencyKey(const std::string & r, const std::string & h, const MetadataKeyType t,
+ UnpackagedDependencyKey(const Environment * const env,
+ const std::string & r, const std::string & h, const MetadataKeyType t,
const std::string & v);
~UnpackagedDependencyKey();