Add tool/DumpSelectable
[platform/upstream/libzypp.git] / tools / patch_find_bug.cc
1 #define INCLUDE_TESTSETUP_WITHOUT_BOOST
2 #include "zypp/../tests/lib/TestSetup.h"
3 #undef  INCLUDE_TESTSETUP_WITHOUT_BOOST
4
5 #include "zypp/PoolQuery.h"
6
7 using namespace zypp;
8 using std::flush;
9
10 static std::string appname( "patch_find_bug" );
11
12 int errexit( const std::string & msg_r = std::string(), int exit_r = 101 )
13 {
14   if ( ! msg_r.empty() )
15   {
16     cerr << endl << msg_r << endl << endl;
17   }
18   return exit_r;
19 }
20
21
22 int usage( const std::string & msg_r = std::string(), int exit_r = 100 )
23 {
24   if ( ! msg_r.empty() )
25   {
26     cerr << endl << msg_r << endl << endl;
27   }
28   cerr << "Usage: " << appname << "[OPTIONS] bugnumber..." << endl;
29   cerr << "  Find patches refering to bugnumber (substring)." << endl;
30   cerr << "  --root SYSROOT: Load system located below directory SYSROOT" << endl;
31   return exit_r;
32 }
33
34 /******************************************************************
35 **
36 **      FUNCTION NAME : main
37 **      FUNCTION TYPE : int
38 */
39 int main( int argc, char * argv[] )
40 {
41   INT << "===[START]==========================================" << endl;
42   appname = Pathname::basename( argv[0] );
43   --argc;
44   ++argv;
45
46   if ( ! argc )
47   {
48     return usage();
49   }
50
51   ///////////////////////////////////////////////////////////////////
52
53   ZConfig::instance();
54   Pathname sysRoot("/");
55
56   if ( (*argv) == std::string("--root") )
57   {
58     --argc,++argv;
59     if ( ! argc )
60       return errexit("--root requires an argument.");
61
62     if ( ! PathInfo( *argv ).isDir() )
63       return errexit("--root requires a directory.");
64
65     sysRoot = *argv;
66     --argc,++argv;
67   }
68
69   TestSetup::LoadSystemAt( sysRoot );
70
71   for ( ; argc; --argc,++argv )
72   {
73     PoolQuery q;
74     q.setMatchSubstring();
75     q.setCaseSensitive( false );
76     q.addAttribute( sat::SolvAttr::updateReferenceId, *argv );
77
78     if ( q.empty() )
79     {
80       cout << "BUG REFERENCE '" << *argv << "': No match found." << endl;
81     }
82     else
83     {
84       cout << "BUG REFERENCE '" << *argv << endl;
85       for_( it , q.begin(), q.end() )
86       {
87         // print the solvable that has a match:
88         cout << "  - " << *it << endl;
89
90         if ( true )
91         {
92           // Print details about each match in that solvable:
93           for_( d, it.matchesBegin(), it.matchesEnd() )
94           {
95             // directly access specific attribute like "subFind(updateReferenceType)":
96             cout << "    - " << d->inSolvAttr() << "\t\"" << d->asString() << "\" has type \""
97                 << d->subFind( sat::SolvAttr::updateReferenceType ).asString() << "\"" << endl;
98
99             // list the whole updateReference structure:
100             for_( s, d->subBegin(), d->subEnd() )
101             {
102               cout << "       -" << s.inSolvAttr() << "\t\"" << s.asString() << "\"" << endl;
103             }
104           }
105         }
106       }
107     }
108   }
109
110   ///////////////////////////////////////////////////////////////////
111   INT << "===[END]============================================" << endl << endl;
112   return 0;
113 }