From 2b85ca19470e1e313ef58838070038f2db8b8973 Mon Sep 17 00:00:00 2001 From: Ger van Diepen <diepen@astron.nl> Date: Wed, 29 Oct 2008 14:56:45 +0000 Subject: [PATCH] bug 1267: First version of ParameterSet python binding --- .gitattributes | 2 + LCS/pyparameterset/Makefile.am | 16 ++ LCS/pyparameterset/bootstrap | 3 + LCS/pyparameterset/configure.in | 74 ++++++ LCS/pyparameterset/package.dox | 3 + LCS/pyparameterset/pyparameterset.spec.in | 160 ++++++++++++ LCS/pyparameterset/src/Makefile.am | 17 ++ LCS/pyparameterset/src/__init__.py | 87 +++++++ LCS/pyparameterset/src/pyparameterset.cc | 233 ++++++++++++++++++ LCS/pyparameterset/test/Makefile.am | 15 ++ LCS/pyparameterset/test/tpyparameterset.in | 16 ++ LCS/pyparameterset/test/tpyparameterset.py | 74 ++++++ LCS/pyparameterset/test/tpyparameterset.run | 14 ++ LCS/pyparameterset/test/tpyparameterset.sh | 2 + .../test/tpyparameterset.stdout | 79 ++++++ LCS/pytools/Makefile.am | 12 + LCS/pytools/bootstrap | 3 + LCS/pytools/configure.in | 66 +++++ LCS/pytools/package.dox | 3 + LCS/pytools/src/Makefile.am | 16 ++ LCS/pytools/src/__init__.py | 21 ++ 21 files changed, 916 insertions(+) create mode 100644 LCS/pyparameterset/Makefile.am create mode 100755 LCS/pyparameterset/bootstrap create mode 100644 LCS/pyparameterset/configure.in create mode 100644 LCS/pyparameterset/package.dox create mode 100644 LCS/pyparameterset/pyparameterset.spec.in create mode 100644 LCS/pyparameterset/src/Makefile.am create mode 100755 LCS/pyparameterset/src/__init__.py create mode 100644 LCS/pyparameterset/src/pyparameterset.cc create mode 100644 LCS/pyparameterset/test/Makefile.am create mode 100644 LCS/pyparameterset/test/tpyparameterset.in create mode 100644 LCS/pyparameterset/test/tpyparameterset.py create mode 100755 LCS/pyparameterset/test/tpyparameterset.run create mode 100755 LCS/pyparameterset/test/tpyparameterset.sh create mode 100644 LCS/pyparameterset/test/tpyparameterset.stdout create mode 100644 LCS/pytools/Makefile.am create mode 100755 LCS/pytools/bootstrap create mode 100644 LCS/pytools/configure.in create mode 100644 LCS/pytools/package.dox create mode 100644 LCS/pytools/src/Makefile.am create mode 100755 LCS/pytools/src/__init__.py diff --git a/.gitattributes b/.gitattributes index 51307ad2fd9..797c1ac59a3 100644 --- a/.gitattributes +++ b/.gitattributes @@ -283,6 +283,8 @@ LCS/Common/src/Common-Model.cat -text LCS/Common/test/CMakeLists.txt -text LCS/LACE/bootstrap -text LCS/Stream/bootstrap -text +LCS/pyparameterset/bootstrap -text +LCS/pytools/bootstrap -text MAC/APL/APLCommon/Makefile.am -text svneol=native#application/octet-stream MAC/APL/APLCommon/bootstrap -text svneol=native#application/octet-stream MAC/APL/APLCommon/configure.in -text svneol=native#application/octet-stream diff --git a/LCS/pyparameterset/Makefile.am b/LCS/pyparameterset/Makefile.am new file mode 100644 index 00000000000..469fba2fe46 --- /dev/null +++ b/LCS/pyparameterset/Makefile.am @@ -0,0 +1,16 @@ +SUBDIRS=src test + +ACLOCAL_AMFLAGS = -I $(top_srcdir)/autoconf_share + +pkgextdir = $(prefix)/config/$(PACKAGE) +pkgext_DATA = pkgext pkgextcppflags pkgextcxxflags pkgextldflags + +DISTCHECK_CONFIGURE_FLAGS=\ + --with-common=$(prefix) + +EXTRA_DIST = \ + Makefile.common \ + pyparameterset.spec \ + autoconf_share/compiletool + +include $(top_srcdir)/Makefile.common diff --git a/LCS/pyparameterset/bootstrap b/LCS/pyparameterset/bootstrap new file mode 100755 index 00000000000..fd49f5826a5 --- /dev/null +++ b/LCS/pyparameterset/bootstrap @@ -0,0 +1,3 @@ +#!/bin/sh + +../../autoconf_share/bootstrap ../../autoconf_share diff --git a/LCS/pyparameterset/configure.in b/LCS/pyparameterset/configure.in new file mode 100644 index 00000000000..e4106ad331f --- /dev/null +++ b/LCS/pyparameterset/configure.in @@ -0,0 +1,74 @@ +dnl +dnl Process this file with autoconf to produce a configure script. +dnl +AC_INIT +dnl AC_CONFIG_AUX_DIR(config) +dnl AM_CONFIG_HEADER(config/config.h) +AM_CONFIG_HEADER(config.h) +AM_INIT_AUTOMAKE(pyparameterset, 1.0, no-define) + +dnl Initialize for LOFAR (may set compilers) +lofar_INIT + +dnl Checks for programs. +AC_PROG_AWK +AC_PROG_YACC +AC_PROG_CC +AC_PROG_CXX +AM_PROG_LEX +AC_PROG_INSTALL +AC_PROG_LN_S +dnl AC_DISABLE_SHARED +AC_PROG_LIBTOOL + +dnl Checks for libraries. + +dnl dnl Replace `main' with a function in -lfl: +dnl AC_CHECK_LIB(fl, main) +dnl dnl Replace `main' with a function in -lcosev_r: +dnl AC_CHECK_LIB(cosev_r, main) +dnl dnl Replace `main' with a function in -lcosnm_r: +dnl AC_CHECK_LIB(cosnm_r, main) +dnl dnl Replace `main' with a function in -lorb_r: +dnl AC_CHECK_LIB(orb_r, main) +dnl dnl Replace `main' with a function in -lpthread: +dnl AC_CHECK_LIB(pthread, main) +dnl dnl Replace `main' with a function in -lvport_r: +dnl AC_CHECK_LIB(vport_r, main) + +dnl Checks for header files. +AC_HEADER_STDC +AC_CHECK_HEADERS(unistd.h) + +dnl Checks for typedefs, structures, and compiler characteristics. +AC_C_CONST +AC_TYPE_SIZE_T + +dnl Checks for library functions. +AC_FUNC_VPRINTF + +dnl Checks for Python +AM_PATH_PYTHON + +dnl +dnl Check for LOFAR specific things +dnl +lofar_GENERAL +lofar_INTERNAL(LCS/ACC/APS,APS,,1,APS/ParameterSet.h) +lofar_INTERNAL(LCS/Common,Common,,1,Common/LofarTypedefs.h) +lofar_INTERNAL(LCS/pytools,pytools,,1,pytools/Package__Version.h) + +lofar_EXTERNAL(pyrap,1,pyrap/Converters/PycBasicData.h) +lofar_AIPSPP(1,"-lcasa") +lofar_EXTERNAL(boost,1,boost/python.hpp,boost_python) +lofar_PYTHON(1) + +dnl +dnl Output Makefiles +dnl +AC_OUTPUT( +src/Makefile +test/Makefile +Makefile +pyparameterset.spec +) diff --git a/LCS/pyparameterset/package.dox b/LCS/pyparameterset/package.dox new file mode 100644 index 00000000000..12331c0f3cb --- /dev/null +++ b/LCS/pyparameterset/package.dox @@ -0,0 +1,3 @@ +// \ingroup LCS +// \defgroup pyparameterset pyparamterset +// Python binding to ParameterSet class. diff --git a/LCS/pyparameterset/pyparameterset.spec.in b/LCS/pyparameterset/pyparameterset.spec.in new file mode 100644 index 00000000000..9f13651d763 --- /dev/null +++ b/LCS/pyparameterset/pyparameterset.spec.in @@ -0,0 +1,160 @@ +# -*- Mode:rpm-spec -*- +# ParmFacade.spec.in +# + +############################################################################## +# +# Preamble +# +############################################################################## + +Summary: ParmFacade is the high level access to the Parameter Data Base + +%define release @RPM_RELEASE@ +%define version @VERSION@ +%define pkgname @PACKAGE@ +%define pkgdir %{pkgname}-%{version}-%{release} +%define prefix /opt/lofar +%define configure_args @RPM_CONFIGURE_ARGS@ +##define build_kernel_version @BUILD_KERNEL_VERSION@ + +Name: %{pkgname} +Version: %{version} +Release: %{release} +Copyright: LGPL +Group: Application/System +Source: %{pkgname}-%{version}.tar.gz +BuildRoot: %{_tmppath}/%{pkgdir}-root +URL: http://www.astron.nl +Prefix: %{prefix} +BuildArchitectures: i386 # Target platforms, i.e., i586 +##Requires: Common = 1.2 ## define dependent packages here +Packager: %{packager} +Distribution: The LOFAR project +Vendor: ASTRON + +AutoReqProv: no + +%description + +ParmFacade is the high level access to the Parameter Data Base. + +############################################################################## +# +# prep +# +############################################################################## +%prep +echo $prefix + +# create the build directory, untar the source +%setup + +############################################################################## +# +# build +# +############################################################################## +%build +./configure %{configure_args} --prefix=%{prefix} && make + +############################################################################## +# +# install +# +############################################################################## +%install +# To make things work with BUILDROOT +if [ "$RPM_BUILD_ROOT" != "%{_tmppath}/%{pkgdir}-root" ] +then + echo + echo @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ + echo @ @ + echo @ RPM_BUILD_ROOT is not what I expected. Please clean it yourself. @ + echo @ @ + echo @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ + echo +else + echo Cleaning RPM_BUILD_ROOT: "$RPM_BUILD_ROOT" + rm -rf "$RPM_BUILD_ROOT" +fi +mkdir -p $RPM_BUILD_ROOT%{prefix} +make DESTDIR="$RPM_BUILD_ROOT" install + +#uninstall + +############################################################################## +# +# verify +# +############################################################################## +#verify + +############################################################################## +# +# clean +# +############################################################################## +%clean +# Call me paranoid, but I do not want to be responsible for nuking +# someone's harddrive! +if [ "$RPM_BUILD_ROOT" != "%{_tmppath}/%{pkgdir}-root" ] +then + echo + echo @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ + echo @ @ + echo @ RPM_BUILD_ROOT is not what I expected. Please clean it yourself. @ + echo @ @ + echo @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ + echo +else + echo Cleaning RPM_BUILD_ROOT: "$RPM_BUILD_ROOT" + rm -rf "$RPM_BUILD_ROOT" +fi + +############################################################################## +# +# files +# +############################################################################## + +# empty 'files' means all distributed files +%files +%defattr(-, root, root) +%{prefix} + +# Your application file list goes here +# %{prefix}/lib/lib*.so* + +# Documentation +# doc COPYING ChangeLog README AUTHORS NEWS +# doc doc/* + +# link the module to the correct path +%post + +# before uninstall +%preun + +# after uninstall +%postun + +############################################################################## +# +# package devel +# +############################################################################## + +#package devel +#Summary: Development files for %{pkgname} +#Group: Applications/System +#description devel +#Development files for %{pkgname}. + +#files devel + +# Your development files go here +# Programmers documentation goes here +#doc doc + +# end of file diff --git a/LCS/pyparameterset/src/Makefile.am b/LCS/pyparameterset/src/Makefile.am new file mode 100644 index 00000000000..255432b6140 --- /dev/null +++ b/LCS/pyparameterset/src/Makefile.am @@ -0,0 +1,17 @@ +lib_LTLIBRARIES = _pyparameterset.la + +_pyparameterset_la_SOURCES = pyparameterset.cc +# Needed for non-standard library name (i.e. not lib...) +_pyparameterset_la_LDFLAGS = -module +_pyparameterset_la_DEPENDENCIES = $(LOFAR_DEPEND) + +python_SCRIPTS = __init__.py +pythondir = $(prefix)/lib/python$(PYTHON_VERSION)/site-packages/lofar/parameterset +libdir = $(pythondir) + +bin_PROGRAMS = versionpyparameterset + +versionpyparameterset_SOURCES = versionpyparameterset.cc Package__Version.cc +versionpyparameterset_DEPENDENCIES = $(LOFAR_DEPEND) + +include $(top_srcdir)/Makefile.common diff --git a/LCS/pyparameterset/src/__init__.py b/LCS/pyparameterset/src/__init__.py new file mode 100755 index 00000000000..cf5cbd16d8a --- /dev/null +++ b/LCS/pyparameterset/src/__init__.py @@ -0,0 +1,87 @@ +# __init__.py: Top level .py file for python parameterset interface +# Copyright (C) 2008 +# ASTRON (Netherlands Foundation for Research in Astronomy) +# P.O.Box 2, 7990 AA Dwingeloo, The Netherlands, seg@astron.nl +# +# This program 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 2 of the License, or +# (at your option) any later version. +# +# 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 for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# $Id$ + +from _pyparameterset import ParameterValue +from _pyparameterset import ParameterSet + + +class parametervalue(ParameterValue): + """ + The Python interface to ParameterValue + """ + + def __init__(self, value, trim=True): + ParameterValue.__init__ (self, value, trim); + + def __str__(self): + return self.get() + + +class parameterset(ParameterSet): + """ + The Python interface to ParameterSet + """ + + def __init__(self, filename=None, caseInsensitive=False): + if filename==None: + ParameterSet.__init__ (self, caseInsensitive); + elif isinstance(filename, bool): + ParameterSet.__init__ (self, filename); + else: + ParameterSet.__init__ (self, filename, caseInsensitive); + + def __getitem__(self, key): + return self.get (key) + + def getBoolVector(self, key, default=None, expandable=False): + 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): + 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): + 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): + 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): + if default==None: + return self._getStringVector1 (key, expandable) + if isinstance(default, bool): + return self._getStringVector1 (key, default) + return self._getStringVector2 (key, default, expandable) diff --git a/LCS/pyparameterset/src/pyparameterset.cc b/LCS/pyparameterset/src/pyparameterset.cc new file mode 100644 index 00000000000..569b11624b2 --- /dev/null +++ b/LCS/pyparameterset/src/pyparameterset.cc @@ -0,0 +1,233 @@ +//# pyparameterset.cc: python module for ParameterSet class +//# Copyright (C) 2008 +//# ASTRON (Netherlands Foundation for Research in Astronomy) +//# P.O.Box 2, 7990 AA Dwingeloo, The Netherlands, seg@astron.nl +//# +//# This program 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 2 of the License, or +//# (at your option) any later version. +//# +//# 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 for more details. +//# +//# You should have received a copy of the GNU General Public License +//# along with this program; if not, write to the Free Software +//# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +//# +//# $Id$ + +#include <lofar_config.h> +#include <APS/ParameterSet.h> + +#include <pyrap/Converters/PycExcp.h> +#include <pyrap/Converters/PycBasicData.h> +#include <pyrap/Converters/PycRecord.h> +#include <pyrap/Converters/PycBasicData.h> +#include <boost/python.hpp> +#include <boost/python/args.hpp> + +using namespace boost::python; +using namespace casa::pyrap; + +namespace LOFAR { namespace ACC { namespace APS { + + // Define function pointers for overloaded functions to be able to tell + // boost-python which function to take. + void (ParameterSet::*fadd)(const string&, const string&) = + &ParameterSet::add; + void (ParameterSet::*freplace)(const string&, const string&) = + &ParameterSet::replace; + + bool (ParameterSet::*fgetbool1)(const string&) const = + &ParameterSet::getBool; + bool (ParameterSet::*fgetbool2)(const string&, bool) const = + &ParameterSet::getBool; + vector<bool> (ParameterSet::*fgetvecbool1)(const string&, bool) const = + &ParameterSet::getBoolVector; + vector<bool> (ParameterSet::*fgetvecbool2)(const string&, const vector<bool>&, bool) const = + &ParameterSet::getBoolVector; + + int (ParameterSet::*fgetint1)(const string&) const = + &ParameterSet::getInt; + int (ParameterSet::*fgetint2)(const string&, int) const = + &ParameterSet::getInt; + vector<int> (ParameterSet::*fgetvecint1)(const string&, bool) const = + &ParameterSet::getIntVector; + vector<int> (ParameterSet::*fgetvecint2)(const string&, const vector<int>&, bool) const = + &ParameterSet::getIntVector; + + float (ParameterSet::*fgetfloat1)(const string&) const = + &ParameterSet::getFloat; + float (ParameterSet::*fgetfloat2)(const string&, float) const = + &ParameterSet::getFloat; + vector<float> (ParameterSet::*fgetvecfloat1)(const string&, bool) const = + &ParameterSet::getFloatVector; + vector<float> (ParameterSet::*fgetvecfloat2)(const string&, const vector<float>&, bool) const = + &ParameterSet::getFloatVector; + + double (ParameterSet::*fgetdouble1)(const string&) const = + &ParameterSet::getDouble; + double (ParameterSet::*fgetdouble2)(const string&, double) const = + &ParameterSet::getDouble; + vector<double> (ParameterSet::*fgetvecdouble1)(const string&, bool) const = + &ParameterSet::getDoubleVector; + vector<double> (ParameterSet::*fgetvecdouble2)(const string&, const vector<double>&, bool) const = + &ParameterSet::getDoubleVector; + + string (ParameterSet::*fgetstring1)(const string&) const = + &ParameterSet::getString; + string (ParameterSet::*fgetstring2)(const string&, const string&) const = + &ParameterSet::getString; + vector<string> (ParameterSet::*fgetvecstring1)(const string&, bool) const = + &ParameterSet::getStringVector; + vector<string> (ParameterSet::*fgetvecstring2)(const string&, const vector<string>&, bool) const = + &ParameterSet::getStringVector; + + + // Define the python interface to ParameterValue. + void pyparametervalue() + { + class_<ParameterValue> ("ParameterValue", + init<std::string, bool>()) + + .def ("get", &ParameterValue::get, + return_value_policy < copy_const_reference> ()) + .def ("expand", &ParameterValue::expand) + .def ("isVector", &ParameterValue::isVector) + .def ("getVector", &ParameterValue::getVector) + .def ("getBool", &ParameterValue::getBool) + .def ("getInt", &ParameterValue::getInt) + .def ("getFloat", &ParameterValue::getFloat) + .def ("getDouble", &ParameterValue::getDouble) + .def ("getString", &ParameterValue::getString) + .def ("getBoolVector", &ParameterValue::getBoolVector) + .def ("getIntVector", &ParameterValue::getIntVector) + .def ("getFloatVector", &ParameterValue::getFloatVector) + .def ("getDoubleVector", &ParameterValue::getDoubleVector) + .def ("getStringVector", &ParameterValue::getStringVector) + ; + } + + + // Define the python interface to ParameterSet. + void pyparameterset() + { + class_<ParameterSet> ("ParameterSet") + .def (init<bool>()) + .def (init<std::string, bool>()) + + .def ("size", &ParameterSet::size) + .def ("__len__", &ParameterSet::size) + .def ("makeSubset", &ParameterSet::makeSubset, + (boost::python::arg("baseKey"), + boost::python::arg("prefix")="")) + .def ("subtractSubset", &ParameterSet::subtractSubset, + (boost::python::arg("baseKey"))) + .def ("adoptFile", &ParameterSet::adoptFile, + (boost::python::arg("filename"), + boost::python::arg("prefix")="")) + .def ("writeFile", &ParameterSet::writeFile, + (boost::python::arg("filename"), + boost::python::arg("append")=false)) + .def ("add", fadd, + (boost::python::arg("key"), + boost::python::arg("value"))) + .def ("replace", freplace, + (boost::python::arg("key"), + boost::python::arg("value"))) + .def ("remove", &ParameterSet::remove, + (boost::python::arg("key"))) + .def ("clear", &ParameterSet::clear) + .def ("isDefined", &ParameterSet::isDefined, + (boost::python::arg("key"))) + .def ("get", &ParameterSet::get, + return_value_policy < copy_const_reference> (), + (boost::python::arg("key"))) + + .def ("getBool", fgetbool1, + (boost::python::arg("key"))) + .def ("getBool", fgetbool2, + (boost::python::arg("key"), + boost::python::arg("default"))) + .def ("getInt", fgetint1, + (boost::python::arg("key"))) + .def ("getInt", fgetint2, + (boost::python::arg("key"), + boost::python::arg("default"))) + .def ("getFloat", fgetfloat1, + (boost::python::arg("key"))) + .def ("getFloat", fgetfloat2, + (boost::python::arg("key"), + boost::python::arg("default"))) + .def ("getDouble", fgetdouble1, + (boost::python::arg("key"))) + .def ("getDouble", fgetdouble2, + (boost::python::arg("key"), + boost::python::arg("default"))) + .def ("getString", fgetstring1, + (boost::python::arg("key"))) + .def ("getString", fgetstring2, + (boost::python::arg("key"), + boost::python::arg("default"))) + + .def ("_getBoolVector1", fgetvecbool1, + (boost::python::arg("key"), + boost::python::arg("expandable"))) + .def ("_getBoolVector2", fgetvecbool2, + (boost::python::arg("key"), + boost::python::arg("default"), + boost::python::arg("expandable"))) + .def ("_getIntVector1", fgetvecint1, + (boost::python::arg("key"), + boost::python::arg("expandable"))) + .def ("_getIntVector2", fgetvecint2, + (boost::python::arg("key"), + boost::python::arg("default"), + boost::python::arg("expandable"))) + .def ("_getFloatVector1", fgetvecfloat1, + (boost::python::arg("key"), + boost::python::arg("expandable"))) + .def ("_getFloatVector2", fgetvecfloat2, + (boost::python::arg("key"), + boost::python::arg("default"), + boost::python::arg("expandable"))) + .def ("_getDoubleVector1", fgetvecdouble1, + (boost::python::arg("key"), + boost::python::arg("expandable"))) + .def ("_getDoubleVector2", fgetvecdouble2, + (boost::python::arg("key"), + boost::python::arg("default"), + boost::python::arg("expandable"))) + .def ("_getStringVector1", fgetvecstring1, + (boost::python::arg("key"), + boost::python::arg("expandable"))) + .def ("_getStringVector2", fgetvecstring2, + (boost::python::arg("key"), + boost::python::arg("default"), + boost::python::arg("expandable"))) + + ; + } + +}}} + + +// Define the python module itself. +BOOST_PYTHON_MODULE(_pyparameterset) +{ + casa::pyrap::register_convert_excp(); + casa::pyrap::register_convert_basicdata(); + casa::pyrap::register_convert_std_vector<LOFAR::ACC::APS::ParameterValue>(); + casa::pyrap::register_convert_std_vector<bool>(); + casa::pyrap::register_convert_std_vector<int>(); + casa::pyrap::register_convert_std_vector<float>(); + casa::pyrap::register_convert_std_vector<double>(); + casa::pyrap::register_convert_std_vector<std::string>(); + // casa::pyrap::register_convert_casa_record(); + + LOFAR::ACC::APS::pyparametervalue(); + LOFAR::ACC::APS::pyparameterset(); +} diff --git a/LCS/pyparameterset/test/Makefile.am b/LCS/pyparameterset/test/Makefile.am new file mode 100644 index 00000000000..c7ff7792b4a --- /dev/null +++ b/LCS/pyparameterset/test/Makefile.am @@ -0,0 +1,15 @@ +# scripts used to run tests +TESTSCRIPTS = tpyparameterset.sh + +# scripts and possible programs to run tests +TESTS = $(TESTSCRIPTS) + +XFAIL_TESTS = + +# all files (.run, .stdout, .in, .log_prop, etc.) needed to run tests +EXTRA_DIST = $(TESTSCRIPTS) \ + tpyparameterset.run tpyparameterset.py + tpyparameterset.in tpyparameterset.stdout + + +include $(top_srcdir)/Makefile.common diff --git a/LCS/pyparameterset/test/tpyparameterset.in b/LCS/pyparameterset/test/tpyparameterset.in new file mode 100644 index 00000000000..9e9326721b9 --- /dev/null +++ b/LCS/pyparameterset/test/tpyparameterset.in @@ -0,0 +1,16 @@ +# comment line +a.b=7 +# the next two lines overlap with the KVs in test.ps +a.b.lange_naam="dit is nu een andere naam geworden met extra spaties aan het einde " +a.b.c=5 +a.b.double= 3.1415926 # we may put comment here +a.b.bool = true + +e.g=een voorbeeld +egg=een ei + +vecbool=[true,false,true] +vec=[1,2,3] +vecexp=[1..3,5..10] + +vecnest=[[1..3,5*10],[5..10]] diff --git a/LCS/pyparameterset/test/tpyparameterset.py b/LCS/pyparameterset/test/tpyparameterset.py new file mode 100644 index 00000000000..f89cefb5460 --- /dev/null +++ b/LCS/pyparameterset/test/tpyparameterset.py @@ -0,0 +1,74 @@ +from lofar.parameterset import * + +def checkps (ps): + print ps.isDefined("key1") + print ps.isDefined("a.b") + print ps.get("a.b").get() + print ps.getString("a.b") + print ps.getString("a.b", "aa") + print ps.getString("aa.bb", "aa") + + print ps.getString("a.b.lange_naam") + + print ps.getBool(key="a.b.bool") + print ps.getBool("a.b.bool", False) + print ps.getBool("aa.bb", False) + + print ps.getInt("a.b") + print ps.getInt("a.b", 10) + print ps.getInt("aa.bb", 10) + + print ps.getFloat("a.b") + print ps.getFloat("a.b", 3.14) + print ps.getFloat("aa.bb", 3.14) + print ps.getDouble("a.b.double") + + print ps.getBoolVector("vecbool") + print ps.getBoolVector("vecbool", (False,True)) + print ps.getBoolVector("aa.bb", [False,True]) + + print ps.getIntVector("vec") + print ps.getIntVector("vec", (5,6)) + print ps.getIntVector("aa.bb", [5,6]) + + print ps.getFloatVector("vec") + print ps.getFloatVector("vec", (5,6)) + print ps.getFloatVector("aa.bb", [5,6]) + + print ps.getDoubleVector("vec") + print ps.getDoubleVector("vec", (5,6)) + print ps.getDoubleVector("aa.bb", [5,6]) + + print ps.getStringVector("vec") + print ps.getStringVector("vec", ('5','6')) + print ps.getStringVector("aa.bb", ['5','6']) + + print ps.getIntVector("vecexp", True) + print ps.getIntVector("vecexp", [1,2], True) + print ps.getIntVector("aa.bb", [1,2], True) + + pvs = ps["vecnest"] + print pvs.isVector() + pvsvec = pvs.getVector() + print pvsvec[0].get() + print pvsvec[0].expand().getIntVector() + print pvsvec[1].expand().getIntVector() + +# Check using given parset file. +checkps (parameterset("tpyparameterset.in")) +print "" + +# Create and check a new parset using same keys/values as in parset file. +ps=parameterset() +ps.add ("a.b", "7") +ps.add ("a.b.lange_naam", "dit is nu een andere naam geworden met extra spaties aan het einde ") +ps.add ("a.b.c", "5") +ps.add ("a.b.double", "3.1415926") +ps.add ("a.b.bool", "true") +ps.add ("e.g", "een voorbeeld") +ps.add ("egg", "een ei") +ps.add ("vecbool", "[true,false,true]") +ps.add ("vec", "[1,2,3]") +ps.add ("vecexp", "[1..3,5..10]") +ps.add ("vecnest", "[[1..3,5*10],[5..10]]") +checkps (ps) diff --git a/LCS/pyparameterset/test/tpyparameterset.run b/LCS/pyparameterset/test/tpyparameterset.run new file mode 100755 index 00000000000..e9edd26701a --- /dev/null +++ b/LCS/pyparameterset/test/tpyparameterset.run @@ -0,0 +1,14 @@ +#! /bin/sh + +if test "$srcdir" = ""; then + srcdir="../../../test" +fi +PYTHONPATH=`pwd`:$PYTHONPATH +export PYTHONPATH + +mkdir -p lofar/parameterset +touch lofar/__init__.py +cp $srcdir/../src/*.py lofar/parameterset +cp ../src/.libs/_pyparameterset.so lofar/parameterset + +python tpyparameterset.py diff --git a/LCS/pyparameterset/test/tpyparameterset.sh b/LCS/pyparameterset/test/tpyparameterset.sh new file mode 100755 index 00000000000..08deaaccd5c --- /dev/null +++ b/LCS/pyparameterset/test/tpyparameterset.sh @@ -0,0 +1,2 @@ +#!/bin/sh +$lofar_sharedir/runtest.sh tpyparameterset > tpyparameterset.log 2>&1 diff --git a/LCS/pyparameterset/test/tpyparameterset.stdout b/LCS/pyparameterset/test/tpyparameterset.stdout new file mode 100644 index 00000000000..9ae10260061 --- /dev/null +++ b/LCS/pyparameterset/test/tpyparameterset.stdout @@ -0,0 +1,79 @@ +False +True +7 +7 +7 +aa +dit is nu een andere naam geworden met extra spaties aan het einde +True +True +False +7 +7 +10 +7.0 +7.0 +3.1400001049 +3.1415926 +[True, False, True] +[True, False, True] +[False, True] +[1, 2, 3] +[1, 2, 3] +[5, 6] +[1.0, 2.0, 3.0] +[1.0, 2.0, 3.0] +[5.0, 6.0] +[1.0, 2.0, 3.0] +[1.0, 2.0, 3.0] +[5.0, 6.0] +['1', '2', '3'] +['1', '2', '3'] +['5', '6'] +[1, 2, 3, 5, 6, 7, 8, 9, 10] +[1, 2, 3, 5, 6, 7, 8, 9, 10] +[1, 2] +True +[1..3,5*10] +[1, 2, 3, 10, 10, 10, 10, 10] +[5, 6, 7, 8, 9, 10] + +False +True +7 +7 +7 +aa +dit is nu een andere naam geworden met extra spaties aan het einde +True +True +False +7 +7 +10 +7.0 +7.0 +3.1400001049 +3.1415926 +[True, False, True] +[True, False, True] +[False, True] +[1, 2, 3] +[1, 2, 3] +[5, 6] +[1.0, 2.0, 3.0] +[1.0, 2.0, 3.0] +[5.0, 6.0] +[1.0, 2.0, 3.0] +[1.0, 2.0, 3.0] +[5.0, 6.0] +['1', '2', '3'] +['1', '2', '3'] +['5', '6'] +[1, 2, 3, 5, 6, 7, 8, 9, 10] +[1, 2, 3, 5, 6, 7, 8, 9, 10] +[1, 2] +True +[1..3,5*10] +[1, 2, 3, 10, 10, 10, 10, 10] +[5, 6, 7, 8, 9, 10] diff --git a/LCS/pytools/Makefile.am b/LCS/pytools/Makefile.am new file mode 100644 index 00000000000..d663ffdd1e7 --- /dev/null +++ b/LCS/pytools/Makefile.am @@ -0,0 +1,12 @@ +SUBDIRS=src + +ACLOCAL_AMFLAGS = -I $(top_srcdir)/autoconf_share + +pkgextdir = $(prefix)/config/$(PACKAGE) +pkgext_DATA = pkgext pkgextcppflags pkgextcxxflags pkgextldflags + +EXTRA_DIST = \ + Makefile.common \ + autoconf_share/compiletool + +include $(top_srcdir)/Makefile.common diff --git a/LCS/pytools/bootstrap b/LCS/pytools/bootstrap new file mode 100755 index 00000000000..fd49f5826a5 --- /dev/null +++ b/LCS/pytools/bootstrap @@ -0,0 +1,3 @@ +#!/bin/sh + +../../autoconf_share/bootstrap ../../autoconf_share diff --git a/LCS/pytools/configure.in b/LCS/pytools/configure.in new file mode 100644 index 00000000000..4a92c48cca9 --- /dev/null +++ b/LCS/pytools/configure.in @@ -0,0 +1,66 @@ +dnl +dnl Process this file with autoconf to produce a configure script. +dnl +AC_INIT +dnl AC_CONFIG_AUX_DIR(config) +dnl AM_CONFIG_HEADER(config/config.h) +AM_CONFIG_HEADER(config.h) +AM_INIT_AUTOMAKE(pytools, 1.0, no-define) + +dnl Initialize for LOFAR (may set compilers) +lofar_INIT + +dnl Checks for programs. +AC_PROG_AWK +AC_PROG_YACC +AC_PROG_CC +AC_PROG_CXX +AM_PROG_LEX +AC_PROG_INSTALL +AC_PROG_LN_S +dnl AC_DISABLE_SHARED +AC_PROG_LIBTOOL + +dnl Checks for libraries. + +dnl dnl Replace `main' with a function in -lfl: +dnl AC_CHECK_LIB(fl, main) +dnl dnl Replace `main' with a function in -lcosev_r: +dnl AC_CHECK_LIB(cosev_r, main) +dnl dnl Replace `main' with a function in -lcosnm_r: +dnl AC_CHECK_LIB(cosnm_r, main) +dnl dnl Replace `main' with a function in -lorb_r: +dnl AC_CHECK_LIB(orb_r, main) +dnl dnl Replace `main' with a function in -lpthread: +dnl AC_CHECK_LIB(pthread, main) +dnl dnl Replace `main' with a function in -lvport_r: +dnl AC_CHECK_LIB(vport_r, main) + +dnl Checks for header files. +AC_HEADER_STDC +AC_CHECK_HEADERS(unistd.h) + +dnl Checks for typedefs, structures, and compiler characteristics. +AC_C_CONST +AC_TYPE_SIZE_T + +dnl Checks for library functions. +AC_FUNC_VPRINTF + +dnl Checks for Python +AM_PATH_PYTHON + +dnl +dnl Check for LOFAR specific things +dnl +lofar_GENERAL +lofar_INTERNAL(LCS/Common,Common,,1,Common/LofarTypedefs.h) +lofar_PYTHON(1) + +dnl +dnl Output Makefiles +dnl +AC_OUTPUT( +src/Makefile +Makefile +) diff --git a/LCS/pytools/package.dox b/LCS/pytools/package.dox new file mode 100644 index 00000000000..52df9730682 --- /dev/null +++ b/LCS/pytools/package.dox @@ -0,0 +1,3 @@ +// \ingroup LCS +// \defgroup pytools pytools +// Standard files needed for Python code and bindings to C++ classes. diff --git a/LCS/pytools/src/Makefile.am b/LCS/pytools/src/Makefile.am new file mode 100644 index 00000000000..a621b0496df --- /dev/null +++ b/LCS/pytools/src/Makefile.am @@ -0,0 +1,16 @@ +pkginclude_HEADERS = Package__Version.h + +lib_LTLIBRARIES = libpytools.la + +libpytools_la_SOURCES = Package__Version.cc + +bin_PROGRAMS = versionpytools + +versionpytools_SOURCES = versionpytools.cc +versionpytools_LDADD = libpytools.la +versionpytools_DEPENDENCIES = libpytools.la $(LOFAR_DEPEND) + +dist_python_SCRIPTS = __init__.py +pythondir = $(prefix)/lib/python$(PYTHON_VERSION)/site-packages/lofar + +include $(top_srcdir)/Makefile.common diff --git a/LCS/pytools/src/__init__.py b/LCS/pytools/src/__init__.py new file mode 100755 index 00000000000..e0b3c685263 --- /dev/null +++ b/LCS/pytools/src/__init__.py @@ -0,0 +1,21 @@ +# __init__.py: Top level .py file for LOFAR +# Copyright (C) 2007 +# ASTRON (Netherlands Foundation for Research in Astronomy) +# P.O.Box 2, 7990 AA Dwingeloo, The Netherlands, seg@astron.nl +# +# This program 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 2 of the License, or +# (at your option) any later version. +# +# 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 for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# $Id$ + -- GitLab