# $Id$ package main; use strict; use warnings; sub version_Initialize($$) { $cmds{version} = { Fn => "CommandVersion", Hlp=>"[] [noheader],print SVN version of loaded modules"}; } ##################################### sub CommandVersion($$) { my ($cl, $param) = @_; my $noheader = ($param =~ s/(?:^\s*|\s+)noheader\s*$//); eval { "test" =~ /$param/ }; return "invalid filter regexp" if($@); my @ret; my $max = 0; my $modpath = (exists($attr{global}{modpath}) ? $attr{global}{modpath} : ""); my @files = map {$INC{$_}} keys %INC; push @files, $0; # path to fhem.pl push @ret, cfgDB_svnId() if(configDBUsed()); foreach my $fn (@files) { next unless($fn =~ /^(?:$modpath.?)?FHEM/ or $fn =~ /fhem.pl$/); # configDB my $mod_name = ($fn=~ /[\/\\]([^\/\\]+)$/ ? $1 : $fn); next if($param ne "" && $mod_name !~ /$param/); next if(grep(/$mod_name/, @ret)); Log 4, "Looking for SVN Id in module $mod_name"; $max = length($mod_name) if($max < length($mod_name)); my $line; if(!open(FH, $fn)) { $line = "$fn: $!"; if(configDBUsed()){ Log 4, "Looking for module $mod_name in configDB to find SVN Id"; $line = cfgDB_Fileversion($fn,$line); } } else { while() { if(/#.*\$Id\:[^\$\n\r].+\$/) { $line = $_; last; } } close(FH); } $line = "No Id found for $mod_name" unless($line); push @ret, $line; } @ret = map {/\$Id\: (\S+) (\S+) (.+?) \$/ ? sprintf("%-".$max."s %5d %s",$1,$2,$3) : $_} @ret; @ret = sort {version_sortModules($a, $b)} grep {($param ne "" ? $_ =~ /$param/ : 1)} @ret; return "no loaded modules found that match: $param" if($param ne "" && !@ret); return ($noheader ? "" : sprintf("%-".$max."s %s","File","Rev Last Change\n\n")). trim(join("\n", grep (($_ =~ /^fhem.pl|\d\d_/), @ret))."\n\n". join("\n", grep (($_ !~ /^fhem.pl|\d\d_/), @ret)) ); } ##################################### sub version_sortModules($$) { my ($a, $b) = @_; $a =~ s/^No Id found for //; $b =~ s/^No Id found for //; my @a_vals = split(' ', $a); my @b_vals = split(' ', $b); # fhem.pl always at top return -1 if($a_vals[0] eq "fhem.pl"); return 1 if($b_vals[0] eq "fhem.pl"); $a_vals[0] =~ s/^\d\d_//; $b_vals[0] =~ s/^\d\d_//; return uc($a_vals[0]) cmp uc($b_vals[0]); } 1; =pod =item command =begin html

version

=end html =begin html_DE

version

=end html_DE =cut