Back: Spire's main menus | Home: Table of Contents |
If your lab already has a database of reconstruction projects, Spire can communicate with it. This generally occurs at the beginning and end of a project. At the start of a project Spire can download some project parameters (e.g., electron voltage, pixel resolution, etc) from the database. At the end of a project, final volumes, resolution information, etc. can be uploaded into the database.
Since Spire does not know which database you are using, nor anything about the internal
organization of that database, you will have to supply that information. This usually means
- installing an additional Python database library,
- writing some Python code that enables Spire to access your database (code for MySQL is included
in Spire package).
Setting up Spire to connect to an external database:
spiderLocalDB.py
spiderLocalMysql.py
. This file should be copied to spiderLocalDB.py
.spiderLocalDB.py
as a template (see an example).
This module must contain a class spiderDatabase
, which inherits from
spiderClasses.SpiderDatabase
. This class object must have the following
attributes and methods:
Attributes | |
---|---|
databaseName | a database name to present to the user, e.g., "the Project Database" |
id | the project ID number is used to specify a particular project in the database. |
projectquery | another SQL query to fetch project information |
Methods | |
__init__() | sets the required attributes. |
isExtDatabaseAlive() | returns 1 or 0 depending on whether it can successfully connect. |
sendQuery(query) | returns results of SQL statement |
getProjectInfo() | using projectquery , fetches
project information, and inserts it into GB.P, the internal class object of the current Spire project. |
upload(upload_object) | given an uploadable object, establish a connection and insert data into appropriate places in the external database |
spiderLocalDB.py
in $PYTHONPATH/site-packages/Spire
Example: setting up Spire to connect to a MySQL database
The Spire distribution contains example code for a tiny project database in MySQL.You must first:
MySQLdb
, installedtestmysql.py
, which creates
a table in the specified database and inserts some test data in it. Usage:
testmysql.py -u user -p password -d database -t table
All arguments are optional. If you type just
testmysql.py
it will use the following default values:
database = "test_spire"
table = "projects"
user = "" i.e., anonymous login must be enabled for mysql
password = ""
testmysql.py
will create the table projects
in the
database test_spire
and put some values in the table.
CHECK THE FIELD NAMES Data loaded into table 'projects': +------------+-----------+------+--------------+----------+ | project_id | pixelsize | kev | project_file | data_ext | +------------+-----------+------+--------------+----------+ | 149 | 4.78 | 100 | proj149 | xyz | +------------+-----------+------+--------------+----------+"database", "user", and "password" must be set up for your MySQL database.
loadtable.py database user password table
E.g., for database 'test' and user 'brian', whose password is 'heinz57'
newtable.py test brian heinz57 projects
loadtable.py test brian heinz57 projects
copy this file, spiderLocalMysql.py
, to spiderLocalDB.py
,
and run Spire. Start a new project, enter project number 149. It should fetch data
from the MySQL database.