00001 /*! 00002 \mainpage 00003 00004 \section PyDIM 00005 00006 PyDIM is a Python interface to <a href="http://dim.web.cern.ch/dim/">DIM</a>. 00007 PyDIM could be used to create DIM clients and servers, using an API very similar 00008 to the one that is used for <a href="http://dim.web.cern.ch/dim/dimC.html">C</a>. 00009 00010 \section requirements Requirements 00011 00012 \subsection requirements-dim DIM 00013 00014 As the name suggest, the package relies on the DIM package. 00015 00016 PyDIM has been developed using the v16rXX, v17rXX and v18r0 DIM versions and 00017 works with any. It has not been tested with older versions but I believe it 00018 has good chances to work. 00019 It does not depend on the DIM internals but only on DIM's API. 00020 This is why it should be compatible with a wide range of DIM versions. 00021 00022 \subsection requirements-python Python 00023 00024 PyDIM has been tested with Python 2.3, 2.4 and 2.5. 00025 00026 Note: The package has been developed on both 32 and 64 bits architectures. 00027 00028 \section install Installation 00029 00030 \subsection build Building the package from scratch and installing it: 00031 -# Install DIM. I would suggest placing the DIM libraries and header files in 00032 <code>/usr/local/lib</code> and <code>/usr/local/include</code> respectively. 00033 Please make the necessary changes so that the run-time linker finds libdim.so 00034 (basically add an entry in /etc/ld.so.conf that points to the DIM library directory). 00035 Make sure that the DIM library is built using the <b>same</b> compiler and 00036 architecture as the Python installation you want to use. 00037 -# Get the latest SVN version: <code>svn co svn+ssh://lbgw02/group/online/SVN_REPOS/PyDIM</code> or from CVS (TODO: add link to the official Online CVS) 00038 -# cd to the PyDIM directory and execute "sudo make install". 00039 00040 In the general case this should take care of building the library. 00041 00042 If the DIM libraries are not installed in the usual locations, the install 00043 script will look for an environment variable with the actual location. The 00044 variables that can be used are: 00045 00046 - DIMDIR 00047 - DIMHOME 00048 - DIM_HOME 00049 00050 Remember to point that variable to the main DIM installation directory, i.e. the 00051 one that contains the sub-directories <code>dim</code> and the specific one for 00052 your operating system, e.g. <code>linux</code>. 00053 00054 For building on Windows you will need the same compiler (the same cl version) 00055 as the one used to build DIM. 00056 At this point, the default DIM C compiler is included in the Microsoft .Net 2003 00057 framework. 00058 Ideally the Python interpreter should be build using the same compiler (any Python 00059 version > 2.3 should do the job). 00060 00061 Windows does not come by default with any SVN or CVS clients 00062 so you might want to install the Cygwin linux like environment for convenience. 00063 In this case make sure that the .Net paths are still correctly set. 00064 00065 00066 \subsection rpm RPM Installation and building instructions 00067 PyDIM comes already built as and RPM package with a dependency on the DIM RPM. 00068 In this manner the PyDIM libraries can be deployed more easily on all the machines 00069 inside the Online system using rpm, yum or quattor. 00070 These RPMs (including the DIM ones) can be found on AFS under: 00071 00072 <pre>/afs/cern.ch/lhcb/project/web/online/online-rpm-repo/</pre> 00073 00074 They are also replicated to the pit on the yum server 00075 (<b>TODO</b>: Add the actual machine name and path to them). 00076 00077 The RPMs are for both i386 and x86_64 architectures and are compiled gcc 3.4.X 00078 against Python 2.3 (these are the standard Python, gcc versions for SLC 4.6). 00079 00080 There are two dependencies for building the package: python-devel and dim-devel. 00081 Those packages contains the header files for Python and DIM respectively. 00082 00083 RPMs packages are build using the distutils module, this can be done by running 00084 the setup script with command <code>bdist_rpm</code>: 00085 00086 <pre> 00087 $ python setup.py bdist_rpm 00088 </pre> 00089 00090 The <code>bdist_rpm</code> command will create binary and source packages in 00091 the <code>dist</code> directory. The command provides options for the process, 00092 such as creating only the <code>.spec</code> file: 00093 00094 <pre> 00095 $ python setup.py bdist_rpm --spec-only 00096 </pre> 00097 00098 Or building only the RPM source package: 00099 00100 <pre> 00101 $ python setup.py bdist_rpm --source-only 00102 </pre> 00103 00104 The full list of the options can be displayed with the help command: 00105 00106 <pre> 00107 $ python setup.py --help bdist_rpm 00108 </pre> 00109 00110 \subsubsection disutils-slc5 Building RPMs packages in SLC5 00111 00112 Builing RPM packages with distutils in SLC5 can be tricky. Check this 00113 <a href="https://lbtwiki.cern.ch/bin/view/Online/RpmPythonDistutils">guide</a> 00114 with the description of the problem and a workaround. 00115 00116 \subsection msi MSI Installation and building instructions 00117 PyDIM can be also be build as an MSI package or as a Windows installer. 00118 In the most simple scenario a simple "make msi" will do the job. This relies on the following assumption that 00119 the .Net environment is set up properly as described in the building instructions. 00120 The *.msi and *.exe packages will be found in the PyDIM/dist directory. 00121 00122 \subsection make Summary of make targets 00123 - build -> only builds the package 00124 00125 - install -> builds and install the package in /usr/lib/pythonXX (requires root). It does not include the documentation. 00126 00127 - doc -> builds the documentation using doxygen. You will require a version >= 1.5.XX. The typical SLC installation has doxygen 1.3.XX and this has poor support for parsing Python sources. You can use an older version but the documentation will be malformed. 00128 00129 - rpm -> creates a RPM. See also the pydim.spec file. Might require root privileges. 00130 00131 - msi -> creates a MSI installer package in the PyDIM/dist directory. 00132 00133 00134 \section usage Usage 00135 -# In case you have PyDIM installed as a RPM (recommended) then just set up the DIM_DNS_NODE and say "import pydim" from Python. 00136 -# In case you have your own local installation you have to set up your environment properly to point to the appropriate libraries and scripts. 00137 00138 The setup/setup.sh is provided for bash shells as an environment setup template. 00139 It tries to set up the DIM_DNS_NODE, adds the PyDIM/python directory to 00140 your PYTHONPATH, LD_LIBRARY_PATH. 00141 00142 You can execute some tests/examples from the 'tests' directory. 00143 Those scripts can be used as examples of the package's functionality. 00144 00145 \section examples Examples 00146 00147 The following example shows to run a server with two simple services. 00148 00149 00150 \code 00151 import sys, time 00152 import pydim 00153 00154 def service_callback(tag): 00155 """ 00156 Service callbacks are functions (in general, Python callable objects) 00157 that take one argument: the DIM tag used when the service was added, 00158 and returns a tuple with the values that corresponds to the service 00159 parameters definition in DIM. 00160 """ 00161 # Calculate the value of the server 00162 # ... 00163 val1 = 3.11 00164 val2 = 42 00165 return (val1, val2) 00166 00167 def callback2(tag): 00168 # Calculate the value 00169 # ... 00170 # Remember, the callback function must return a tuple 00171 return ( "hello world", ) 00172 00173 # The function dis_add_service is used to register the service in DIM 00174 svc = pydim.dis_add_service('test service 1', "F:1;I:1;", service_callback, 1) 00175 00176 # Register another service 00177 svc2 = pydim.dis_add_service('another service', "C", callback2, 2) 00178 00179 # The return value is the service identifier. It can be used to check 00180 # if the service was registered correctly. 00181 if not svc2: 00182 sys.stderr.write("An error occurred while registering the service\n") 00183 sys.exit(1) 00184 00185 # A service must be updated before using it. 00186 pydim.dis_update_service(svc) 00187 pydim.dis_update_service(svc2) 00188 00189 # Start the DIM server 00190 pydim.dis_start_serving('server-name') 00191 00192 while True: 00193 # Update the service periodically 00194 pydim.dis_update_service(svc) 00195 time.sleep(5) 00196 00197 \endcode 00198 00199 \section contact Contact 00200 00201 This module was originally developed by 00202 <a href="http://consult.cern.ch/xwho/people/652087">Radu Stoica</a>. 00203 00204 Now it's maintained by 00205 <a href="http://consult.cern.ch/xwho/people/417932">Niko Neufeld</a> and 00206 <a href="http://consult.cern.ch/xwho/people/681596">Juan Manuel Caicedo</a>. 00207 00208 Feel free to send your questions and bugfixes. 00209 00210 \defgroup examples Examples of using PyDIM 00211 Various examples using the C and C++ DIM APIs. 00212 00213 You can execute some tests/examples from the 'tests' directory. 00214 These scripts can be used as examples of the module's functionality. 00215 */