Design/Process/Programming

Writing Drugle scripts

Runtime location of Drugle scripts

The root directory for runtime location of Drugle scripts is /var/lib/drugle/scripts.

General scripts should be installed in that directory. Scripts that are specifically written for a given source should be placed in a subdirectory of the above named after the given source, eg. "/var/lib/drugle/scripts/emea".

The Drugle Environment

The first thing you have to do when writing a Drugle script is to determine which environment you intend to work on.

The Drugle environment is completely defined by its base prefix, i.e. the path of its base directory. The rest of the environment is deduced from this path.

E.g.: The xapian database is in <prefix>/index_db, the sources directory is in <prefix>/sources and so on.

Here is the complete list of elements in the Drugle environment:

LocationPathDescription
current prefix<prefix>The base directory of the current Drugle environment
data<prefix>/dataDirectory containing basic data used in Drugle. E.g.: Atc codes, terms, etc
sources<prefix>/sourcesBase directory of downloaded data sources.
a source<prefix>/sources/<source>Base directory of a particular data source, called <source>. E.g: emea, lmc, mhra, etc
a document type<prefix>/sources/<source>/<dtype>Base directory of a document type (<dtype>) in a source. E.g.: spc, pat, ...
index<prefix>/sources/<source>/<dtype>/indexBase directory of all index files in a document type.
index of a language<prefix>/sources/<source>/<dtype>/index/<lan>Base directory of all index files in a document type and a language (<lan>: sv, en,es, ...).
xapian database<prefix>/xapian_dbIndexing database
intialization<prefix>/initInitialization scripts
scripts<prefix>/scriptsDownloading, handling and indexing scripts
translation<prefix>/translationsTranslation data
profiles<prefix>/profilesSearch profiles

The ENVIRONMENT class

The class ENVIRONMENT is used to initialize the environment with a prefix.

import drugle
env = drugle.ENVIRONMENT ("/my/own/drugle")

... and the environment is based in the directory "/my/own/drugle"

import drugle
env = drugle.ENVIRONMENT ()

... and the environment is based in the default value "/var/lib/drugle"

The Index file interface

See specification of index files

The INDEX_DOCS class

The INDEX_DOCS class represents a collection of index files on a specific source, of a specific type and in a specific language.

import drugle
import drugle.index as di
env = drugle.ENVIRONMENT () # default location: /var/lib/drugle
idocs = di.INDEX_DOCS('emea', 'spc', 'en', env)

idocs represents all the english index files containing information about Emea's Specification documents (SPCs)

You can now create index files:

if not idocs.has ('not-yet-existent-id'):
    newdoc = idocs.new_index_doc ('not-yet-existent-id')
    newdoc.store ()

Or retreive existent index files:

if idocs.has ('existent-id'):
    idoc = idocs.index_doc ('existent-id')

You can generate xapian indexes for all the index files in the collection.

idocs.generate_index ()

Generates xapian indexing, replacing old indexing information in the database.

The INDEX_DOC class hierarchy

INDEX_DOC -- Base class for index files
  INDEX_SPC -- Index files of type "spc" (Specification of Product Characteristics)
  INDEX_PAT -- Index files of type "pat" (kloka listan)