2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-05-01 12:38:37 +00:00

version: shows latest revision since last update (Forum: #49215)

git-svn-id: https://svn.fhem.de/fhem/trunk@10819 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
markusbloch 2016-02-13 17:47:03 +00:00
parent 90fdcec0a6
commit 4d9e271fcc
2 changed files with 44 additions and 16 deletions

View File

@ -1,5 +1,6 @@
# Add changes at the top of the list. Keep it in ASCII, and 80-char wide.
# Do not insert empty lines here, update check depends on it.
- feature: version: version command shows latest revision since last update
- feature: 02_RSS: new attribute itemtitle
- bugfix: 57_Calendar: weekly recurring events on several weekdays, that
start around midnight

View File

@ -7,7 +7,7 @@ use warnings;
sub version_Initialize($$) {
$cmds{version} = { Fn => "CommandVersion",
Hlp=>"[<filter>] [noheader],print SVN version of loaded modules"};
Hlp=>"[<filter>|revision] [noheader],print SVN version of loaded modules"};
}
#####################################
@ -27,6 +27,7 @@ CommandVersion($$)
my @files = map {$INC{$_}} keys %INC;
push @files, $0; # path to fhem.pl
push @ret, cfgDB_svnId() if(configDBUsed());
@files = () if($param && $param eq "revision");
foreach my $fn (@files) {
next unless($fn =~ /^(?:$modpath.?)?FHEM/ or $fn =~ /fhem.pl$/); # configDB
my $mod_name = ($fn=~ /[\/\\]([^\/\\]+)$/ ? $1 : $fn);
@ -57,10 +58,15 @@ CommandVersion($$)
push @ret, $line;
}
my $fhem_revision = version_getRevFromControls();
$fhem_revision = "Latest Revision: $fhem_revision\n\n" if(defined($fhem_revision) && !$noheader);
@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")).
@ret = sort {version_sortModules($a, $b)} grep {($param ne "" ? /$param/ : 1)} @ret;
return "no loaded modules found that match: $param" if($param ne "" && $param ne "revision" && !@ret);
return (((!$param && !$noheader) || $param eq "revision") ? $fhem_revision : "").
($noheader || !@ret ? "" : 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))
);
@ -87,6 +93,25 @@ sub version_sortModules($$)
return uc($a_vals[0]) cmp uc($b_vals[0]);
}
sub version_getRevFromControls(;$)
{
my ($name) = @_;
$name = "fhem" unless(defined($name));
my $control_file = AttrVal("global","modpath",".")."/FHEM/controls_$name.txt";
my $revision;
if(open(FH, $control_file)) {
while(<FH>) {
if(/^REV\s+(\S+.*)$/) {
$revision = $1;
last;
}
}
close(FH);
}
return $revision;
}
1;
=pod
@ -96,19 +121,19 @@ sub version_sortModules($$)
<a name="version"></a>
<h3>version</h3>
<ul>
<code>version [&lt;filter&gt;] [noheader]</code>
<code>version [&lt;filter&gt;|revision] [noheader]</code>
<br><br>
List the version of fhem.pl and all loaded modules. The optional parameter
can be used to filter the ouput.<br><br>
The optional flag <code>noheader</code> disables the output of the header line (File, Rev, Last Change).
can be used to filter the ouput. The special filter value "revision" shows
only the latest revision number since the last update.<br><br>
The optional flag <code>noheader</code> disables the output of the header lines (Latest Revision, File, Rev, Last Change).
<br><br>
Example output of <code>version</code>:
<ul>
<code><br>
Latest Revision: 10814<br><br>
File&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Rev&nbsp;&nbsp;&nbsp;Last&nbsp;Change<br><br>
fhem.pl&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;10397&nbsp;2016-01-07&nbsp;08:36:49Z&nbsp;rudolfkoenig<br>
fhem.pl&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;10769&nbsp;2016-02-08&nbsp;12:11:51Z&nbsp;rudolfkoenig<br>
90_at.pm&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;10048&nbsp;2015-11-29&nbsp;14:51:40Z&nbsp;rudolfkoenig<br>
98_autocreate.pm&nbsp;10165&nbsp;2015-12-13&nbsp;11:14:15Z&nbsp;rudolfkoenig<br>
00_CUL.pm&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;10146&nbsp;2015-12-10&nbsp;10:17:42Z&nbsp;rudolfkoenig<br>
@ -140,18 +165,20 @@ sub version_sortModules($$)
<a name="version"></a>
<h3>version</h3>
<ul>
<code>version [&lt;filter&gt;] [noheader]</code>
<code>version [&lt;filter&gt;|revision] [noheader]</code>
<br><br>
Gibt die Versionsinformation von fhem.pl und aller geladenen Module aus. Mit
der optionalen Parameter kann man die Ausgabe filtern.
dem optionalen Parameter kann man die Ausgabe filtern. Der spezielle Filterwert "revision"
zeigt nur die aktuellste Revisions-Nummer seit dem letzten Update an.
<br><br>
Der optionale Parameter <code>noheader</code> unterdrückt die Ausgabe des Listenkopf (File, Rev, Last Change).
Der optionale Parameter <code>noheader</code> unterdr&uuml;ckt die Ausgabe des Listenkopfs (Latest Revision, File, Rev, Last Change).
<br><br>
Beispiel der Ausgabe von <code>version</code>:
<ul>
<code><br>
Latest Revision: 10814<br><br>
File&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Rev&nbsp;&nbsp;&nbsp;Last&nbsp;Change<br><br>
fhem.pl&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;10397&nbsp;2016-01-07&nbsp;08:36:49Z&nbsp;rudolfkoenig<br>
fhem.pl&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;10769&nbsp;2016-02-08&nbsp;12:11:51Z&nbsp;rudolfkoenig<br>
90_at.pm&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;10048&nbsp;2015-11-29&nbsp;14:51:40Z&nbsp;rudolfkoenig<br>
98_autocreate.pm&nbsp;10165&nbsp;2015-12-13&nbsp;11:14:15Z&nbsp;rudolfkoenig<br>
00_CUL.pm&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;10146&nbsp;2015-12-10&nbsp;10:17:42Z&nbsp;rudolfkoenig<br>
@ -164,14 +191,14 @@ sub version_sortModules($$)
<ul>
<code><br>
File&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Rev&nbsp;&nbsp;&nbsp;Last&nbsp;Change<br><br>
fhem.pl&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;10397&nbsp;2016-01-07&nbsp;08:36:49Z&nbsp;rudolfkoenig<br>
fhem.pl&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;10769&nbsp;2016-02-08&nbsp;12:11:51Z&nbsp;rudolfkoenig<br>
</code>
</ul>
<br>
Beispiel der Ausgabe von <code>version fhem.pl noheader</code>:
<ul>
<code><br>
fhem.pl&nbsp;10397&nbsp;2016-01-07&nbsp;08:36:49Z&nbsp;rudolfkoenig<br>
fhem.pl&nbsp;10769&nbsp;2016-02-08&nbsp;12:11:51Z&nbsp;rudolfkoenig<br>
</code>
</ul>
</ul>