Skip to content

Commit

Permalink
products --xmlfwd: Literally forward the XML tags found in a product …
Browse files Browse the repository at this point in the history
…file (FATE#320699)
  • Loading branch information
mlandres committed Sep 9, 2016
1 parent dbcdf13 commit 5e85116
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 5 deletions.
32 changes: 30 additions & 2 deletions doc/zypper.8
Expand Up @@ -2,12 +2,12 @@
.\" Title: zypper
.\" Author: [see the "AUTHORS" section]
.\" Generator: DocBook XSL Stylesheets v1.78.1 <http://docbook.sf.net/>
.\" Date: 08/12/2016
.\" Date: 09/09/2016
.\" Manual: ZYPPER
.\" Source: SUSE Linux
.\" Language: English
.\"
.TH "ZYPPER" "8" "08/12/2016" "SUSE Linux" "ZYPPER"
.TH "ZYPPER" "8" "09/09/2016" "SUSE Linux" "ZYPPER"
.\" -----------------------------------------------------------------
.\" * Define some portability stuff
.\" -----------------------------------------------------------------
Expand Down Expand Up @@ -1579,6 +1579,34 @@ Show only products which are not installed\&.

The old option name \-\-uninstalled\-only is still acceptable, but should be considered deprecated\&.
.RE
.PP
\fB\-\-xmlfwd\fR \fItag\fR
.RS 4
XML output only: Literally forward the XML
\fItag\fR, if it is found in an installed products \&.prod\-file (in
\fB/etc/products\&.d\fR)\&.

Using this option, for each installed product an
\fB<xmlfwd>\fR
node will be created inside the
\fB<product>\fR
output node of the product\&.

Tag defines the name (or
\fI/\fR\-separated path) of a xml\-tag inside an installed products \&.prod\-file\&. If the tag is present inside the products \&.prod\-file, the tag and it\(cqs content is literally forwarded into the products
\fB<xmlfwd>\fR
output node\&.

The option may be specified multiple times\&.
.RE
.PP
Examples:
.RS 4
.PP
$ \fBzypper \-x pd \-\-xmlfwd name \-\-xmlfwd register/target\fR
.RS 4
.RE
.RE
.RE
.PP
\fBwhat\-provides\fR (\fBwp\fR) \fIcapability\fR
Expand Down
14 changes: 14 additions & 0 deletions doc/zypper.8.txt
Expand Up @@ -848,6 +848,20 @@ Query Commands
Show only products which are not installed.
+
The old option name --uninstalled-only is still acceptable, but should be considered deprecated.

*--xmlfwd* 'tag'::
XML output only: Literally forward the XML 'tag', if it is found in an installed products .prod-file (in */etc/products.d*).
+
Using this option, for each installed product an *<xmlfwd>* node will be created inside the *<product>* output node of the product.
+
Tag defines the name (or '/'-separated path) of a xml-tag inside an installed products .prod-file. If the tag is present inside the products .prod-file, the tag and it's content is literally forwarded into the products *<xmlfwd>* output node.
+
The option may be specified multiple times.

Examples: :: {nop}

$ *zypper -x pd --xmlfwd name --xmlfwd register/target*;;
{nop}
--

*what-provides* (*wp*) 'capability'::
Expand Down
13 changes: 10 additions & 3 deletions src/Zypper.cc
Expand Up @@ -2577,11 +2577,13 @@ void Zypper::processCommandOptions()
// rug compatibility option, we have --repo
{"catalog", required_argument, 0, 'c'},
ARG_not_INSTALLED_ONLY,
{"xmlfwd", required_argument, 0, 0 },
{"help", no_argument, 0, 'h'},
{0, 0, 0, 0}
};
specific_options = options;
_command_help = _(
_command_help = ( CommandHelpFormater()
<< _(
"products (pd) [options] [repository] ...\n"
"\n"
"List all products available in specified repositories.\n"
Expand All @@ -2590,8 +2592,9 @@ void Zypper::processCommandOptions()
"\n"
"-r, --repo <alias|#|URI> Just another means to specify repository.\n"
"-i, --installed-only Show only installed products.\n"
"-u, --not-installed-only Show only products which are not installed.\n"
);
"-u, --not-installed-only Show only products which are not installed.\n") )
.option26( "--xmlfwd <tag>", _("XML output only: Literally forward the XML tags found in a product file.") )
;
break;
}

Expand Down Expand Up @@ -4516,6 +4519,10 @@ void Zypper::doCommand()
list_packages( *this );
break;
case ZypperCommand::PRODUCTS_e:
if ( copts.count("xmlfwd") && out().type() != Out::TYPE_XML )
{
out().warning( str::Format(_("Option %1% has no effect without the %2% global option.")) % "--xmlfwd" % "--xmlout" );
}
list_products( *this );
break;
default:;
Expand Down
21 changes: 21 additions & 0 deletions src/utils/misc.cc
Expand Up @@ -29,6 +29,7 @@
#include "repos.h"

#include "utils/misc.h"
#include "utils/XmlFilter.h"

extern ZYpp::Ptr God;

Expand Down Expand Up @@ -617,6 +618,26 @@ std::string asXML( const Product & p, bool is_installed )
if ( ! text.empty() )
*xmlout::Node( *parent, "description" ) << xml::escape( text );
}

if ( is_installed && copts.count("xmlfwd") )
{
// literally forward tags found in the .prod file...
xmlout::Node fwd( *parent, "xmlfwd", xmlout::Node::optionalContent );

std::vector<std::string> tags;
for ( const auto & tag : copts["xmlfwd"] )
{ tags.push_back( Pathname::assertprefix( "/product", tag ).asString() ); }

const Pathname & proddir( Pathname::assertprefix( Zypper::instance()->globalOpts().root_dir, "/etc/products.d" ) );
try
{
XmlFilter::fwd( InputStream( proddir+p.referenceFilename() ), *fwd, std::move(tags) );
}
catch ( const Exception & exp )
{
ZYPP_CAUGHT( exp ); // parse error
}
}
}
return str.str();
}
Expand Down

0 comments on commit 5e85116

Please sign in to comment.