Ver Fonte

refactroing for cmdparser

avkonst há 11 anos atrás
pai
commit
6ab5212282
2 ficheiros alterados com 21 adições e 42 exclusões
  1. 0 39
      mainline/mpp/cmdparser.py
  2. 21 3
      mainline/mpp/internal/loader.py

+ 0 - 39
mainline/mpp/cmdparser.py

@@ -1,39 +0,0 @@
-#
-#    Metrix++, Copyright 2009-2013, Metrix++ Project
-#    Link: http://metrixplusplus.sourceforge.net
-#    
-#    This file is a part of Metrix++ Tool.
-#    
-#    Metrix++ is free software: you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation, version 3 of the License.
-#    
-#    Metrix++ 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.
-#    
-#    You should have received a copy of the GNU General Public License
-#    along with Metrix++.  If not, see <http://www.gnu.org/licenses/>.
-#
-
-import optparse
-
-class MultiOptionParser(optparse.OptionParser):
-    
-    class MultipleOption(optparse.Option):
-        ACTIONS = optparse.Option.ACTIONS + ("multiopt",)
-        STORE_ACTIONS = optparse.Option.STORE_ACTIONS + ("multiopt",)
-        TYPED_ACTIONS = optparse.Option.TYPED_ACTIONS + ("multiopt",)
-        ALWAYS_TYPED_ACTIONS = optparse.Option.ALWAYS_TYPED_ACTIONS + ("multiopt",)
-    
-        def take_action(self, action, dest, opt, value, values, parser):
-            if action == "multiopt":
-                values.ensure_value(dest, []).append(value)
-            else:
-                optparse.Option.take_action(self, action, dest, opt, value, values, parser)
-
-    
-    def __init__(self, *args, **kwargs):
-        optparse.OptionParser.__init__(self, *args, option_class=self.MultipleOption, **kwargs)
-        

+ 21 - 3
mainline/mpp/internal/loader.py

@@ -18,12 +18,30 @@
 #
 
 import mpp.api
-import mpp.cmdparser
 
 import os
 import sys
 import ConfigParser
 import re
+import optparse
+
+class MultiOptionParser(optparse.OptionParser):
+    
+    class MultipleOption(optparse.Option):
+        ACTIONS = optparse.Option.ACTIONS + ("multiopt",)
+        STORE_ACTIONS = optparse.Option.STORE_ACTIONS + ("multiopt",)
+        TYPED_ACTIONS = optparse.Option.TYPED_ACTIONS + ("multiopt",)
+        ALWAYS_TYPED_ACTIONS = optparse.Option.ALWAYS_TYPED_ACTIONS + ("multiopt",)
+    
+        def take_action(self, action, dest, opt, value, values, parser):
+            if action == "multiopt":
+                values.ensure_value(dest, []).append(value)
+            else:
+                optparse.Option.take_action(self, action, dest, opt, value, values, parser)
+
+    
+    def __init__(self, *args, **kwargs):
+        optparse.OptionParser.__init__(self, *args, option_class=self.MultipleOption, **kwargs)
 
 class Loader(object):
 
@@ -134,7 +152,7 @@ class Loader(object):
             self.plugins.append(item)
             self.hash[plugin_name] = item
 
-        optparser = mpp.cmdparser.MultiOptionParser(
+        optparser = MultiOptionParser(
             usage = "Usage: python %prog --help\n" +
                     "       python %prog <action> --help\n" +
                     "       python %prog <action> [options] -- [path 1] ... [path N]\n" +
@@ -150,7 +168,7 @@ class Loader(object):
 
         self.action = command
 
-        optparser =mpp.cmdparser.MultiOptionParser(
+        optparser = MultiOptionParser(
             usage="Usage: python %prog --help\n"
                   "       python %prog {command} --help\n"
                   "       python %prog {command} [options] -- [path 1] ... [path N]".format(command=command))