Started patch-check.
zmart-source-callbacks.h \
zmart-sources.h \
zmart-misc.h \
+ zypper-tabulator.h \
+ zypper-tabulator.cc \
zmart.h
zypper_SOURCES = zypper.cc zmart-sources.cc zmart-misc.cc \
zmart-source-callbacks.h \
zmart-sources.h \
zmart-misc.h \
+ zypper-tabulator.h \
+ zypper-tabulator.cc \
zmart.h
zypp_checkpatches_SOURCES = zypp-checkpatches.cc zmart-sources.cc \
+ zypper-tabulator.h \
+ zypper-tabulator.cc \
checkpatches-keyring-callbacks.h
#zmart_LDFLAGS = -static
#include <boost/format.hpp>
#include "zmart.h"
#include "zmart-misc.h"
+#include "zypper-tabulator.h"
#include <zypp/Patch.h>
#include <zypp/base/Algorithm.h>
return token;
}
+void cond_load_resolvables ()
+{
+ // something changed
+ cerr_v << "loading sources" << endl;
+ load_sources();
+
+ if ( ! gSettings.disable_system_resolvables ) {
+ cerr_v << "loading target" << endl;
+ load_target();
+ }
+}
+
void load_target()
{
cout << "Adding system resolvables to pool..." << endl;
}
}
-void resolve()
+void establish ()
{
- cout << "Resolving dependencies ..." << endl;
+ cerr_v << "Establishing status of aggregates" << endl;
God->resolver()->establishPool();
+}
+
+void resolve()
+{
+ establish ();
+ cerr_v << "Resolving dependencies ..." << endl;
God->resolver()->resolvePool();
}
void show_pool()
{
MIL << "Pool contains " << God->pool().size() << " items. Checking whether available patches are needed." << std::endl;
- for ( ResPool::byKind_iterator it = God->pool().byKindBegin<Patch>(); it != God->pool().byKindEnd<Patch>(); ++it )
+
+ Table tbl;
+ ResPool::byKind_iterator
+ it = God->pool().byKindBegin<Patch>(),
+ e = God->pool().byKindEnd<Patch>();
+ for (; it != e; ++it )
{
Resolvable::constPtr res = it->resolvable();
Patch::constPtr patch = asKind<Patch>(res);
- //cout << patch->name() << " " << patch->edition() << " " << "[" << patch->category() << "]" << ( it->status().isNeeded() ? " [needed]" : " [unneeded]" )<< std::endl;
+
if ( it->status().isNeeded() )
{
gData.patches_count++;
if (patch->category() == "security")
gData.security_patches_count++;
-
- cerr << patch->name() << " " << patch->edition() << " " << "[" << patch->category() << "]" << std::endl;
+
+ TableRow tr;
+ tr << patch->name() << patch->edition().asString() << patch->category();
+ tbl << tr;
}
- }
+ }
+ cout << tbl;
+
cout << gData.patches_count << " patches needed. ( " << gData.security_patches_count << " security patches )" << std::endl;
}
const std::string &name );
void show_summary();
std::string calculate_token();
+//! load all resolvables that the user wants
+void cond_load_resolvables ();
void load_target();
void load_sources();
+void establish ();
void resolve();
void show_pool();
void usage(int argc, char **argv);
#include "zmart.h"
#include "zmart-sources.h"
+#include "zypper-tabulator.h"
#include <boost/format.hpp>
#include <boost/lexical_cast.hpp>
extern RuntimeData gData;
extern Settings gSettings;
+void cond_init_system_sources ()
+{
+ if ( geteuid() != 0 ) {
+ cerr << "Sorry, you need root privileges to use system sources, disabling them..." << endl;
+ gSettings.disable_system_sources = true;
+ MIL << "system sources disabled" << endl;
+ }
+
+ if ( ! gSettings.disable_system_sources ) {
+ cerr_v << "initializing sources" << endl;
+ init_system_sources();
+ }
+}
+
void init_system_sources()
{
SourceManager_Ptr manager;
cout << " Sub'd? | Name | Service" << endl;
cout << "-------+--------------------------------------------------------+-------------------------------------------------------" << endl;
+ Table tbl;
for( std::list<zypp::source::SourceInfo>::const_iterator it = sources.begin() ;
it != sources.end() ; ++it )
{
SourceInfo source = *it;
- cout << ( source.enabled() ? "[x]" : "[ ]" );
- cout << ( source.autorefresh() ? "* " : " " );
- if ( source.alias() != source.url().asString() )
- cout << source.alias() << " (" << source.url() << ")" << endl;
- else
- cout << source.url() << endl;
+ TableRow tr;
+ tr << ( source.enabled() ? "[x]" : "[ ]" );
+ tr << ( source.autorefresh() ? "* " : " " );
+ tr << source.alias();
+ tr << source.url().asString();
+ tbl << tr;
}
+ cout << tbl;
/*
Sub'd? | Name | Service
exit(-1);
}
- print_source_list(sources);
+ print_source_list_rug_style(sources);
}
static
#include "zypp/Url.h"
+//! calls init_system_sources if not disabled by user (or non-root)
+void cond_init_system_sources();
void init_system_sources();
void include_source_by_url( const zypp::Url &url );
void add_source_by_url( const zypp::Url &url, std::string alias );
--- /dev/null
+#include <iostream>
+#include "zypper-tabulator.h"
+using namespace std;
+
+void TableRow::add (const string& s) {
+ _columns.push_back (s);
+}
+
+// 1st implementation: no width calculation, just tabs
+void TableRow::dumbDumpTo (ostream &stream) const {
+ bool seen_first = false;
+ for (container::const_iterator i = _columns.begin (); i != _columns.end (); ++i) {
+ if (seen_first)
+ stream << '\t';
+ seen_first = true;
+
+ stream << *i;
+ }
+ stream << endl;
+}
+
+void TableRow::dumpTo (ostream &stream, const vector<unsigned>& widths) const {
+ const char* separator = " | ";
+ bool seen_first = false;
+ container::const_iterator
+ i = _columns.begin (),
+ e = _columns.end ();
+
+ stream.setf (ios::left, ios::adjustfield);
+ for (unsigned c = 0; i != e ; ++i, ++c) {
+ if (seen_first) {
+ stream.width (0);
+ stream << separator;
+ }
+ seen_first = true;
+
+ stream.width (widths[c]);
+ stream << *i;
+ }
+ stream << endl;
+}
+
+void Table::add (const TableRow& tr) {
+ _rows.push_back (tr);
+
+ // update column widths
+ TableRow::container::const_iterator
+ i = tr._columns.begin (),
+ e = tr._columns.end ();
+ for (unsigned c = 0; i != e; ++i, ++c) {
+ // ensure that _max_width[c] exists
+ if (_max_col < c)
+ _max_col = c;
+ _max_width.resize (_max_col + 1);
+
+ unsigned &max = _max_width[c];
+ // FIXME: i18n: screen columns
+ unsigned cur = i->length();
+ if (max < cur)
+ max = cur;
+ }
+}
+
+// 1st implementation: no width calculation, just tabs
+void Table::dumpTo (ostream &stream) const {
+ container::const_iterator
+ b = _rows.begin (),
+ e = _rows.end (),
+ i;
+ for (i = b; i != e; ++i) {
+ i->dumpTo (stream, _max_width);
+ }
+}
--- /dev/null
+/*-----------------------------------------------------------*- c++ -*-\
+| ____ _ __ __ ___ |
+| |__ / \ / / . \ . \ |
+| / / \ V /| _/ _/ |
+| / /__ | | | | | | |
+| /_____||_| |_| |_| |
+| |
+\---------------------------------------------------------------------*/
+
+#ifndef ZYPPER_TABULATOR_H
+#define ZYPPER_TABULATOR_H
+
+#include <string>
+#include <iosfwd>
+#include <list>
+#include <vector>
+using std::string;
+using std::ostream;
+using std::list;
+using std::vector;
+
+class TableRow {
+public:
+ void add (const string& s);
+
+ //! tab separated output
+ void dumbDumpTo (ostream &stream) const;
+ //! output with field widths
+ void dumpTo (ostream &stream, const vector<unsigned>& widths) const;
+
+ typedef list<string> container;
+private:
+ container _columns;
+ friend class Table;
+};
+
+inline
+TableRow& operator << (TableRow& tr, const string& s) {
+ tr.add (s);
+ return tr;
+}
+
+class Table {
+public:
+ void add (const TableRow& tr);
+ void dumpTo (ostream& stream) const;
+
+ typedef list<TableRow> container;
+private:
+ container _rows;
+ //! maximum column index seen in this table
+ unsigned _max_col;
+ //! maximum width of respective columns
+ vector<unsigned> _max_width;
+};
+
+inline
+Table& operator << (Table& table, const TableRow& tr) {
+ table.add (tr);
+ return table;
+}
+
+inline
+ostream& operator << (ostream& stream, const Table& table) {
+ table.dumpTo (stream);
+ return stream;
+}
+
+#endif
{"verbose", no_argument, 0, 'v'},
{"version", no_argument, 0, 'V'},
{"terse", no_argument, 0, 't'},
- {"req", required_argument, 0, 'r'},
{"opt", optional_argument, 0, 'o'},
{0, 0, 0, 0}
};
cerr << endl;
}
- // testing option
- if (gopts.count("req")) {
- cerr << "Req arg: ";
- std::copy (gopts["req"].begin(), gopts["req"].end(),
- ostream_iterator<string> (cerr, ", "));
- cerr << endl;
- }
-
string command;
if (optind < argc) {
"\tservice-add, sa\t\tAdd a new service\n"
"\tservice-delete, sd\tDelete a service\n"
"\tservice-rename, sr\tRename a service\n"
+ "\tpatch-check,pchk\tCheck for patches\n"
;
string help_global_source_options = " Source options:\n"
ZYPP_CAUGHT (excpt_r);
ERR << "a ZYpp transaction is already in progress." << endl;
cerr << "a ZYpp transaction is already in progress." << endl;
- cout << RANDOM_TOKEN;
return 1;
}
return 1;
}
- std::string previous_token;
-
- SourceManager_Ptr manager;
- manager = SourceManager::sourceManager();
-
KeyRingCallbacks keyring_callbacks;
DigestCallbacks digest_callbacks;
-
- if ( geteuid() != 0 )
- {
- cerr << "Sorry, you need root privileges to use system sources, disabling them..." << endl;
- gSettings.disable_system_sources = true;
- MIL << "system sources disabled" << endl;
- }
- if ( ! gSettings.disable_system_sources ) {
- cerr_v << "initializing sources" << endl;
- init_system_sources();
- }
-
+ cond_init_system_sources ();
+
for ( std::list<Url>::const_iterator it = gSettings.additional_sources.begin(); it != gSettings.additional_sources.end(); ++it )
{
include_source_by_url( *it );
cerr_v << "calculating token" << endl;
std::string token = calculate_token();
+ cerr_v << "token:" << token << endl;
if ( token != gSettings.previous_token )
{
- // something changed
- cerr_v << "loading sources" << endl;
- load_sources();
-
- if ( ! gSettings.disable_system_resolvables ) {
- cerr_v << "loading target" << endl;
- load_target();
- }
+ cond_load_resolvables ();
for ( vector<string>::const_iterator it = gData.packages_to_install.begin(); it != gData.packages_to_install.end(); ++it ) {
mark_for_install(kind, *it);
cerr << result << std::endl;
}
}
+ else {
+ cerr_v << "Token unchanged" << endl;
+ }
+ return 0;
}
+
+ if (command == "patch-check" || command == "pchk") {
+ KeyRingCallbacks keyring_callbacks;
+ DigestCallbacks digest_callbacks;
+
+ cond_init_system_sources ();
+ // TODO additional_sources
+ // TODO warn_no_sources
+
+ // dont add rpms
+ cerr_v << "initializing target" << endl;
+ God->initializeTarget("/");
+ // TODO calc token?
+
+ // now load resolvables:
+
+ cond_load_resolvables ();
+
+ establish ();
+ show_pool ();
+ }
+
return 0;
}