dbClientAPI
index
/home/pjx/BIOXHIT/Bioxhit_db/dbccp4i/ClientAPI/dbClientAPI.py

#     Copyright (C) 2006
#
#     This code is distributed under the terms and conditions of the
#     CCP4 Program Suite Licence Agreement as a CCP4 Library.
#     A copy of the CCP4 licence can be obtained by writing to the
#     CCP4 Secretary, Daresbury Laboratory, Warrington WA4 4AD, UK.
#
#====================================================================
# CCP4 Interface - dbClientAPI.py
#
# Classes and methods for interacting with the database handler

# Wanjuan Yang and Peter Briggs
#
#====================================================================

 
Modules
       
ccp4i
dbsocket
exceptions
os
re
socket
sys
time

 
Classes
       
File
HandlerConnection
Job
JobFile
JobLink
Project
db
exceptions.Exception
DbError

 
class DbError(exceptions.Exception)
    Exception raised when db request is not successful
 
  Methods defined here:
__init__(self, message)
__str__(self)

Methods inherited from exceptions.Exception:
__getitem__(...)

 
class File
    create a file object. have methods set & get file attributes
 
  Methods defined here:
__init__(self, db)
getFormat(self, FileId)
getLastModified(self, FileId)
getName(self, FileId)
getNote(self, FileId)
getPath(self, FileId)
newFile(self)
setFormat(self, FileId, Format)
setLastModified(self, FileId, LastModified)
setName(self, FileId, Name)
setNote(self, FileId, Note)
setPath(self, FileId, Path)

 
class HandlerConnection
    create a connection to the handler, provide commands to talk to handler, access database.def file & directories.def.
 
  Methods defined here:
AddDataDirRef(self, def_dir, path)
Summary: Add default directory reference
Arguments:
def_dir: default directory name
path: the path of the default directory
AddInputFile(self, project, jobid, filen, projdir='')
Summary: Add a file to the list of input files for a job.
Arguments:
projec: project name
jobid: job id
filen: input file name
projdir: project directory
AddOutputFile(self, project, jobid, filen, projdir='')
Summary: Add a file to the list of input files for a job.
Arguments:
project: project name
jobid: job id
filen: output file name
projdir: project directory
AddSubJob(self, project, jobid, title, taskname)
Summary: Add sub jobs to a job
Arguments:
project: project name
jobid: job id
BroadcastReporter(self)
Summary: Checks for broadcast messages and print them to stdout
CheckServerStatus(self)
Summary: Return handler status
CloseProject(self, project)
Summary: Close a project
Argument:
project: project name
CreateProject(self, project, dir)
Summary: Create a new project
Arguments:
project: project name
dir: the path of the project
DbInfo(self)
Summary: Return information about the handler version
DbRegister(self, user_agent, broadcast=True)
Summary: Register with handler
Arguments: 
user_agent: application that talks to the db handler. e.g: ccp4i
broadcast:  flag for whether application want to receive broadcast
message from db handler
DbSupported(self, db)
Summary: Check if handler support db type
Argument:
db: the type of db. e.g. def, sqlite
DeleteDataDirRef(self, def_dir)
Summary: Delete default directory reference
Argument:
def_dir: default directory name
DeleteJob(self, project, job_id)
Summary: Delete a job in a project
Arguments:
project: project name
job_id: job id
DeleteProject(self, project)
Summary: Delete a project reference
Argument:
project: project name
GetAllChildren(self, project, jobid)
Summary: Return all the descendents of a job
Arguments:
project: project name
jobid: job id
GetAllFileLinks(self, project)
Summary: Return all the links between jobs in a project
Argument:
project: project name
GetAllParents(self, project, jobid)
Summary: Return all the antecedents of a job
Arguments:
project: project name
jobid: job id
GetAllParentsChildren(self, project, jobid)
Summary: Return all the antecedents of a job
Arguments:
project: project name
jobid: job id
GetAllSQLdbData(self, project, itemlist)
Summary: Return all values of given items from sql db
Arguments:
project: project name
itemlist: a list of items. e.g. ["JobNumber","JobQuality"]
GetChildren(self, project, jobid)
Summary: Return the immediate children of the job
Arguments:
project: project name
jobid: job id
GetData(self, project, job_id, *items)
Summary: Return value for job data items in a project
Arguments:
project: project name
job_id: job id
*items: one or more items, e.g. "TITLE" "TASKNAME"
GetDataDir(self, def_dir)
Summary: Return the directory corresponding to a def dir name
Argument:
def_dir: the default directory name
GetDescription(self, project, job_list, db_display, db_display_format)
Summary: Return the description of a job in a project
Arguments:
project: project name
job_list: a list of job ids
db_display: a list of the database parameters to be displayed
db_display_format: a list of the field widths (as integers) to use for displaying the items in the db_display list
GetFileLinks(self, project, joblist)
Summary: Return the links for specified jobs
Arguments:
project: project name
joblist: a list of job ids
GetFileList(self, project, jobid, type)
Summary: Return a list of files associated with a job.
Arguments:
project: project name
jobid: job id
type:  the type of file. e.g. 'INPUT','OUTPUT'
GetJobQuality(self, project, jobid)
Summary: Get Job quality data
Arguments:
project: project name
jobid: job id
GetListofRecords(self, project, joblist, itemlist)
Summary: Return a list of records for a project
Arguments:
project: project name
joblist: a list of job ids
itemlist: a list of items, e.g. ["TASKNAME","TITLE","STATUS"]
GetNJOB(self, project)
Summary: Return the highest job number in the project
Argument:
project: project name
GetNProjects(self)
Summary: Return the number of projects
GetNextJobList(self, project, jobid)
Summary: Return all the jobs that link to the job
Arguments:
project: project name
jobid: job id
GetNotebook(self, project, jobid)
Summary: Return the notebook
Arguments:
project: project name
jobid: job id
GetParents(self, project, jobid)
Summary: Return the immediate parents of the job
Arguments:
project: project name
jobid: job id
GetProjectDir(self, project)
Summary: Return the directory corresponding to a project name
Argument:
project: project name
GetSQLdbData(self, project, jobid, *items)
Summary: Return value for a given job given items from sql db
Arguments:
project: project name
jobid: job id
*itmes: one or more items. e.g. JobNumber, JobQuality
GetTableData(self, project, table, tableid, attribute)
Summary: Get a value of an attribute in a table 
Argument:
project: project name
table: table name
tableid: the primary key for the record
attribute: the attribute of the value belong to
GetTablePrimaryKey(self, project, table, condition)
Summary: Get a value of an attribute in a table 
Argument:
project: project name
table: table name
condition: the condition of getting the key, it is where clause of SQL language
HandlerDisconnect(self)
Summary: Disconnect from handler
HasSQLdb(self, project)
Summary: Check if the project has SQL db
Argument:
project: project name
HasSubJobs(self, project, jobid)
Summary: Check if the job has sub jobs
Arguments:
project: project name
jobid: job id
ImportProject(self, alias, path)
Summary: Import a project
Arguments:
alias: project name
path: path of the project
ItemExists(self, project, job_id, item)
Summary: Check if an item exist for a project
Arguments:
project: project name
job_id: job id
item: item name. e.g. TITLE, TASKNAME
ListDataDirs(self)
Summary: Return a list of the user's default directories
ListInputFiles(self, project, jobid)
Summary: Return a list of input files for a given job.
Arguments:
project: project name
jobid: job id
ListJobs(self, project, jobid='')
Summary: List all of the jobs in a project
Argument:
project: project name
jobid: job id. This is only needed when list subjobs.
ListJobswithsubjobs(self, project)
Summary: List jobs that have subjobs
Arguments:
project: project name
ListOutputFiles(self, project, jobid)
Summary: Return a list of output files for a given job.
Arguments:
project: project name
jobid: job id
ListProjects(self)
Summary: List all the user's projects
NewJob(self, project)
Summary: Create a job in a project
Argument:
project: project name
NewTableRecord(self, project, table, *args)
Summary: Create a new record in a table
Argument:
project: project name
table: table name
*args: a list of item-value pairs.
OpenProject(self, project, grablock=False, readonly=False)
Summary: Open an existing project
Arguments:
project: project name
grablock: when there is a lock on database, set grablock True
can force to open the database.
readonly: when there is a lock on database, set readonly True
can read the data, but not allow to update the data.
ProjectReadable(self, project)
Summary: Check if the project is writeable
Argument:
project: project name
ProjectWriteable(self, project)
Summary: Check if the project is writeable
Arugment:
project: project
ReacquireProject(self, project)
Summary: Re grab the lock
Argument:
project: project name
SelectJobs(self, project, item, pattern)
Summary: Retrieve a list of jobs based on some selection criterion
Arguments:
project: project name
item: item name being searched on
pattern: Regular expression pattern to search on
SelectSubJobs(self, project, jobid, item, pattern)
Summary: Select sub jobs from a job
Arguments:
project: project name
jobid: job id
item: item name being searched on
pattern: Regular expression pattern to search on
SetData(self, project, job_id, *args)
Summary: Set item value pairs for the same job in a project
Arguments:
project: project name
job_id: job id
*args: a list of item-value pairs. e.g. TASKNAME mlphare TITLE Refining Se sites
SetJobQuality(self, project, jobid, quality)
Summary: Set Job quality data
Arguments:
project: project name
jobid: job id
quality: quality of the job solution. Could be '1','0' or '-1'.
'1' means 'good', '0' means 'marginal', '-1' means 'bad'
SetLogfile(self, project, jobid, logfile)
Summary: Set the filename for the logfile for a job.
Arguments:
project: project name
jobid: job id
logfile: logfile name
SetStatus(self, project, jobid, status)
Summary: Set status for a job
Arguments:
project: project name
jobid: job id
status: status for the job.
SetTableData(self, project, table, tableid, attribute, value)
Summary: Set a value of an attribute in a table 
Argument:
project: project name
table: table name
tableid: the primary key for the record
attribute: the attribute of the value belong to
value: the value being set
SetTaskname(self, project, jobid, taskname)
Summary: Set taskname for a job
Arguments:
project: project name
jobid: job id
taskname: taskname for the job. This taskname cannot contain space.
SetTitle(self, project, jobid, title)
Summary: Set title for a job
Arguments:
project: project name
jobid: job id
title: title for the job.
ShutDown(self)
Summary: Shut down the handler
Updatetime(self, project, jobid)
Summary: Update the time of a job
Arguments:
project: project name
jobid: job id
__init__(self, user_agent, broadcastflag=True)

 
class Job
    create a job object. have methods of set & get job attributes
 
  Methods defined here:
__init__(self, db)
getApplication(self, JobId)
Get attribute application
getControlFile(self, JobId)
Get control file
getData(self, jobid, item)
Get job attribute
getLastModified(self, jobid)
Get lastmodified
getLogFile(self, jobid)
Get logfile
getNotebookFile(self, JobId)
Get notebook
getStatus(self, jobid)
Get attribute status
getTaskname(self, jobid)
Get taskname
getTitle(self, jobid)
Get title
newJob(self, projectname)
Create a new job
setApplication(self, JobId, Application)
Set attribute application
setControlFile(self, JobId, ControlFile)
set controlfile
setData(self, jobid, item, value)
Set job attribute
setLastModified(self, jobid, time)
Set lastmodified
setLogFile(self, jobid, logfile)
Set logfile
setNotebookFile(self, JobId, NotebookFile)
Set notebook
setStatus(self, jobid, status)
Set attribute status
setTaskname(self, jobid, taskname)
Set taskname
setTitle(self, jobid, title)
Set title

 
class JobFile
    create a JobFile object, have methods set & get JobFile attributes
 
  Methods defined here:
__init__(self, db)
getFileId(self, JobFileId)
getType(self, JobFileId)
newJobFile(self)
setFileId(self, JobFileId, FileId)
setType(self, JobFileId, Type)

 
class JobLink
    create a JobLink object, have methods set & get JobLink attributes
 
  Methods defined here:
__init__(self, db)
getNextJobId(self, JobLinkId)
getNote(self, JobLinkId)
getType(self, JobLinkId)
newJobLink(self)
setNextJobId(self, JobLinkId, NextJobId)
setNote(self, JobLinkId, Note)
setType(self, JobLinkId, Type)

 
class Project
    create a project object, have methods to set and get project attributes
 
  Methods defined here:
__init__(self, db)
getOwner(self, pid)
Get attribute owner
getPath(self, pid)
Get attribute path
getProjectId(self, projectname)
Get project id
newProject(self, projectname)
Create a project
setOwner(self, pid, owner)
Set attribute owner
setPath(self, pid, path)
Set attribute path

 
class db
    create a SQLite db object
 
  Methods defined here:
CloseDB(self)
Close a database
GetData(self, table, id, attribute)
Return the attribute value in a table
GetJobList(self, projectname)
Return joblist in a project
GetProjectList(self)
Return a project list
GetRowofTable(self, table, rid)
Return a record in a table
NewDB(self, dbname, dir)
Create a database
NewRecord(self, table, *args)
New a record in a given table 
Arguments:
table: table name
*args: a list of item-value pairs.
OpenDB(self, dbname, dir)
Open a database
SetData(self, table, id, attribute, value)
Set attribute value in a table's record
__init__(self, con)
sendrequest(self, command, argu_list)
send request to handler and return response

 
Functions
       
ConvertTime(secs)
Given a time expressed in seconds, convert into formated time
ConvertTimeCCP4i(secs)
Given a time expressed in seconds, convert into CCP4i format
DbStartHandler()
Start a dbccp4i handler process in background.
GetHandlerPort(nowait=False)
Acquire the port number for a handler process.
 
Attempts to read the port number from the handler lock file in the
user's .CCP4 area, and returns the port number if successful (otherwise
returns -1). Set nowait=True to prevent the function from making
multiple attempts to get the port number before giving up.
Report(message)
write error message to a logfile
ResultParser1(result)
Parse the result and return 1 if successful, 0 if failed  and write to logfile
ResultParser2(result)
Parse the result and return result value if successful, -1 if failed and write to logfile