Whamcloud - gitweb
LU-1538 utils: remove obsolete scripts
[fs/lustre-release.git] / lustre / utils / Lustre / cmdline.py
index 53bb6e8..58bc08b 100644 (file)
@@ -1,23 +1,41 @@
 #!/usr/bin/env python
+# GPL HEADER START
 #
-#  Copyright (C) 2002 Cluster File Systems, Inc.
-#   Author: Robert Read <rread@clusterfs.com>
-#   This file is part of Lustre, http://www.lustre.org.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 #
-#   Lustre is free software; you can redistribute it and/or
-#   modify it under the terms of version 2 of the GNU General Public
-#   License as published by the Free Software Foundation.
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 2 only,
+# as published by the Free Software Foundation.
 #
-#   Lustre is distributed in the hope that it will be useful,
-#   but WITHOUT ANY WARRANTY; without even the implied warranty of
-#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#   GNU General Public License for more details.
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License version 2 for more details (a copy is included
+# in the LICENSE file that accompanied this code).
 #
-#   You should have received a copy of the GNU General Public License
-#   along with Lustre; if not, write to the Free Software
-#   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+# You should have received a copy of the GNU General Public License
+# version 2 along with this program; If not, see
+# http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
+# copy of GPLv2].
+#
+# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+# CA 95054 USA or visit www.sun.com if you need additional information or
+# have any questions.
+#
+# GPL HEADER END
 #
 
+#
+# Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# This file is part of Lustre, http://www.lustre.org/
+# Lustre is a trademark of Sun Microsystems, Inc.
+#
+# Author: Robert Read <rread@clusterfs.com>
+#
 # Standard the comand line handling for all the python tools.
 
 import sys, getopt, types
@@ -28,6 +46,7 @@ class Options:
     FLAG = 1
     PARAM = 2
     INTPARAM = 3
+    PARAMLIST = 4
     def __init__(self, cmd, remain_help, options):
         self.options = options
         shorts = ""
@@ -36,9 +55,13 @@ class Options:
         for opt in options:
             long = self.long(opt)
             short = self.short(opt)
-            if self.type(opt) in (Options.PARAM, Options.INTPARAM):
-                if short:  short = short + ':'
-                if long: long = long + '='
+            if self.type(opt) in (Options.PARAM, Options.INTPARAM,
+                                  Options.PARAMLIST):
+                if short: short = short + ':'
+                if long:
+                    long = long + '='
+            if string.find(long, '_') >= 0:
+                longs.append(string.replace(long, '_', '-'))
             shorts = shorts + short
             longs.append(long)
         self.short_opts = shorts
@@ -77,6 +100,8 @@ class Options:
     def default(self, option):
         if len(option) >= 4:
             return option[3]
+        if self.type(option) == Options.PARAMLIST:
+            return []
         return None
 
     def lookup_option(self, key, key_func):
@@ -88,6 +113,7 @@ class Options:
         return self.lookup_option(key, self.short)
 
     def lookup_long(self, key):
+        key = string.replace(key, '-', '_')
         return self.lookup_option(key, self.long)
 
     def handle_opts(self, opts):
@@ -104,6 +130,9 @@ class Options:
                     val = int(a)
                 except ValueError, e:
                     raise error.OptionError("option: '%s' expects integer value, got '%s' "  % (o,a))
+            elif self.type(option) == Options.PARAMLIST:
+                val = values[self.key(option)];
+                val.append(a)
             else:
                 val = 1
             values[self.key(option)] = val
@@ -118,6 +147,11 @@ class Options:
                 return self.values[name]
             else:
                 raise error.OptionError("bad option name: " + name)
+        def __getitem__(self, name):
+            if self.values.has_key(name):
+                return self.values[name]
+            else:
+                raise error.OptionError("bad option name: " + name)
         def __setattr__(self, name, value):
             self.values[name] = value