aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2008-01-23 07:25:30 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2008-01-23 07:25:30 +0000
commit5e426948b85259c62038494d2a850a900dfa9023 (patch)
treed052f28d39d9721e2b7398a0d5d9118bc1fe79f6
parent950188b3424c66b395db6583073533d6cbf5e421 (diff)
downloadpaludis-5e426948b85259c62038494d2a850a900dfa9023.tar.gz
paludis-5e426948b85259c62038494d2a850a900dfa9023.tar.xz
Display size of downloads as part of pretend install output. (Victor Meyerson)
-rw-r--r--paludis/repositories/e/e_key.cc18
-rw-r--r--paludis/util/files.m41
-rw-r--r--paludis/util/pretty_print.cc48
-rw-r--r--paludis/util/pretty_print.hh41
-rw-r--r--paludis/util/pretty_print_TEST.cc57
-rw-r--r--src/output/console_install_task.cc8
-rw-r--r--src/output/console_install_task.hh11
7 files changed, 168 insertions, 16 deletions
diff --git a/paludis/repositories/e/e_key.cc b/paludis/repositories/e/e_key.cc
index e3edd75..b5326ff 100644
--- a/paludis/repositories/e/e_key.cc
+++ b/paludis/repositories/e/e_key.cc
@@ -24,6 +24,7 @@
#include <paludis/repositories/e/dep_spec_pretty_printer.hh>
#include <paludis/repositories/e/vdb_contents_tokeniser.hh>
+#include <paludis/util/pretty_print.hh>
#include <paludis/util/private_implementation_pattern-impl.hh>
#include <paludis/util/stringify.hh>
#include <paludis/util/tokeniser.hh>
@@ -46,7 +47,6 @@
#include <vector>
#include <fstream>
#include <map>
-#include <iomanip>
using namespace paludis;
using namespace paludis::erepository;
@@ -1144,19 +1144,5 @@ EDistSizeKey::value() const
std::string
EDistSizeKey::pretty_print() const
{
- double size(value());
- int i(0);
- std::string suffix[] = {"Bytes", "kBytes", "MBytes", "GBytes"};
- std::ostringstream val;
-
- while (size >= 1024.0 && i < 3)
- {
- size /= 1024.0;
- i++;
- }
- if (i >= 1) val << std::fixed << std::setprecision(2);
-
- val << size << " " << suffix[i];
-
- return val.str();
+ return pretty_print_bytes(value());
}
diff --git a/paludis/util/files.m4 b/paludis/util/files.m4
index e2b3bc4..1ab35fb 100644
--- a/paludis/util/files.m4
+++ b/paludis/util/files.m4
@@ -40,6 +40,7 @@ add(`operators', `hh')
add(`options', `hh', `fwd', `cc', `test')
add(`output_wrapper', `test', `testscript')
add(`pipe', `hh', `cc')
+add(`pretty_print', `hh', `cc', `test')
add(`private_implementation_pattern', `hh', `impl')
add(`random', `hh', `cc', `test')
add(`remove_shared_ptr', `hh')
diff --git a/paludis/util/pretty_print.cc b/paludis/util/pretty_print.cc
new file mode 100644
index 0000000..eb3b053
--- /dev/null
+++ b/paludis/util/pretty_print.cc
@@ -0,0 +1,48 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2008 Mike Kelly
+ *
+ * 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/util/pretty_print.hh>
+
+#include <iomanip>
+#include <sstream>
+
+using namespace paludis;
+
+std::string
+pretty_print_bytes(const long & bytes)
+{
+ double size(bytes);
+ int i(0);
+ std::string suffix[] = {"Bytes", "kBytes", "MBytes", "GBytes"};
+ std::ostringstream val;
+
+ while (size >= 1024.0 && i < 3)
+ {
+ size /= 1024.0;
+ i++;
+ }
+
+ if (i >= 1)
+ val << std::fixed << std::setprecision(2);
+
+ val << size << " " << suffix[i];
+
+ return val.str();
+}
+
diff --git a/paludis/util/pretty_print.hh b/paludis/util/pretty_print.hh
new file mode 100644
index 0000000..17e097f
--- /dev/null
+++ b/paludis/util/pretty_print.hh
@@ -0,0 +1,41 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2008 Mike Kelly
+ *
+ * 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_UTIL_PRETTY_PRINT_HH
+#define PALUDIS_GUARD_PALUDIS_UTIL_PRETTY_PRINT_HH 1
+
+#include <paludis/util/attributes.hh>
+#include <string>
+
+/** \file
+ * Pretty print function.
+ *
+ */
+
+namespace paludis
+{
+
+ /**
+ * Convert bytes to a pretty printed string.
+ *
+ */
+ std::string pretty_print_bytes(const long & bytes) PALUDIS_VISIBLE;
+}
+
+#endif
diff --git a/paludis/util/pretty_print_TEST.cc b/paludis/util/pretty_print_TEST.cc
new file mode 100644
index 0000000..9c16007
--- /dev/null
+++ b/paludis/util/pretty_print_TEST.cc
@@ -0,0 +1,57 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2008 Victor Meyerson
+ *
+ * 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/util/pretty_print.hh>
+#include <string>
+#include <test/test_framework.hh>
+#include <test/test_runner.hh>
+
+using namespace test;
+using namespace paludis;
+
+/** \file
+ * Test case for pretty_print.hh .
+ *
+ */
+
+namespace test_cases
+{
+ /** \test
+ * Test pretty_print_bytes.
+ *
+ */
+ struct PrettyPrintBytesTests : TestCase
+ {
+ PrettyPrintBytesTests() : TestCase("pretty_print_bytes") { }
+
+ void run()
+ {
+ TEST_CHECK_EQUAL(pretty_print_bytes(0), "0 Bytes");
+ TEST_CHECK_EQUAL(pretty_print_bytes(1), "1 Bytes");
+ TEST_CHECK_EQUAL(pretty_print_bytes(100), "100 Bytes");
+ TEST_CHECK_EQUAL(pretty_print_bytes(1024), "1.00 kBytes");
+ TEST_CHECK_EQUAL(pretty_print_bytes(1536), "1.50 kBytes");
+ TEST_CHECK_EQUAL(pretty_print_bytes(1048576), "1.00 MBytes");
+ TEST_CHECK_EQUAL(pretty_print_bytes(1953497), "1.86 MBytes");
+ TEST_CHECK_EQUAL(pretty_print_bytes(1073741824), "1.00 GBytes");
+ TEST_CHECK_EQUAL(pretty_print_bytes(1537598292), "1.43 GBytes");
+ }
+ } test_case_pretty_print_bytes;
+}
+
diff --git a/src/output/console_install_task.cc b/src/output/console_install_task.cc
index cc8550d..bbc1423 100644
--- a/src/output/console_install_task.cc
+++ b/src/output/console_install_task.cc
@@ -23,6 +23,7 @@
#include "mask_displayer.hh"
#include <paludis/util/log.hh>
+#include <paludis/util/pretty_print.h>
#include <paludis/util/sr.hh>
#include <paludis/util/strip.hh>
#include <paludis/util/tokeniser.hh>
@@ -122,6 +123,7 @@ ConsoleInstallTask::ConsoleInstallTask(Environment * const env,
const DepListOptions & options,
tr1::shared_ptr<const DestinationsSet> d) :
InstallTask(env, options, d),
+ _download_size(0),
_all_tags(new Set<DepTagEntry>),
_all_use_descriptions(new Set<UseDescription, UseDescriptionComparator>),
_all_expand_prefixes(new UseFlagNameSet)
@@ -573,6 +575,11 @@ ConsoleInstallTask::display_merge_list_post_counts()
need_comma = true;
}
s << ")";
+
+ if (get_download_size())
+ {
+ s << ", at most " << pretty_print_bytes(get_download_size()) << " to download";
+ }
}
if (count<max_count>() && count<error_count>())
@@ -1180,6 +1187,7 @@ ConsoleInstallTask::display_merge_list_entry_distsize(const DepListEntry & d,
output_stream() << d.package_id->size_of_download_required_key()->pretty_print()
<< " to download";
+ set_download_size(get_download_size() + d.package_id->size_of_download_required_key()->value());
}
void
diff --git a/src/output/console_install_task.hh b/src/output/console_install_task.hh
index cb80ac6..35e2fcf 100644
--- a/src/output/console_install_task.hh
+++ b/src/output/console_install_task.hh
@@ -113,6 +113,7 @@ namespace paludis
private:
int _counts[last_count];
+ long _download_size;
tr1::shared_ptr<Set<DepTagEntry> > _all_tags;
tr1::shared_ptr<Set<UseDescription, UseDescriptionComparator> > _all_use_descriptions;
tr1::shared_ptr<UseFlagNameSet> _all_expand_prefixes;
@@ -270,6 +271,16 @@ namespace paludis
_counts[count_] = value;
}
+ long get_download_size() const
+ {
+ return _download_size;
+ }
+
+ void set_download_size(const long value)
+ {
+ _download_size = value;
+ }
+
tr1::shared_ptr<Set<DepTagEntry> > all_tags()
{
return _all_tags;