[pve-devel] r5106 - pve-common/trunk

svn-commits at proxmox.com svn-commits at proxmox.com
Fri Sep 10 09:43:40 CEST 2010


Author: dietmar
Date: 2010-09-10 07:43:40 +0000 (Fri, 10 Sep 2010)
New Revision: 5106

Modified:
   pve-common/trunk/CLIHandler.pm
   pve-common/trunk/ChangeLog
   pve-common/trunk/JSONSchema.pm
   pve-common/trunk/RESTHandler.pm
   pve-common/trunk/Tools.pm
Log:
	* Tools.pm (kvmkeymaps): moved from PVE::Utils.

	* JSONSchema.pm: add a new attribute caled 'typetext' (any better
	name?), used to generate nice docs.

	* RESTHandler.pm (usage_str): only print indexed options
	once (-vlan\d+ -scsi\d+)
	(usage_str): sort options
	(usage_str): use Text::Wrap to format output



Modified: pve-common/trunk/CLIHandler.pm
===================================================================
--- pve-common/trunk/CLIHandler.pm	2010-09-09 09:22:06 UTC (rev 5105)
+++ pve-common/trunk/CLIHandler.pm	2010-09-10 07:43:40 UTC (rev 5106)
@@ -45,7 +45,7 @@
 	raise_param_exc({ cmd => "no such command '$cmd'"}) if !$class;
 
 	my $str = $class->usage_str($name, "$exename $cmd", $arg_param, $uri_param, 'full');
-	print $str;
+	print "$str\n";
 
 	return undef;
 

Modified: pve-common/trunk/ChangeLog
===================================================================
--- pve-common/trunk/ChangeLog	2010-09-09 09:22:06 UTC (rev 5105)
+++ pve-common/trunk/ChangeLog	2010-09-10 07:43:40 UTC (rev 5106)
@@ -1,5 +1,17 @@
+2010-09-10  Proxmox Support Team  <support at proxmox.com>
+
+	* Tools.pm (kvmkeymaps): moved from PVE::Utils.
+
+	* JSONSchema.pm: add a new attribute caled 'typetext' (any better
+	name?), used to generate nice docs.
+
 2010-09-08  Proxmox Support Team  <support at proxmox.com>
 
+	* RESTHandler.pm (usage_str): only print indexed options
+	once (-vlan\d+ -scsi\d+)
+	(usage_str): sort options
+	(usage_str): use Text::Wrap to format output
+
 	* JSONSchema.pm (check_format): revert previous change - to keep
 	it simply
 

Modified: pve-common/trunk/JSONSchema.pm
===================================================================
--- pve-common/trunk/JSONSchema.pm	2010-09-09 09:22:06 UTC (rev 5105)
+++ pve-common/trunk/JSONSchema.pm	2010-09-10 07:43:40 UTC (rev 5106)
@@ -345,10 +345,7 @@
 			  join(", ", @$ea) . "'");
 	    }
 	}
- 
     }
-
-
 }
 
 sub validate {
@@ -426,6 +423,11 @@
 	    optional => 1,
 	    description => "This indicates the maximum value for the instance property when the type of the instance value is a number.",
 	},
+	typetext => {
+	    type => "string",
+	    optional => 1,
+	    description => "A text representation of the type (used to generate documentation).",
+	},
 	pattern => {
 	    type => "string",
 	    format => "regex",

Modified: pve-common/trunk/RESTHandler.pm
===================================================================
--- pve-common/trunk/RESTHandler.pm	2010-09-09 09:22:06 UTC (rev 5105)
+++ pve-common/trunk/RESTHandler.pm	2010-09-10 07:43:40 UTC (rev 5106)
@@ -6,6 +6,7 @@
 use PVE::Exception qw(raise raise_param_exc);
 use PVE::JSONSchema;
 use HTTP::Status qw(:constants :is status_message);
+use Text::Wrap;
 
 # fixme: use new PVE::Exception
 
@@ -237,13 +238,29 @@
 	$args .= $prop->{$p} && $prop->{$p}->{optional} ? "[<$p>]" : "<$p>";
     }
 
-    my $get_type_str = sub {
+   my $get_type_text = sub {
 	my ($k) = @_;
 
 	my $phash = $prop->{$k};
 
-	my $type =  $phash->{format} || $phash->{type} || 'string';
+	if ($phash->{typetext}) {
+	    return $phash->{typetext};
+	} elsif ($phash->{enum}) {
+	    return "(" . join(' | ', sort @{$phash->{enum}}) . ")";
+	} elsif ($phash->{pattern}) {
+	    return $phash->{pattern};
+	} elsif ($phash->{type} eq 'integer' || $phash->{type} eq 'number') {
+	    if (defined($phash->{minimum}) && defined($phash->{maximum})) {
+		return "$phash->{type} ($phash->{minimum} - $phash->{maximum})";
+	    } elsif (defined($phash->{minimum})) {
+		return "$phash->{type} ($phash->{minimum} - N)";
+	    } elsif (defined($phash->{maximum})) {
+		return "$phash->{type} (-N - $phash->{maximum})";
+	    }
+	}
 
+	my $type = $phash->{type} || 'string';
+
 	return $type;
     };
 
@@ -255,24 +272,25 @@
 	my $res = '';
 
 	my $descr = $phash->{description} || "no description available";
-	my $type =  &$get_type_str($k);
+	chomp $descr;
 
+	my $type =  &$get_type_text($k);
+
 	if ($hidepw && $k eq 'password') {
 	    $type = '';
 	}
-
-	$res .= sprintf "  %-10s %-10s   $descr\n", $display_name, "$type";
-	my $indend = "                          ";
-	if ($phash->{enum}) {
-	    $res .= sprintf "${indend}possible values: %s\n",  join ('|', @{$phash->{enum}});
-	}	
-	if ($phash->{minimum}) {
-	    $res .= "${indend}minimum: $phash->{minimum}\n";
+	
+	my $defaulttxt = '';
+	if (defined(my $dv = $phash->{default})) {
+	    $defaulttxt = "   (default=$dv)";
 	}
-	if ($phash->{maximum}) {
-	    $res .= "${indend}maximum: $phash->{maximum}\n";
-	}
+	my $tmp = sprintf "  %-10s %s$defaulttxt\n", $display_name, "$type";
+	my $indend = "             ";
 
+	$res .= Text::Wrap::wrap('', $indend, ($tmp));
+	$res .= "\n",
+	$res .= Text::Wrap::wrap($indend, $indend, ($descr)) . "\n\n";
+
 	return $res;
     };
 
@@ -283,20 +301,30 @@
 	$argdescr .= &$get_prop_descr($k, "<$k>");
     }
 
+    my $idx_param = {}; # -vlan\d+ -scsi\d+
+
     my $opts = '';
-    foreach my $k (keys %$prop) {
+    foreach my $k (sort keys %$prop) {
 	next if $arg_hash->{$k};
 	next if defined($fixed_param->{$k});
 
-	my $type =  &$get_type_str($k);
+	my $type = $prop->{$k}->{type} || 'string';
 
 	next if $hidepw && ($k eq 'password') && !$prop->{$k}->{optional};
 
-	$opts .= &$get_prop_descr($k, "-$k");
+	my $base = $k;
+	if ($k =~ m/^([a-z]+)(\d+)$/) {
+	    my $name = $1;
+	    next if $idx_param->{$name};
+	    $idx_param->{$name} = 1;
+	    $base = "${name}[n]";
+	}
 
+	$opts .= &$get_prop_descr($k, "-$base");
+
 	if (!$prop->{$k}->{optional}) {
 	    $args .= " " if $args;
-	    $args .= "-$k $type"
+	    $args .= "-$base $type"
 	}
     } 
 
@@ -343,7 +371,7 @@
 
 	die $err if !$ec || $ec ne "PVE::Exception" || !$err->is_param_exc();
 	
-	$err->{usage} = $self->usage_str($name, $prefix, $arg_param, $fixed_param, undef, $pwcallback);
+	$err->{usage} = $self->usage_str($name, $prefix, $arg_param, $fixed_param, 'short', $pwcallback);
 
 	die $err;
     }

Modified: pve-common/trunk/Tools.pm
===================================================================
--- pve-common/trunk/Tools.pm	2010-09-09 09:22:06 UTC (rev 5105)
+++ pve-common/trunk/Tools.pm	2010-09-10 07:43:40 UTC (rev 5106)
@@ -351,4 +351,41 @@
     die "write to '$filename' failed\n" if !$res;
 }
 
+sub kvmkeymaps {
+    return {
+	'dk'     => ['Danish', 'da', 'qwerty/dk-latin1.kmap.gz', 'dk', 'nodeadkeys'],
+	'de'     => ['German', 'de', 'qwertz/de-latin1-nodeadkeys.kmap.gz', 'de', 'nodeadkeys' ],
+	'de-ch'  => ['Swiss-German', 'de-ch', 'qwertz/sg-latin1.kmap.gz',  'ch', 'de_nodeadkeys' ], 
+	'en-gb'  => ['United Kingdom', 'en-gb', 'qwerty/uk.kmap.gz' , 'gb', 'intl' ],
+	'en-us'  => ['U.S. English', 'en-us', 'qwerty/us-latin1.kmap.gz',  'us', 'intl' ],
+	'es'     => ['Spanish', 'es', 'qwerty/es.kmap.gz', 'es', 'nodeadkeys'],
+	#'et'     => [], # Ethopia or Estonia ??
+	'fi'     => ['Finnish', 'fi', 'qwerty/fi-latin1.kmap.gz', 'fi', 'nodeadkeys'],
+	#'fo'     => ['Faroe Islands', 'fo', ???, 'fo', 'nodeadkeys'],
+	'fr'     => ['French', 'fr', 'azerty/fr-latin1.kmap.gz', 'fr', 'nodeadkeys'],
+	'fr-be'  => ['Belgium-French', 'fr-be', 'azerty/be2-latin1.kmap.gz', 'be', 'nodeadkeys'],
+	'fr-ca'  => ['Canada-French', 'fr-ca', 'qwerty/cf.kmap.gz', 'ca', 'fr-legacy'],
+	'fr-ch'  => ['Swiss-French', 'fr-ch', 'qwertz/fr_CH-latin1.kmap.gz', 'ch', 'fr_nodeadkeys'],
+	#'hr'     => ['Croatia', 'hr', 'qwertz/croat.kmap.gz', 'hr', ??], # latin2?
+	'hu'     => ['Hungarian', 'hu', 'qwertz/hu.kmap.gz', 'hu', undef],
+	'is'     => ['Icelandic', 'is', 'qwerty/is-latin1.kmap.gz', 'is', 'nodeadkeys'],
+	'it'     => ['Italian', 'it', 'qwerty/it2.kmap.gz', 'it', 'nodeadkeys'],
+	'jp'     => ['Japanese', 'ja', 'qwerty/jp106.kmap.gz', 'jp', undef],
+	'lt'     => ['Lithuanian', 'lt', 'qwerty/lt.kmap.gz', 'lt', 'std'],
+	#'lv'     => ['Latvian', 'lv', 'qwerty/lv-latin4.kmap.gz', 'lv', ??], # latin4 or latin7?
+	'mk'     => ['Macedonian', 'mk', 'qwerty/mk.kmap.gz', 'mk', 'nodeadkeys'],
+	'nl'     => ['Dutch', 'nl', 'qwerty/nl.kmap.gz', 'nl', undef],
+	#'nl-be'  => ['Belgium-Dutch', 'nl-be', ?, ?, ?],
+	'no'   => ['Norwegian', 'no', 'qwerty/no-latin1.kmap.gz', 'no', 'nodeadkeys'], 
+	'pl'     => ['Polish', 'pl', 'qwerty/pl.kmap.gz', 'pl', undef],
+	'pt'     => ['Portuguese', 'pt', 'qwerty/pt-latin1.kmap.gz', 'pt', 'nodeadkeys'],
+	'pt-br'  => ['Brazil-Portuguese', 'pt-br', 'qwerty/br-latin1.kmap.gz', 'br', 'nodeadkeys'],
+	#'ru'     => ['Russian', 'ru', 'qwerty/ru.kmap.gz', 'ru', undef], # dont know?
+	'si'     => ['Slovenian', 'sl', 'qwertz/slovene.kmap.gz', 'si', undef],
+	#'sv'     => [], Swedish ?
+	#'th'     => [],
+	#'tr'     => [],
+    };
+}
+
 1;




More information about the pve-devel mailing list