mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-04-17 23:46:03 +00:00
configDB - added new commands fileimport and fileexport
git-svn-id: https://svn.fhem.de/fhem/trunk@5563 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
401371d01c
commit
714ebae901
@ -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 fileimport and fileexport
|
||||
- feature: 36_JeeLink: added LaCrosse, ETH200comfort, CUL_IR,
|
||||
HX2272 and FS20 modes from ulli
|
||||
added AliRF
|
||||
|
@ -180,6 +180,16 @@ sub CommandConfigdb($$) {
|
||||
$ret = _cfgDB_Diff($param1, $param2);
|
||||
}
|
||||
|
||||
when ('fileexport') {
|
||||
return "\n Syntax: configdb fileexport <pathToFile>" if @a != 2;
|
||||
$ret = _cfgDB_Fileexport $param1;
|
||||
}
|
||||
|
||||
when ('fileimport') {
|
||||
return "\n Syntax: configdb fileimport <pathToFile>" if @a != 2;
|
||||
$ret = _cfgDB_Fileimport $param1;
|
||||
}
|
||||
|
||||
when ('info') {
|
||||
Log3('configdb', 4, "info requested.");
|
||||
$ret = _cfgDB_Info;
|
||||
@ -378,7 +388,7 @@ sub CommandConfigdb($$) {
|
||||
from current version 0 with version <version><br/>
|
||||
Example for valid request:<br/>
|
||||
<br/>
|
||||
<code>get configDB telnetPort 1</code><br/>
|
||||
<code>configdb diff telnetPort 1</code><br/>
|
||||
<br/>
|
||||
will show a result like this:
|
||||
<pre>
|
||||
@ -394,6 +404,22 @@ 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 fileexport <targetFilename></code></li><br/>
|
||||
Exports specified fhem file from database into filesystem.
|
||||
Example:<br/>
|
||||
<br/>
|
||||
<code>configdb fileexport FHEM/99_myUtils.pm</code><br/>
|
||||
<br/>
|
||||
<br/>
|
||||
|
||||
<li><code>configdb fileimport <sourceFilename></code></li><br/>
|
||||
Imports specified fhem file from from filesystem into database.
|
||||
Example:<br/>
|
||||
<br/>
|
||||
<code>configdb fileimport FHEM/99_myUtils.pm</code><br/>
|
||||
<br/>
|
||||
<br/>
|
||||
|
||||
<li><code>configdb info</code></li><br/>
|
||||
Returns some database statistics<br/>
|
||||
<pre>
|
||||
@ -637,6 +663,22 @@ 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 fileexport <zielDatei></code></li><br/>
|
||||
Schreibt die angegebene Datei aus der Datenbank in das Dateisystem.
|
||||
Beispiel:<br/>
|
||||
<br/>
|
||||
<code>configdb fileexport FHEM/99_myUtils.pm</code><br/>
|
||||
<br/>
|
||||
<br/>
|
||||
|
||||
<li><code>configdb fileimport <quellDatei></code></li><br/>
|
||||
Liest die angegbene Datei aus dem Dateisystem und schreibt den Inhalt in die Datenbank.
|
||||
Beispiel:<br/>
|
||||
<br/>
|
||||
<code>configdb fileimport FHEM/99_myUtils.pm</code><br/>
|
||||
<br/>
|
||||
<br/>
|
||||
|
||||
<li><code>configdb info</code></li><br/>
|
||||
Liefert eine Datenbankstatistik<br/>
|
||||
<pre>
|
||||
|
@ -153,6 +153,9 @@ sub cfgDB_Init {
|
||||
# create TABLE fhemstate if nonexistent
|
||||
$fhem_dbh->do("CREATE TABLE IF NOT EXISTS fhemstate(stateString TEXT)");
|
||||
|
||||
# create TABLE fhemfilesave if nonexistent
|
||||
$fhem_dbh->do("CREATE TABLE IF NOT EXISTS fhemfilesave(filename TEXT, line TEXT)");
|
||||
|
||||
# close database connection
|
||||
$fhem_dbh->commit();
|
||||
$fhem_dbh->disconnect();
|
||||
@ -615,6 +618,45 @@ sub _cfgDB_Diff($$) {
|
||||
return $ret;
|
||||
}
|
||||
|
||||
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 $!;
|
||||
while (<in>){
|
||||
$counter++;
|
||||
my $line = substr($_,0,length($_)-1);
|
||||
$sth->execute($path, $line);
|
||||
}
|
||||
close in;
|
||||
$sth->finish();
|
||||
$fhem_dbh->commit();
|
||||
$fhem_dbh->disconnect();
|
||||
return "$counter lines written from file $filename to database";
|
||||
}
|
||||
|
||||
sub _cfgDB_Fileexport($) {
|
||||
my ($filename) = @_;
|
||||
my $path = $attr{global}{modpath};
|
||||
$path .= "/$filename";
|
||||
my $counter = 0;
|
||||
my $fhem_dbh = _cfgDB_Connect;
|
||||
my $sth = $fhem_dbh->prepare( "SELECT * FROM fhemfilesave WHERE filename = '$path'" );
|
||||
$sth->execute();
|
||||
open( FILE, ">$path" );
|
||||
while (my @line = $sth->fetchrow_array()) {
|
||||
$counter++;
|
||||
print FILE $line[1], "\n";
|
||||
}
|
||||
close ( FILE );
|
||||
$sth->finish();
|
||||
$fhem_dbh->disconnect();
|
||||
return "$counter lines read from database into file $filename";
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user