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

svn-commits at proxmox.com svn-commits at proxmox.com
Tue Feb 15 13:21:32 CET 2011


Author: dietmar
Date: 2011-02-15 13:21:32 +0100 (Tue, 15 Feb 2011)
New Revision: 5528

Modified:
   pve-common/trunk/data/ChangeLog
   pve-common/trunk/data/PVE/Tools.pm
Log:


Modified: pve-common/trunk/data/ChangeLog
===================================================================
--- pve-common/trunk/data/ChangeLog	2011-02-15 11:34:06 UTC (rev 5527)
+++ pve-common/trunk/data/ChangeLog	2011-02-15 12:21:32 UTC (rev 5528)
@@ -1,5 +1,7 @@
 2011-02-15  Proxmox Support Team  <support at proxmox.com>
 
+	* PVE/Tools.pm (template_replace): support simple uri templates
+
 	* PVE/JSONSchema.pm: add permissions property (path,
 	privs). Allows use to specify required access permissions.
 

Modified: pve-common/trunk/data/PVE/Tools.pm
===================================================================
--- pve-common/trunk/data/PVE/Tools.pm	2011-02-15 11:34:06 UTC (rev 5527)
+++ pve-common/trunk/data/PVE/Tools.pm	2011-02-15 12:21:32 UTC (rev 5528)
@@ -16,6 +16,7 @@
 file_get_contents
 file_read_firstline
 split_list
+template_replace
 safe_print
 trim
 extract_param
@@ -343,6 +344,18 @@
     return $txt;
 }
 
+# simple uri templates like "/vms/{vmid}"
+sub template_replace {
+    my ($tmpl, $data) = @_;
+
+    my $res = '';
+    while ($tmpl =~ m/([^{]+){([^}]+)}/g) {
+	$res .= $1 . ($data->{$2} || '-');
+    }
+
+    return $res;
+}
+
 sub safe_print {
     my ($filename, $fh, $data) = @_;
 



More information about the pve-devel mailing list