Changeset 5410


Ignore:
Timestamp:
May 4, 2015 5:12:06 AM (8 years ago)
Author:
mmh
Message:

add new python API, PyXml?

Location:
branches/uq/lang/python
Files:
5 added
3 edited

Legend:

Unmodified
Added
Removed
  • branches/uq/lang/python/README

    r3177 r5410  
    3838 Python scripts.
    3939
    40  Rappture applications load their data from a library object.  You can
    41  load a library as follows:
     40 Rappture applications load their data from a an XML driver file.
     41 In the tool.xml file, you should have something like
     42
     43 <command> @tool/path/to/executable @driver </command>
     44
     45The "@driver" pattern is replaced by the driver xml file generated by
     46Rappture.  This driver file will contain the values to use for the
     47parameters in your application.  See
     48https://nanohub.org/infrastructure/rappture/wiki/rappture_xml_elements
     49for more information.
     50
     51The first thing your application should do is load the driver file.
    4252
    4353   import Rappture
    44    lib = Rappture.library('example.xml')
    45    print lib.xml()
    46  
     54   rx = Rappture.PyXml('example.xml')
     55
     56You can see the xml contents by doing
     57   print rx.xml()
     58
    4759 The "import" statement loads the Rappture toolkit into your Python
    4860 application.  The next line creates a library object representing
     
    5466
    5567   import Rappture
    56    lib = Rappture.library('example.xml')
     68   lib = Rappture.PyXml('example.xml')
    5769   tval = lib.get('group(ambient).number(temp).current')
     70or alternatively
     71   tval = lib['group(ambient).number(temp).current'].value
    5872
    5973 The get() method follows a path through the XML.  In this example,
     
    6882
    6983   tval += 10
    70    lib.put('group(ambient).number(temp).current',str(tval))
     84   lib.put('group(ambient).number(temp).current', tval)
     85or
     86   lib[group(ambient).number(temp).current'] = tval
    7187
    7288 This changes the text within the <current>...</current> tag,
    73  replacing it with the new value.  Note that the value must be a
    74  string, so we use str(tval), rather than tval itself, when inserting
    75  a value.
     89 replacing it with the new value, converted to a string if necessary.
    7690
    7791 You can also append to an existing value.  For example,
     
    7993   lib.put('group(ambient).number(temp).current', 'more text', append=1)
    8094
    81  This adds the string 'more text' after the value (tval) within the
    82  <current>...</current> tag.
     95 This adds the string 'more text' after the value (tval) within the
     96 <current>...</current> tag.  Use of append in a loop is not
     97 recommended because it can be very slow.  It is faster to collect
     98 data in python and put it all at once.
    8399
    84  Suppose we wanted to add another number to the "ambient" group.
    85  We could do that by requesting "number#".  The # sign indicates
    86  that you'd like to create a new number element (number1, number2,
    87  etc.).  For example, we could add a number for a damping factor:
    88 
    89    lib.put('group(ambient).number#(damping).current','0.25')
    90 
    91  This creates a new element <number id="damping"> within
    92  <group id="ambient">, positioned just after the existing
    93  <number id="temp">.
  • branches/uq/lang/python/Rappture/__init__.py

    r790 r5410  
    11# Rappture package
    22from library import library
     3from pyxml import PyXml
    34from interface import interface
    45from number import number
  • branches/uq/lang/python/setup.py.in

    r1584 r5410  
    4141                     'Rappture.signalHandler',
    4242                     'Rappture.tools',
    43                      'Rappture.result'],
     43                     'Rappture.result',
     44                     'Rappture.pyxml'],
    4445        ext_modules=[ encode_module,
    4546                      library_module,
Note: See TracChangeset for help on using the changeset viewer.