From ae5e229735e4c1f07c9d061ef56987582f1eaf4c Mon Sep 17 00:00:00 2001 From: jpawlowski Date: Sat, 23 Mar 2019 14:44:44 +0000 Subject: [PATCH] 98_search: add cmd for metadata search git-svn-id: https://svn.fhem.de/fhem/trunk@19004 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/FHEM/98_Installer.pm | 65 +++++++++++++------- fhem/FHEM/98_search.pm | 123 ++++++++++++++++++++++++++++++++++++++ fhem/MAINTAINER.txt | 13 ++-- 3 files changed, 174 insertions(+), 27 deletions(-) create mode 100755 fhem/FHEM/98_search.pm diff --git a/fhem/FHEM/98_Installer.pm b/fhem/FHEM/98_Installer.pm index 383ee91ba..ff9279748 100644 --- a/fhem/FHEM/98_Installer.pm +++ b/fhem/FHEM/98_Installer.pm @@ -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, '

Devices

' . $lb; - push @ret, $tableOpen; + push @ret, + '

Devices

' . $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, '

Modules

' . $lb; - push @ret, $tableOpen; + push @ret, + '

Modules

' . $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, '

Packages

' . $lb; - push @ret, $tableOpen; + push @ret, + '

Packages

' . $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, '

Keywords

' unless ($foundKeywords); + push @ret, '

Keywords

' + 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, '

Authors & Maintainers

' . $lb; - push @ret, $tableOpen; + push @ret, +'

Authors & Maintainers

' + . $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, '

Perl packages

' . $lb; - push @ret, $tableOpen; + push @ret, + '

Perl packages

' . $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 ? '' : '' ) . $foundPerl . ' ' - . ( $foundPerl > 1 ? 'Perl modules' : 'Perl module' ) - . ( $html ? '' : '' ) + . ( $foundPerl > 1 ? 'Perl packages' : 'Perl package' ) + . ( $html ? '' : '' ) if ($foundPerl); unshift @ret, $lb @@ -1353,7 +1367,7 @@ sub CreateSearchList ($$$) { . ( $html ? '' : '' ) . $foundMaintainers . ' ' . ( $foundMaintainers > 1 ? 'authors' : 'author' ) - . ( $html ? '' : '' ) + . ( $html ? '' : '' ) if ($foundMaintainers); unshift @ret, $lb @@ -1397,7 +1411,8 @@ sub CreateSearchList ($$$) { else { unshift @ret, 'Nothing found'; } - unshift @ret, '

Search result: ' . $search . '

'; + unshift @ret, + '

Search result: ' . $search . '

'; 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 diff --git a/fhem/FHEM/98_search.pm b/fhem/FHEM/98_search.pm new file mode 100755 index 000000000..af3d7cebb --- /dev/null +++ b/fhem/FHEM/98_search.pm @@ -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 => "", + ); + $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 + + +

search

+ + +=end html + +=begin html_DE + + +

search

+ + +=end html_DE + +=for :application/json;q=META.json 98_search.pm +{ + "version": "v0.9.0", + "author": [ + "Julian Pawlowski " + ], + "x_fhem_maintainer": [ + "loredo" + ], + "x_fhem_maintainer_github": [ + "jpawlowski" + ] +} +=end :application/json;q=META.json + +=cut diff --git a/fhem/MAINTAINER.txt b/fhem/MAINTAINER.txt index 4d839385c..d0edf7ec6 100644 --- a/fhem/MAINTAINER.txt +++ b/fhem/MAINTAINER.txt @@ -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