Newer
Older
# __init__.py: Top level .py file for python parameterset interface
# Copyright (C) 2008
# ASTRON (Netherlands Institute for Radio Astronomy)
# P.O.Box 2, 7990 AA Dwingeloo, The Netherlands
# This file is part of the LOFAR software suite.
# The LOFAR software suite 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, either version 3 of the License, or
# The LOFAR software suite 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 the LOFAR software suite. If not, see <http://www.gnu.org/licenses/>.
class parametervalue(ParameterValue):
"""
The Python interface to ParameterValue
"""
def __init__(self, value, trim=True):
""" Create the parametervalue object.
value
The parameter value as a string.
trim
True = remove leading/trailing whitespace from value.
"""
ParameterValue.__init__ (self, value, trim);
def __str__(self):
"""
The Python interface to ParameterSet
"""
def __init__(self, filename=None, caseInsensitive=False):
"""Create a parameterset object.
filename
If a filename is given, the object is filled from that parset file.
If a bool is given, it is treated as argument caseInsensitive.
caseInsensitive
True = parameter names are case insensitive
"""
def __len__(self):
"""Get the number of parameters."""
return self.size()
"""Get the parametervalue object of a parameter."""
return self._get (key)
def keys(self):
"""Get a sorted list of all parameter names."""
return self.keywords()
def get(self, key):
"""Get the parametervalue object of a parameter."""
return self._get (key)
def getBoolVector(self, key, default=None, expandable=False):
"""Get the value as a list of boolean values.
key
Parameter name
default
Default value to be used if parameter is undefined.
If None is given, an exception is raised if undefined.
expandable
True = ranges and repeats (.. and *) are expanded first.
"""
if default==None:
return self._getBoolVector1 (key, expandable)
if isinstance(default, bool):
return self._getBoolVector1 (key, default)
return self._getBoolVector2 (key, default, expandable)
def getIntVector(self, key, default=None, expandable=False):
"""Get the value as a list of integer values.
key
Parameter name
default
Default value to be used if parameter is undefined.
If None is given, an exception is raised if undefined.
expandable
True = ranges and repeats (.. and *) are expanded first.
"""
if default==None:
return self._getIntVector1 (key, expandable)
if isinstance(default, bool):
return self._getIntVector1 (key, default)
return self._getIntVector2 (key, default, expandable)
def getFloatVector(self, key, default=None, expandable=False):
"""Get the value as a list of floating point values.
key
Parameter name
default
Default value to be used if parameter is undefined.
If None is given, an exception is raised if undefined.
expandable
True = ranges and repeats (.. and *) are expanded first.
"""
if default==None:
return self._getFloatVector1 (key, expandable)
if isinstance(default, bool):
return self._getFloatVector1 (key, default)
return self._getFloatVector2 (key, default, expandable)
def getDoubleVector(self, key, default=None, expandable=False):
"""Get the value as a list of floating point values.
key
Parameter name
default
Default value to be used if parameter is undefined.
If None is given, an exception is raised if undefined.
expandable
True = ranges and repeats (.. and *) are expanded first.
"""
if default==None:
return self._getDoubleVector1 (key, expandable)
if isinstance(default, bool):
return self._getDoubleVector1 (key, default)
return self._getDoubleVector2 (key, default, expandable)
def getStringVector(self, key, default=None, expandable=False):
"""Get the value as a list of string values.
key
Parameter name
default
Default value to be used if parameter is undefined.
If None is given, an exception is raised if undefined.
expandable
True = ranges and repeats (.. and *) are expanded first.
"""
if default==None:
return self._getStringVector1 (key, expandable)
if isinstance(default, bool):
return self._getStringVector1 (key, default)
return self._getStringVector2 (key, default, expandable)