mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-03-03 16:56:54 +00:00
configDB - added new commands filelist and filedelete
git-svn-id: https://svn.fhem.de/fhem/trunk@5571 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
63e8a87c45
commit
a892b58930
@ -1,6 +1,7 @@
|
||||
# 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.
|
||||
- SVN
|
||||
- feature: configDB: added commands filelist and filedelete
|
||||
- feature: configDB: added commands fileimport and fileexport
|
||||
- feature: 36_JeeLink: added LaCrosse, ETH200comfort, CUL_IR,
|
||||
HX2272 and FS20 modes from ulli
|
||||
|
@ -180,14 +180,54 @@ sub CommandConfigdb($$) {
|
||||
$ret = _cfgDB_Diff($param1, $param2);
|
||||
}
|
||||
|
||||
when ('filedelete') {
|
||||
return "\n Syntax: configdb fileexport <pathToFile>" if @a != 2;
|
||||
my $filename;
|
||||
if(substr($param1,0,1) eq '/') {
|
||||
$filename = $param1;
|
||||
} else {
|
||||
$filename = $attr{global}{modpath};
|
||||
$filename .= "/$param1";
|
||||
}
|
||||
$ret = _cfgDB_Filedelete $filename;
|
||||
}
|
||||
|
||||
when ('fileexport') {
|
||||
return "\n Syntax: configdb fileexport <pathToFile>" if @a != 2;
|
||||
$ret = _cfgDB_Fileexport $param1;
|
||||
my $filename;
|
||||
if(substr($param1,0,1) eq '/') {
|
||||
$filename = $param1;
|
||||
} else {
|
||||
$filename = $attr{global}{modpath};
|
||||
$filename .= "/$param1";
|
||||
}
|
||||
if ( -w $filename ) {
|
||||
$ret = _cfgDB_Fileexport $filename;
|
||||
} else {
|
||||
$ret = "\n Write error on file $filename";
|
||||
}
|
||||
}
|
||||
|
||||
when ('fileimport') {
|
||||
return "\n Syntax: configdb fileimport <pathToFile>" if @a != 2;
|
||||
$ret = _cfgDB_Fileimport $param1;
|
||||
my $filename;
|
||||
if(substr($param1,0,1) eq '/') {
|
||||
$filename = $param1;
|
||||
} else {
|
||||
$filename = $attr{global}{modpath};
|
||||
$filename .= "/$param1";
|
||||
}
|
||||
if ( -r $filename ) {
|
||||
$ret = _cfgDB_Fileimport $filename;
|
||||
} elsif ( -e $filename) {
|
||||
$ret = "\n Read error on file $filename";
|
||||
} else {
|
||||
$ret = "\n File $filename not found.";
|
||||
}
|
||||
}
|
||||
|
||||
when ('filelist') {
|
||||
return _cfgDB_Filelist;
|
||||
}
|
||||
|
||||
when ('info') {
|
||||
@ -404,6 +444,11 @@ compare device: telnetPort in current version 0 (left) to version: 1 (right)
|
||||
The target file can be imported again, if needed.<br/>
|
||||
<br/>
|
||||
|
||||
<li><code>configdb filedelete <Filename></code></li><br/>
|
||||
Delete file from database.<br/>
|
||||
<br/>
|
||||
<br/>
|
||||
|
||||
<li><code>configdb fileexport <targetFilename></code></li><br/>
|
||||
Exports specified fhem file from database into filesystem.
|
||||
Example:<br/>
|
||||
@ -420,6 +465,11 @@ compare device: telnetPort in current version 0 (left) to version: 1 (right)
|
||||
<br/>
|
||||
<br/>
|
||||
|
||||
<li><code>configdb filelist</code></li><br/>
|
||||
Show a list with all filenames stored in database.<br/>
|
||||
<br/>
|
||||
<br/>
|
||||
|
||||
<li><code>configdb info</code></li><br/>
|
||||
Returns some database statistics<br/>
|
||||
<pre>
|
||||
@ -663,6 +713,11 @@ compare device: telnetPort in current version 0 (left) to version: 1 (right)
|
||||
Die Zieldatei kann später für die Wiederherstellung verwendet werden.<br/>
|
||||
<br/>
|
||||
|
||||
<li><code>configdb filedelete <Dateiname></code></li><br/>
|
||||
Löscht eine gespeicherte Datei aus der Datenbank.<br/>
|
||||
<br/>
|
||||
<br/>
|
||||
|
||||
<li><code>configdb fileexport <zielDatei></code></li><br/>
|
||||
Schreibt die angegebene Datei aus der Datenbank in das Dateisystem.
|
||||
Beispiel:<br/>
|
||||
@ -679,6 +734,11 @@ compare device: telnetPort in current version 0 (left) to version: 1 (right)
|
||||
<br/>
|
||||
<br/>
|
||||
|
||||
<li><code>configdb filelist</code></li><br/>
|
||||
Liefert eine Liste mit allen Namen der gespeicherten Dateien.<br/>
|
||||
<br/>
|
||||
<br/>
|
||||
|
||||
<li><code>configdb info</code></li><br/>
|
||||
Liefert eine Datenbankstatistik<br/>
|
||||
<pre>
|
||||
|
@ -618,19 +618,48 @@ sub _cfgDB_Diff($$) {
|
||||
return $ret;
|
||||
}
|
||||
|
||||
sub _cfgDB_Fileimport($) {
|
||||
sub _cfgDB_Filedelete($) {
|
||||
my ($filename) = @_;
|
||||
my $fhem_dbh = _cfgDB_Connect;
|
||||
my $ret = $fhem_dbh->do("delete from fhemfilesave where filename = '$filename'");
|
||||
$fhem_dbh->commit();
|
||||
$fhem_dbh->disconnect();
|
||||
if($ret > 0) {
|
||||
$ret = "File $filename deleted from database ($ret lines)";
|
||||
} else {
|
||||
$ret = "File $filename not found in database.";
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
sub _cfgDB_Fileexport($) {
|
||||
my ($filename) = @_;
|
||||
my $counter = 0;
|
||||
my $fhem_dbh = _cfgDB_Connect;
|
||||
my $sth = $fhem_dbh->prepare( "SELECT * FROM fhemfilesave WHERE filename = '$filename'" );
|
||||
$sth->execute();
|
||||
open( FILE, ">$filename" );
|
||||
while (my @line = $sth->fetchrow_array()) {
|
||||
$counter++;
|
||||
print FILE $line[1], "\n";
|
||||
}
|
||||
close ( FILE );
|
||||
$sth->finish();
|
||||
$fhem_dbh->disconnect();
|
||||
return "$counter lines written from database into file $filename";
|
||||
}
|
||||
|
||||
sub _cfgDB_Fileimport($) {
|
||||
my ($filename) = @_;
|
||||
my $path = $attr{global}{modpath};
|
||||
$path .= "/$filename";
|
||||
my $counter = 0;
|
||||
my $fhem_dbh = _cfgDB_Connect;
|
||||
$fhem_dbh->do("delete from fhemfilesave where filename = '$path'");
|
||||
my $sth = $fhem_dbh->prepare('INSERT INTO fhemfilesave values (?, ?)');
|
||||
open (in,"<$path") || die $!;
|
||||
$fhem_dbh->do("delete from fhemfilesave where filename = '$filename'");
|
||||
open (in,"<$filename") || die $!;
|
||||
while (<in>){
|
||||
$counter++;
|
||||
my $line = substr($_,0,length($_)-1);
|
||||
$sth->execute($path, $line);
|
||||
$sth->execute($filename, $line);
|
||||
}
|
||||
close in;
|
||||
$sth->finish();
|
||||
@ -639,23 +668,18 @@ sub _cfgDB_Fileimport($) {
|
||||
return "$counter lines written from file $filename to database";
|
||||
}
|
||||
|
||||
sub _cfgDB_Fileexport($) {
|
||||
my ($filename) = @_;
|
||||
my $path = $attr{global}{modpath};
|
||||
$path .= "/$filename";
|
||||
my $counter = 0;
|
||||
sub _cfgDB_Filelist {
|
||||
my $ret = "Files found in database:\n".
|
||||
"------------------------------------------------------------\n";
|
||||
my $fhem_dbh = _cfgDB_Connect;
|
||||
my $sth = $fhem_dbh->prepare( "SELECT * FROM fhemfilesave WHERE filename = '$path'" );
|
||||
my $sth = $fhem_dbh->prepare( "SELECT filename FROM fhemfilesave group by filename order by filename" );
|
||||
$sth->execute();
|
||||
open( FILE, ">$path" );
|
||||
while (my @line = $sth->fetchrow_array()) {
|
||||
$counter++;
|
||||
print FILE $line[1], "\n";
|
||||
while (my $line = $sth->fetchrow_array()) {
|
||||
$ret .= "$line\n";
|
||||
}
|
||||
close ( FILE );
|
||||
$sth->finish();
|
||||
$fhem_dbh->disconnect();
|
||||
return "$counter lines read from database into file $filename";
|
||||
return $ret;
|
||||
}
|
||||
|
||||
1;
|
||||
|
Loading…
x
Reference in New Issue
Block a user