[pve-devel] r6480 - in pve-common/trunk/data: . PVE

svn-commits at proxmox.com svn-commits at proxmox.com
Tue Aug 16 06:52:00 CEST 2011


Author: dietmar
Date: 2011-08-16 06:51:59 +0200 (Tue, 16 Aug 2011)
New Revision: 6480

Modified:
   pve-common/trunk/data/ChangeLog
   pve-common/trunk/data/PVE/JSONSchema.pm
Log:
	* PVE/JSONSchema.pm (dump_config): a simply way to generate
	key/value configuration files.



Modified: pve-common/trunk/data/ChangeLog
===================================================================
--- pve-common/trunk/data/ChangeLog	2011-08-15 09:50:14 UTC (rev 6479)
+++ pve-common/trunk/data/ChangeLog	2011-08-16 04:51:59 UTC (rev 6480)
@@ -1,3 +1,8 @@
+2011-08-16  Proxmox Support Team  <support at proxmox.com>
+
+	* PVE/JSONSchema.pm (dump_config): a simply way to generate
+	key/value configuration files.
+
 2011-08-15  Proxmox Support Team  <support at proxmox.com>
 
 	* PVE/JSONSchema.pm (parse_config): a simply way to verify

Modified: pve-common/trunk/data/PVE/JSONSchema.pm
===================================================================
--- pve-common/trunk/data/PVE/JSONSchema.pm	2011-08-15 09:50:14 UTC (rev 6479)
+++ pve-common/trunk/data/PVE/JSONSchema.pm	2011-08-16 04:51:59 UTC (rev 6480)
@@ -951,5 +951,23 @@
     return $cfg;
 }
 
+# generate simple key/value file
+sub dump_config {
+    my ($schema, $filename, $cfg) = @_;
 
+    # do fast check (avoid validate_schema($schema))
+    die "got strange schema" if !$schema->{type} || 
+	!$schema->{properties} || $schema->{type} ne 'object';
+
+    validate($cfg, $schema, "validation error in '$filename'\n");
+
+    my $data = '';
+
+    foreach my $k (keys %$cfg) {
+	$data .= "$k: $cfg->{$k}\n";
+    }
+
+    return $data;
+}
+
 1;




More information about the pve-devel mailing list