Changes between Version 1 and Version 2 of PythonFramework


Ignore:
Timestamp:
Apr 25, 2007, 2:54:19 PM (17 years ago)
Author:
Nicolas
Comment:

Required manual changes to automatic conversion.

Legend:

Unmodified
Added
Removed
Modified
  • PythonFramework

    v1 v2  
    11= Python scripting framework =
    22
    3       See the section on Python in the [http://boinc.berkeley.edu/trac/wiki/SoftwarePrereqsUnix Software Prerequisites].
     3See the section on Python in the [http://boinc.berkeley.edu/trac/wiki/SoftwarePrereqsUnix Software Prerequisites].
     4
    45== Structure ==
    5   The directory `boinc/py/Boinc` contains the `Boinc` module. This means if you have `boinc/py/` in your python path you can write for example:  `from Boinc.setup_project import *`   To ensure `boinc/py/` is in your python path:  `import boinc_path_config`  This is a special module that `configure` places in relevant directories which then modifies `sys.path` appropriately.
     6
     7The directory `boinc/py/Boinc` contains the `Boinc` module. This means if you have `boinc/py/` in your python path you can write for example:
     8{{{
     9from Boinc.setup_project import *
     10}}}
     11To ensure `boinc/py/` is in your python path:
     12{{{
     13import boinc_path_config
     14}}}
     15This is a special module that `configure` places in relevant directories which then modifies `sys.path` appropriately.
     16
    617== Project-specific settings ==
    7  The module `boinc_project_path` is imported to get the paths for `config.xml` and `run_state.xml`. The default paths for these are the parent directory of the invocation script. You can override these defaults
    8  1. modify this file directly (if you have only one project on your server     or have separate copies for each)
     18
     19The module `boinc_project_path` is imported to get the paths for `config.xml` and `run_state.xml`. The default paths for these are the parent directory of the invocation script. You can override these defaults
     20 1. modify this file directly (if you have only one project on your server or have separate copies for each)
    921 1. create a new boinc_project_path.py and place it earlier in PYTHONPATH        than the default one
    1022 1. define environment variables
    1123
    12   Example `boinc_project_path.py`
     24Example `boinc_project_path.py`
    1325{{{
    1426  config_xml_filename = '/etc/boinc/yetiathome/config.xml'
    1527  run_state_xml_filename = '/var/lib/boinc/yetiathome/run_state.xml'
    1628}}}
    17   See the source of file `boinc/py/Boinc/boinc_project_path.py` for details.
     29See the source of file `boinc/py/Boinc/boinc_project_path.py` for details.
     30
    1831== Directories containing python scripts ==
    1932
    20 
    21 
    22 
     33||boinc/py/Boinc/*.py||Main BOINC python modules||
     34||[StartTool boinc/sched/start]||BOINC start / Super Cron program||
     35||[XaddTool boinc/tools/xadd]||Adds objects to the database||
     36||[MakeProject boinc/tools/make_project]||Creates a project||
     37||[UpdateVersions boinc/tools/update_versions]||Adds all relevant core client and application executables to download directory and database||
     38||boinc/test/test*.py[[BR]]cgiserver.py||Test scripts: see the [http://boinc.berkeley.edu/test.php testing framework].||
    2339
    2440== Python modules in '''boinc/py/Boinc/''' ==
    2541
    26 
    27 
    28 
     42||`boinc_path_config.py.in`||`Configure` puts `boinc_path_config.py` in all directories that need it; see above||
     43||`boinc_project_path.py`||sets where `config.xml` et al can be found; see above.||
     44||`configxml.py`||reads and writes `config.xml` and `run_state.xml` - see its pydoc for more information||
     45||`boinc_db.py`||auto-generated file that contains database constant definitions, e.g. `RESULT_OUTCOME_SUCCESS = 1`||
     46||`setup_project.py`||internal module for creating a project. See [MakeProject make_project] and test scripts.||
     47||`database.py`||defines database backend functions and database operations; see below.||
     48||`db_mid.py`||'middle-end': optional mix-in to ease debugging by allowing printing of database objects directly||
     49||`util.py`||miscellaneous functions||
     50||`version.py.in`||version and platform-specific definitions snarfed by `configure`||
    2951
    3052== Python database access ==
    31  `Database.py` defines database backend library and database table and object relationships to allow easy data manipulation. All [DataBase database tables] have a corresponding class and its rows have classes, where each column is a member of that class. Ids are automatically translated to and from objects. To begin, import the `database` module:
     53`Database.py` defines database backend library and database table and object relationships to allow easy data manipulation.
    3254
     55All [DataBase database tables] have a corresponding class and its rows have classes, where each column is a member of that class. Ids are automatically translated to and from objects. To begin, import the `database` module:
    3356
    3457{{{
    35   from Boinc import database
     58from Boinc import database
    3659}}}
    37   Connect to the database:
     60Connect to the database:
    3861{{{
    39   database.connect_default_config()
     62database.connect_default_config()
    4063}}}
    41   Table classes can be indexed using the [ ] operator to retrieve an object by id; e.g.
     64Table classes can be indexed using the [ ] operator to retrieve an object by id; e.g.
    4265{{{
    43   # executes 'select * from project where id=1'.
    44   # exception is raised if project is not found
    45   project_with_id_1 = database.Projects[1]
     66# executes 'select * from project where id=1'.
     67# exception is raised if project is not found
     68project_with_id_1 = database.Projects[1]
    4669}}}
    47   Table classes have a `find` function that builds and executes a MySQL query based on its arguments:
     70Table classes have a `find` function that builds and executes a MySQL query based on its arguments:
    4871{{{
    49   # this could return any number (0, 1, 2, ...) of platforms
    50   # executes "select * from platform where user_friendly_name='commodore 64'"
    51   list_of_platforms_called_c64 = database.Platforms.find(
    52       user_friendly_name = 'Commodore 64')
     72# this could return any number (0, 1, 2, ...) of platforms
     73# executes "select * from platform where user_friendly_name='commodore 64'"
     74list_of_platforms_called_c64 = database.Platforms.find(
     75    user_friendly_name = 'Commodore 64')
    5376}}}
    54   Find can take any number of arguments; they are ANDed. For more advanced usage such as custom SQL queries (anything is possible :) see the pydoc.
     77Find can take any number of arguments; they are ANDed. For more advanced usage such as custom SQL queries (anything is possible) see the pydoc.
    5578{{{
    56   all_apps = database.Apps.find()
    57   finished_yeti_wus = database.Workunits.find(
    58       app = database.Apps.find(name='YETI@home')[0],
    59       assimilate_state = ASSIMILATE_DONE)
     79all_apps = database.Apps.find()
     80finished_yeti_wus = database.Workunits.find(
     81    app = database.Apps.find(name='YETI@home')[0],
     82    assimilate_state = ASSIMILATE_DONE)
    6083}}}
    61   Objects (table rows) have their column data as members so you can access and modify them directly.
     84Objects (table rows) have their column data as members so you can access and modify them directly.
    6285{{{
    63   user_quarl = database.users.find(email_addr='quarl@quarl.org')[0]
    64   print 'name =', user_quarl.name
    65   user_quarl.postal_code = 97404
     86user_quarl = database.users.find(email_addr='quarl@quarl.org')[0]
     87print 'name =', user_quarl.name
     88user_quarl.postal_code = 97404
    6689}}}
    67   To create a new database object, create a Python object and give all values as parameters to the initializer:
     90To create a new database object, create a Python object and give all values as parameters to the initializer:
    6891{{{
    69   new_app = database.App(name='SPAGHETTI@home',
    70                          min_version=1,
    71                          create_time=time.time())
     92new_app = database.App(name='SPAGHETTI@home',
     93                       min_version=1,
     94                       create_time=time.time())
    7295}}}
    73   To commit any changes (including a new object), call `commit()` (the tool `boinc/tools/add.py` is a command-line interface to this):
     96To commit any changes (including a new object), call `commit()` (the tool `boinc/tools/add.py` is a command-line interface to this):
    7497{{{
    75   user_quarl.commit()  # executes an UPDATE
    76   new_app.commit()     # executes an INSERT
     98user_quarl.commit()  # executes an UPDATE
     99new_app.commit()     # executes an INSERT
    77100}}}
    78   To remove an object, call `remove()`:
     101To remove an object, call `remove()`:
    79102{{{
    80   team_eric_test = database.Teams(name="Eric's Test Team")[0]
    81   team_eric_test.remove()
    82   #                        OR
    83   for team in database.Teams(name="Eric's Test Team"):
    84       team.remove()
    85   #                        OR
    86   map(database.Team.remove,database.Teams(name="Eric's Test Team"))
     103team_eric_test = database.Teams(name="Eric's Test Team")[0]
     104team_eric_test.remove()
     105#                        OR
     106for team in database.Teams(name="Eric's Test Team"):
     107    team.remove()
     108#                        OR
     109map(database.Team.remove,database.Teams(name="Eric's Test Team"))
    87110}}}
    88   To access objects related by id, access the field name without "id" suffix: (the `result` table has columns '`workunitid`' and '`hostid`'; the `host` table has column `userid`)
     111To access objects related by id, access the field name without "id" suffix: (the `result` table has columns '`workunitid`' and '`hostid`'; the `host` table has column `userid`)
    89112{{{
    90   wu_1234 = database.Workunits.find(name='1234.wu')[0]
    91   results_of_wu_1234 = database.Results.find(workunit=wu_1234)
    92   for result in results_of_wu_1234:
    93       os.system("echo 'you are crunching %s' | mail '%s'" %(
    94                  result.name, result.host.user.email_addr))
     113wu_1234 = database.Workunits.find(name='1234.wu')[0]
     114results_of_wu_1234 = database.Results.find(workunit=wu_1234)
     115for result in results_of_wu_1234:
     116    os.system("echo 'you are crunching %s' | mail '%s'" %(
     117               result.name, result.host.user.email_addr))
    95118}}}
     119
     120||'''Table'''||'''Python table object'''||'''Python row object class'''||
     121||project||Projects||Project||
     122||platform||Platforms||Platform||
     123||core_version||!CoreVersions||!CoreVersion||
     124||app||Apps||App||
     125||app_version||!AppVersions||!AppVersion||
     126||user||Users||User||
     127||team||Teams||Team||
     128||host||Hosts||Host||
     129||workunit||Workunits||Workunit||
     130||result||Results||Result||
     131||workseq||Workseqs||Workseq||