98_search: add cmd for metadata search

git-svn-id: https://svn.fhem.de/fhem/trunk/fhem@19004 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
jpawlowski 2019-03-23 14:44:44 +00:00
parent 3367f72bf7
commit e7aaa6b3f6
3 changed files with 174 additions and 27 deletions

View File

@ -131,7 +131,7 @@ sub Undef($$) {
RemoveInternalTimer($hash);
delete( $modules{installer}{defptr}{ $hash->{HOST} } );
delete( $modules{ $hash->{TYPE} }{defptr}{localhost} );
return undef;
}
@ -958,12 +958,14 @@ sub CreateSearchList ($$$) {
if ( $device =~ m/^.*$search.*$/i ) {
unless ($foundDevices) {
push @ret, '<a name="searchResultDevices"></a><h3>Devices</h3>' . $lb;
push @ret, $tableOpen;
push @ret,
'<a name="searchResultDevices"></a><h3>Devices</h3>' . $lb;
push @ret, $tableOpen . $rowOpen;
push @ret,
$colOpen . $txtOpen . 'Device Name' . $txtClose . $colClose;
push @ret,
$colOpen . $txtOpen . 'Device Type' . $txtClose . $colClose;
push @ret, $rowClose;
}
$found++;
$foundDevices++;
@ -1007,12 +1009,14 @@ sub CreateSearchList ($$$) {
foreach my $module ( sort { "\L$a" cmp "\L$b" } keys %modules ) {
if ( $module =~ m/^.*$search.*$/i ) {
unless ($foundModules) {
push @ret, '<a name="searchResultModules"></a><h3>Modules</h3>' . $lb;
push @ret, $tableOpen;
push @ret,
'<a name="searchResultModules"></a><h3>Modules</h3>' . $lb;
push @ret, $tableOpen . $rowOpen;
push @ret,
$colOpen . $txtOpen . 'Module Name' . $txtClose . $colClose;
push @ret,
$colOpen . $txtOpen . 'Abstract' . $txtClose . $colClose;
push @ret, $rowClose;
}
$found++;
$foundModules++;
@ -1054,12 +1058,14 @@ sub CreateSearchList ($$$) {
foreach my $package ( sort { "\L$a" cmp "\L$b" } keys %packages ) {
if ( $package =~ m/^.*$search.*$/i ) {
unless ($foundPackages) {
push @ret, '<a name="searchResultPackages"></a><h3>Packages</h3>' . $lb;
push @ret, $tableOpen;
push @ret,
'<a name="searchResultPackages"></a><h3>Packages</h3>' . $lb;
push @ret, $tableOpen . $rowOpen;
push @ret,
$colOpen . $txtOpen . 'Package Name' . $txtClose . $colClose;
push @ret,
$colOpen . $txtOpen . 'Abstract' . $txtClose . $colClose;
push @ret, $rowClose;
}
$found++;
$foundPackages++;
@ -1102,7 +1108,8 @@ sub CreateSearchList ($$$) {
my $keyword ( sort { "\L$a" cmp "\L$b" } keys %FHEM::Meta::keywords )
{
if ( $keyword =~ m/^.*$search.*$/i ) {
push @ret, '<a name="searchResultKeywords"></a><h3>Keywords</h3>' unless ($foundKeywords);
push @ret, '<a name="searchResultKeywords"></a><h3>Keywords</h3>'
unless ($foundKeywords);
$found++;
$foundKeywords++;
@ -1117,7 +1124,7 @@ sub CreateSearchList ($$$) {
packages
);
push @ret, $tableOpen;
push @ret, $tableOpen . $rowOpen;
push @ret, $colOpen . $txtOpen . 'Name' . $txtClose . $colClose;
@ -1125,6 +1132,8 @@ sub CreateSearchList ($$$) {
push @ret, $colOpen . $txtOpen . 'Abstract' . $txtClose . $colClose;
push @ret, $rowClose;
foreach my $mAttr (@mAttrs) {
next
unless ( defined( $FHEM::Meta::keywords{$keyword}{$mAttr} )
@ -1189,13 +1198,16 @@ sub CreateSearchList ($$$) {
{
if ( $maintainer =~ m/^.*$search.*$/i ) {
unless ($foundMaintainers) {
push @ret, '<a name="searchResultMaintainers"></a><h3>Authors & Maintainers</h3>' . $lb;
push @ret, $tableOpen;
push @ret,
'<a name="searchResultMaintainers"></a><h3>Authors & Maintainers</h3>'
. $lb;
push @ret, $tableOpen . $rowOpen;
push @ret, $colOpen . $txtOpen . 'Name' . $txtClose . $colClose;
push @ret,
$colOpen . $txtOpen . 'Modules' . $txtClose . $colClose;
push @ret,
$colOpen . $txtOpen . 'Packages' . $txtClose . $colClose;
push @ret, $rowClose;
}
$found++;
$foundMaintainers++;
@ -1275,8 +1287,9 @@ sub CreateSearchList ($$$) {
if ( $dependent =~ m/^.*$search.*$/i ) {
unless ($foundPerl) {
push @ret, '<a name="searchResultPerl"></a><h3>Perl packages</h3>' . $lb;
push @ret, $tableOpen;
push @ret,
'<a name="searchResultPerl"></a><h3>Perl packages</h3>' . $lb;
push @ret, $tableOpen . $rowOpen;
push @ret, $colOpen . $txtOpen . 'Name' . $txtClose . $colClose;
push @ret,
$colOpen
@ -1284,6 +1297,7 @@ sub CreateSearchList ($$$) {
. 'Referenced from'
. $txtClose
. $colClose;
push @ret, $rowClose;
}
$found++;
$foundPerl++;
@ -1343,8 +1357,8 @@ sub CreateSearchList ($$$) {
. $space
. ( $html ? '<a href="#searchResultPerl">' : '' )
. $foundPerl . ' '
. ( $foundPerl > 1 ? 'Perl modules' : 'Perl module' )
. ( $html ? '</a>' : '' )
. ( $foundPerl > 1 ? 'Perl packages' : 'Perl package' )
. ( $html ? '</a>' : '' )
if ($foundPerl);
unshift @ret,
$lb
@ -1353,7 +1367,7 @@ sub CreateSearchList ($$$) {
. ( $html ? '<a href="#searchResultMaintainers">' : '' )
. $foundMaintainers . ' '
. ( $foundMaintainers > 1 ? 'authors' : 'author' )
. ( $html ? '</a>' : '' )
. ( $html ? '</a>' : '' )
if ($foundMaintainers);
unshift @ret,
$lb
@ -1397,7 +1411,8 @@ sub CreateSearchList ($$$) {
else {
unshift @ret, 'Nothing found';
}
unshift @ret, '<a name="searchResultTOP"></a><h2>Search result: ' . $search . '</h2>';
unshift @ret,
'<a name="searchResultTOP"></a><h2>Search result: ' . $search . '</h2>';
return $header . join( "\n", @ret ) . $footer;
}
@ -2240,7 +2255,7 @@ m/^([^<>\n\r]+?)(?:\s+(\(last release only\)))?(?:\s+(?:<(.*)>))?$/
. $lb
. $lb;
push @ret, $tableOpen;
push @ret, $tableOpen . $rowOpen;
push @ret,
$colOpen . $txtOpen . 'Importance' . $txtClose . $colClose;
@ -2251,6 +2266,8 @@ m/^([^<>\n\r]+?)(?:\s+(\(last release only\)))?(?:\s+(?:<(.*)>))?$/
. 'Dependent Modules'
. $txtClose
. $colClose;
push @ret, $rowClose;
}
my $l = $linecount % 2 == 0 ? $rowOpenEven : $rowOpenOdd;
@ -2310,7 +2327,7 @@ m/^([^<>\n\r]+?)(?:\s+(\(last release only\)))?(?:\s+(?:<(.*)>))?$/
suggests
);
push @ret, $tableOpen;
push @ret, $tableOpen . $rowOpen;
push @ret, $colOpen . $txtOpen . 'Name' . $txtClose . $colClose;
@ -2318,6 +2335,8 @@ m/^([^<>\n\r]+?)(?:\s+(\(last release only\)))?(?:\s+(?:<(.*)>))?$/
push @ret, $colOpen . $txtOpen . 'Status' . $txtClose . $colClose;
push @ret, $rowClose;
$linecount = 1;
foreach my $mAttr (@mAttrs) {
next
@ -2455,7 +2474,7 @@ m/^([^<>\n\r]+?)(?:\s+(\(last release only\)))?(?:\s+(?:<(.*)>))?$/
suggests
);
push @ret, $tableOpen;
push @ret, $tableOpen . $rowOpen;
push @ret, $colOpen . $txtOpen . 'Name' . $txtClose . $colClose;
@ -2463,6 +2482,8 @@ m/^([^<>\n\r]+?)(?:\s+(\(last release only\)))?(?:\s+(?:<(.*)>))?$/
push @ret, $colOpen . $txtOpen . 'Status' . $txtClose . $colClose;
push @ret, $rowClose;
$linecount = 1;
foreach my $mAttr (@mAttrs) {
next
@ -2555,7 +2576,7 @@ m/^([^<>\n\r]+?)(?:\s+(\(last release only\)))?(?:\s+(?:<(.*)>))?$/
suggests
);
push @ret, $tableOpen;
push @ret, $tableOpen . $rowOpen;
push @ret, $colOpen . $txtOpen . 'Name' . $txtClose . $colClose;
@ -2563,6 +2584,8 @@ m/^([^<>\n\r]+?)(?:\s+(\(last release only\)))?(?:\s+(?:<(.*)>))?$/
push @ret, $colOpen . $txtOpen . 'Status' . $txtClose . $colClose;
push @ret, $rowClose;
$linecount = 1;
foreach my $mAttr (@mAttrs) {
next

123
FHEM/98_search.pm Executable file
View File

@ -0,0 +1,123 @@
# $Id$
package main;
use strict;
use warnings;
use FHEM::Meta;
sub search_Initialize($$) {
my ($modHash) = @_;
my %hash = (
Fn => "FHEM::search::run",
Hlp => "<search expression>",
);
$cmds{search} = \%hash;
return FHEM::Meta::InitMod( __FILE__, $modHash );
}
# define package
package FHEM::search;
use strict;
use warnings;
use POSIX;
use GPUtils qw(GP_Import);
# Run before module compilation
BEGIN {
# Import from main::
GP_Import(
qw(
modules
defs
fhem
)
);
}
sub run {
my ( $cl, $search ) = @_;
my $hash;
my $name = 'fhemInstaller';
if ( defined( $modules{Installer} )
&& defined( $modules{Installer}{defptr} )
&& defined( $modules{Installer}{defptr}{localhost} ) )
{
$hash = $modules{Installer}{defptr}{localhost};
}
else {
my $no = 1;
my $newname = $name;
while ( defined( $defs{$newname} ) ) {
$newname = $name . $no++;
}
fhem "define $newname Installer";
$hash = $modules{Installer}{defptr}{localhost};
}
return 'Not a hash reference: ' unless ( $hash && ref($hash) eq 'HASH' );
$name = $hash->{NAME};
$hash->{CL} = $cl if ($cl);
my $ret = FHEM::Installer::Get( $hash, $name, 'search', $search );
delete $hash->{CL} if ($cl);
return $ret;
}
1;
=pod
=encoding utf8
=item command
=item summary Search through this FHEM instance
=item summary_DE Durchsucht die FHEM Instanz
=begin html
<a name="search"></a>
<h3>search</h3>
<ul>
<code>search &lt;search expression&gt;</code>
<br />
Searches FHEM for devices, modules, developer packages, keywords, authors/maintainers and Perl packages.<br />
This command requires a device instance of the FHEM Installer module. If no local Installer device is present,
the first run of this command will create one.<br />
<br />
Have a look to the 'Get search' command of the FHEM Installer to learn more about how to search.
</ul>
=end html
=begin html_DE
<a name="search"></a>
<h3>search</h3>
<ul>
<code>search &lt;Suchausdruck&gt;</code>
<br />
Durchsucht FHEM nach Ger&auml;ten, Modulen, Entwickler Paketen, Schl&uuml;sselw&ouml;rtern und Perl Paketen.<br />
Dieses Kommando ben&ouml;tigt eine Ger&auml;teinstanz des FHEM Installer Moduls. Sofern kein lokales Installer Ger&auml;t
vorhanden ist, wird beim ersten ausf&uuml;hren dieses Kommandos eines angelegt.<br />
<br />
Das 'Get search' Kommando des FHEM Installer verr&auml;t mehr dar&auml;ber, wie die Suche funktioniert.
</ul>
=end html_DE
=for :application/json;q=META.json 98_search.pm
{
"version": "v0.9.0",
"author": [
"Julian Pawlowski <julian.pawlowski@gmail.com>"
],
"x_fhem_maintainer": [
"loredo"
],
"x_fhem_maintainer_github": [
"jpawlowski"
]
}
=end :application/json;q=META.json
=cut

View File

@ -260,7 +260,7 @@ FHEM/49_IPCAM.pm mfr69bs Sonstiges
FHEM/49_SSCam.pm DS_Starter Sonstiges
FHEM/49_SSCamSTRM.pm DS_Starter Sonstiges
FHEM/49_TBot_List.pm viegener Unterstuetzende Dienste
FHEM/50_HP1000.pm loredo Unterstuetzende Dienste/Wettermodule
FHEM/50_HP1000.pm loredo Unterstützende Dienste/Wettermodule
FHEM/50_MOBILEALERTSGW.pm MarkusF Sonstige Systeme
FHEM/50_TelegramBot.pm viegener Unterstuetzende Dienste
FHEM/50_WS300.pm Dirk SlowRF
@ -300,7 +300,7 @@ FHEM/59_OPENWEATHER.pm tupol Unterstuetzende Dienste/Wetter
FHEM/59_PROPLANTA.pm tupol Unterstuetzende Dienste/Wettermodule (Link als PM an tupol)
FHEM/59_Twilight.pm jeschkec Unterstuetzende Dienste/Wettermodule
FHEM/59_Weather.pm neubert Unterstuetzende Dienste/Wettermodule
FHEM/59_Wunderground.pm loredo Unterstuetzende Dienste/Wettermodule
FHEM/59_Wunderground.pm loredo Unterstützende Dienste/Wettermodule
FHEM/59_WUup.pm mahowi Unterstuetzende Dienste/Wettermodule
FHEM/59_WWO.pm baumrasen Unterstuetzende Dienste/Wettermodule
FHEM/60_allergy.pm markus-m Unterstuetzende Dienste
@ -326,7 +326,7 @@ FHEM/70_PHTV.pm loredo Multimedia
FHEM/70_PIONEERAVR.pm 50watt Multimedia
FHEM/70_Pushbullet.pm fhainz Unterstuetzende Dienste
FHEM/70_PushNotifier.pm xusader Unterstuetzende Dienste
FHEM/70_Pushover.pm loredo Unterstuetzende Dienste
FHEM/70_Pushover.pm loredo Unterstützende Dienste
FHEM/70_Pushsafer.pm markusbloch Unterstuetzende Dienste
FHEM/70_SCIVT.pm rudolfkoenig/orphan Sonstiges
FHEM/70_SISPM.pm real-wusel Sonstiges
@ -368,7 +368,7 @@ FHEM/74_HOMBOT.pm CoolTux sonstige Systeme
FHEM/74_HusqvarnaAutomower.pm krannich Sonstige Systeme
FHEM/74_Nmap.pm igami Unterstuetzende Dienste
FHEM/74_NUKIDevice.pm CoolTux Sonstige Systeme
FHEM/74_THINKINGCLEANER.pm loredo Unterstuetzende Dienste
FHEM/74_THINKINGCLEANER.pm loredo Unterstützende Dienste
FHEM/74_Unifi.pm rapster/wuehler Automatisierung
FHEM/74_UnifiSwitch.pm wuehler Automatisierung
FHEM/74_UnifiVideo.pm justme1968 Sonstiges
@ -466,7 +466,7 @@ FHEM/98_fheminfo.pm betateilchen Sonstiges
FHEM/98_freezemon KernSani Unterstuetzende Dienste
FHEM/98_FReplacer.pm StefanStrobel Sonstiges
FHEM/98_GAEBUS.pm jamesgo Heizungssteuerung/Raumklima
FHEM/98_GEOFANCY.pm loredo Unterstuetzende Dienste
FHEM/98_GEOFANCY.pm loredo Unterstützende Dienste
FHEM/98_GoogleAuth.pm betateilchen Unterstuetzende Dienste
FHEM/98_GOOGLECAST.pm dominikkarall Multimedia
FHEM/98_Heating_Control.pm igami Unterstuetzende Dienste
@ -477,10 +477,11 @@ FHEM/98_HTTPMOD.pm StefanStrobel Sonstiges
FHEM/98_Hyperion.pm DeeSPe Beleuchtung
FHEM/98_IF.pm damian-s Automatisierung
FHEM/98_inotify.pm marvin78 Automatisierung
FHEM/98_Installer.pm loredo Unterstuetzende Dienste
FHEM/98_Installer.pm loredo Unterstützende Dienste
FHEM/98_JsonList2.pm rudolfkoenig Automatisierung
FHEM/98_livetracking.pm markus-m Unterstuetzende Dienste
FHEM/98_logProxy.pm justme1968 Frontends/SVG Plots logProxy
FHEM/98_search.pm loredo Unterstützende Dienste
FHEM/98_MaxScanner.pm john MAX
FHEM/98_MediaList.pm Tobias Multimedia
FHEM/98_Modbus.pm StefanStrobel Sonstiges