Module EDCommandLine
[hide private]
[frames] | no frames]

Source Code for Module EDCommandLine

 1  # 
 2  #    Project: The EDNA Kernel 
 3  #             http://www.edna-site.org 
 4  # 
 5  #    File: "$Id$" 
 6  # 
 7  #    Copyright (C) 2008-2009 European Synchrotron Radiation Facility 
 8  #                            Grenoble, France 
 9  # 
10  #    Principal author: Karl Levik (karl.levik@diamond.ac.uk) 
11  # 
12  #    Contributing author: Olof Svensson (svensson@esrf.fr) 
13  #  
14  #    This program is free software: you can redistribute it and/or modify 
15  #    it under the terms of the GNU Lesser General Public License as published 
16  #    by the Free Software Foundation, either version 3 of the License, or 
17  #    (at your option) any later version. 
18  # 
19  #    This program is distributed in the hope that it will be useful, 
20  #    but WITHOUT ANY WARRANTY; without even the implied warranty of 
21  #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
22  #    GNU Lesser General Public License for more details. 
23  # 
24  #    You should have received a copy of the GNU General Public License 
25  #    and the GNU Lesser General Public License  along with this program.   
26  #    If not, see <http://www.gnu.org/licenses/>. 
27  # 
28   
29  __author__ = "Karl Levik" 
30  __contact__ = "karl.levik@diamnd.ac.uk" 
31  __license__ = "LGPLv3+" 
32  __copyright__ = "European Synchrotron Radiation Facility, Grenoble, France" 
33   
34  import shlex 
35   
36 -class EDCommandLine:
37 """ 38 Base class for command line objects. 39 """ 40
41 - def __init__(self, _strCommandLineArgument=None):
42 self.__strCommand = None 43 self.__listCommandLineArgument = [] 44 if (isinstance(_strCommandLineArgument, str)): 45 self.__strCommand = _strCommandLineArgument 46 self.__listCommandLineArgument = shlex.split(self.__strCommand) 47 elif (isinstance(_strCommandLineArgument, list)): 48 self.__listCommandLineArgument = [] 49 for cmdkey in _strCommandLineArgument: 50 self.__listCommandLineArgument.append(cmdkey)
51 52
53 - def getCommandLine(self):
54 if (self.__listCommandLineArgument != None): 55 self.__strCommand = "" 56 for cmdkey in self.__listCommandLineArgument: 57 self.__strCommand += cmdkey + " " 58 return self.__strCommand
59 60
61 - def getCommandLineArguments(self):
62 return self.__listCommandLineArgument
63 64
65 - def existCommand(self, _str):
66 return _str in self.__listCommandLineArgument
67 68
69 - def getArgument(self, _str):
70 for i in range(0, len(self.__listCommandLineArgument)): 71 strArgument = self.__listCommandLineArgument[i] 72 if (strArgument == _str): 73 j = i + 1 74 if j < len(self.__listCommandLineArgument): 75 return self.__listCommandLineArgument[j] 76 return None
77