Minor fixes
git-svn-id: https://svn.code.sf.net/p/porg/code/trunk@143 8854956c-c02d-4db9-8198-7e99b8e08f37
This commit is contained in:
parent
e4a4d335d1
commit
f090dfc5b4
56
porg/db.cc
56
porg/db.cc
|
@ -47,14 +47,12 @@ DB::~DB()
|
|||
//
|
||||
// get all packages logged in database
|
||||
//
|
||||
void DB::get_all_pkgs()
|
||||
void DB::get_pkgs_all()
|
||||
{
|
||||
Dir dir(Opt::logdir());
|
||||
|
||||
for (string name; dir.read(name); add_pkg(name)) ;
|
||||
|
||||
std::sort(begin(), end(), Sorter());
|
||||
|
||||
if (empty())
|
||||
Out::vrb("porg: No packages logged in '" + Opt::logdir() + "'");
|
||||
}
|
||||
|
@ -82,8 +80,6 @@ void DB::get_pkgs(vector<string> const& args)
|
|||
g_exit_status = EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
std::sort(begin(), end(), Sorter());
|
||||
}
|
||||
|
||||
|
||||
|
@ -107,13 +103,13 @@ bool DB::add_pkg(string const& name)
|
|||
//
|
||||
// get widths for printing pkg sizes and number of files
|
||||
//
|
||||
void DB::get_pkg_list_widths(int& size_w, int& nfiles_w)
|
||||
void DB::get_pkg_list_widths(int& size_w, int& nfiles_w) const
|
||||
{
|
||||
size_w = Opt::print_totals() ? get_width(m_total_size) : 0;
|
||||
|
||||
ulong max_nfiles(Opt::print_totals() ? m_total_files : 0);
|
||||
|
||||
for (iterator p(begin()); p != end(); ++p) {
|
||||
for (const_iterator p(begin()); p != end(); ++p) {
|
||||
|
||||
size_w = max(size_w, get_width((*p)->size()));
|
||||
|
||||
|
@ -128,11 +124,11 @@ void DB::get_pkg_list_widths(int& size_w, int& nfiles_w)
|
|||
//
|
||||
// get width for printing file sizes
|
||||
//
|
||||
int DB::get_file_size_width()
|
||||
int DB::get_file_size_width() const
|
||||
{
|
||||
int size_w = Opt::print_totals() ? get_width(m_total_size) : 0;
|
||||
|
||||
for (iterator p(begin()); p != end(); ++p) {
|
||||
for (const_iterator p(begin()); p != end(); ++p) {
|
||||
for (Pkg::const_iter f((*p)->files().begin()); f != (*p)->files().end(); ++f)
|
||||
size_w = max(size_w, get_width((*f)->size()));
|
||||
}
|
||||
|
@ -156,7 +152,7 @@ void DB::print_conf_opts() const
|
|||
}
|
||||
|
||||
|
||||
void DB::query()
|
||||
void DB::query() const
|
||||
{
|
||||
for (uint i(0); i < Opt::args().size(); ++i) {
|
||||
|
||||
|
@ -186,7 +182,17 @@ void DB::print_info() const
|
|||
}
|
||||
|
||||
|
||||
void DB::remove()
|
||||
void DB::sort_pkgs( sort_t type, // = SORT_BY_NAME
|
||||
bool reverse) // = false
|
||||
{
|
||||
std::sort(begin(), end(), Sorter(type));
|
||||
|
||||
if (reverse)
|
||||
std::reverse(begin(), end());
|
||||
}
|
||||
|
||||
|
||||
void DB::remove() const
|
||||
{
|
||||
// ask the user, if needed
|
||||
if (!Opt::remove_batch()) {
|
||||
|
@ -194,7 +200,7 @@ void DB::remove()
|
|||
cout << "The following packages will be "
|
||||
<< (Opt::remove_unlog() ? "unlogged:" : "removed:") << endl;
|
||||
|
||||
for (iterator p(begin()); p != end(); ++p)
|
||||
for (const_iterator p(begin()); p != end(); ++p)
|
||||
cout << " " << (*p)->name() << endl;
|
||||
|
||||
cout << "Do you want to proceed (y/N) ? ";
|
||||
|
@ -205,15 +211,15 @@ void DB::remove()
|
|||
}
|
||||
|
||||
if (Opt::remove_unlog()) {
|
||||
for (iterator p(begin()); p != end(); (*p++)->unlog()) ;
|
||||
for (const_iterator p(begin()); p != end(); (*p++)->unlog()) ;
|
||||
return;
|
||||
}
|
||||
|
||||
// auxiliary DB to check for shared files
|
||||
DB aux;
|
||||
aux.get_all_pkgs();
|
||||
aux.get_pkgs_all();
|
||||
|
||||
for (iterator p(begin()); p != end(); ++p) {
|
||||
for (const_iterator p(begin()); p != end(); ++p) {
|
||||
(*p)->remove(aux);
|
||||
aux.del_pkg((*p)->name());
|
||||
}
|
||||
|
@ -231,24 +237,18 @@ void DB::del_pkg(string const& name)
|
|||
}
|
||||
|
||||
|
||||
void DB::list_pkgs()
|
||||
void DB::list_pkgs() const
|
||||
{
|
||||
int size_w = 0, nfiles_w = 0;
|
||||
|
||||
if (Opt::print_sizes() || Opt::print_nfiles()) {
|
||||
// get widths for printing pkg sizes and number of files
|
||||
get_pkg_list_widths(size_w, nfiles_w);
|
||||
}
|
||||
// get widths for printing pkg sizes and number of files
|
||||
|
||||
// sort list of packages
|
||||
|
||||
std::sort(begin(), end(), Sorter(Opt::sort_type()));
|
||||
if (Opt::reverse_sort())
|
||||
std::reverse(begin(), end());
|
||||
if (Opt::print_sizes() || Opt::print_nfiles())
|
||||
get_pkg_list_widths(size_w, nfiles_w);
|
||||
|
||||
// list packages
|
||||
|
||||
for (iterator p(begin()); p != end(); ++p)
|
||||
for (const_iterator p(begin()); p != end(); ++p)
|
||||
(*p)->list(size_w, nfiles_w);
|
||||
|
||||
// print totals, if needed
|
||||
|
@ -269,11 +269,11 @@ void DB::list_pkgs()
|
|||
}
|
||||
|
||||
|
||||
void DB::list_files()
|
||||
void DB::list_files() const
|
||||
{
|
||||
int size_w(get_file_size_width());
|
||||
|
||||
for (iterator p(begin()); p != end(); ++p) {
|
||||
for (const_iterator p(begin()); p != end(); ++p) {
|
||||
(*p)->list_files(size_w);
|
||||
if (!Opt::print_no_pkg_name() && size() > 1)
|
||||
cout << endl;
|
||||
|
|
15
porg/db.h
15
porg/db.h
|
@ -26,19 +26,20 @@ class DB : public std::vector<Pkg*>
|
|||
~DB();
|
||||
|
||||
void get_pkgs(std::vector<std::string> const& args);
|
||||
void get_all_pkgs();
|
||||
void get_pkgs_all();
|
||||
void sort_pkgs(sort_t type = SORT_BY_NAME, bool reverse = false);
|
||||
|
||||
void list_pkgs();
|
||||
void list_files();
|
||||
void list_pkgs() const;
|
||||
void list_files() const;
|
||||
void print_conf_opts() const;
|
||||
void query();
|
||||
void remove();
|
||||
void query() const;
|
||||
void remove() const;
|
||||
void print_info() const;
|
||||
|
||||
protected:
|
||||
|
||||
void get_pkg_list_widths(int&, int&);
|
||||
int get_file_size_width();
|
||||
void get_pkg_list_widths(int&, int&) const;
|
||||
int get_file_size_width() const;
|
||||
bool add_pkg(std::string const& name);
|
||||
void del_pkg(std::string const& name);
|
||||
|
||||
|
|
|
@ -34,13 +34,15 @@ int main(int argc, char* argv[])
|
|||
DB db;
|
||||
|
||||
if (Opt::mode() == MODE_QUERY || Opt::all_pkgs())
|
||||
db.get_all_pkgs();
|
||||
db.get_pkgs_all();
|
||||
else
|
||||
db.get_pkgs(Opt::args());
|
||||
|
||||
if (db.empty())
|
||||
exit(g_exit_status);
|
||||
|
||||
db.sort_pkgs(Opt::sort_type(), Opt::reverse_sort());
|
||||
|
||||
switch (Opt::mode()) {
|
||||
case MODE_CONF_OPTS: db.print_conf_opts(); break;
|
||||
case MODE_INFO: db.print_info(); break;
|
||||
|
|
Loading…
Reference in New Issue