root/trunk/doc/utilities.srblib.txt

Revision 312, 3.5 KB (checked in by apdavison, 4 years ago)

Bug-fixes to srblib module. Unit tests and doctests now pass.

  • Property svn:eol-style set to native
Line 
1===============================
2The ``utilities.srblib`` module
3===============================
4
5SRB_ ("Storage Resource Broker") is a distributed filesystem, developed by the
6San Diego Supercomputer Center, and intended for "Grid" applications, where
7geographically-separated groups need to share large quantities of data.
8
9SRB comes with a client Python library, but this is very low level, and the API
10is not very Pythonic. This module aims to provide a more useable interface to
11SRB, allowing you to treat an SRB system more like a local filesystem.
12
13Various alternative high-level SRB Python interfaces are available: srboo_,
14SRBpy_ and pysrb_. These mostly offer more features than `srblib`, but I didn't
15succeed in getting any of them up-and-running, so here is another one.
16
17Installing the low-level ``srb`` module
18~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
19
20There are some good build instructions for the low-level bindings at:
21`<http://www.vislab.uq.edu.au/research/accessgrid/virtual_fs/building.htm>`_
22
23If building on OS X, I found this useful:
24`<https://lists.sdsc.edu/pipermail/srb-chat/2007-November/004506.html>`_
25
26Make sure you create a directory called ``.srb`` in your home directory and, in
27this directory, a file called ``.MdasEnv``, which should look something like this::
28   
29    mdasCollectionHome '/home/srbdev.sdsc'
30    mdasDomainHome 'sdsc'
31    srbUser 'srbdev'
32    srbHost 'torah.sdsc.edu'
33    defaultResource 'unix-sdsc'
34    AUTH_SCHEME 'ENCRYPT1'
35   
36Check your configuration works using the "Scommands_" before trying the Python
37interface. You will find full details on the `SRB website`__.
38
39Browsing an SRB filesystem
40~~~~~~~~~~~~~~~~~~~~~~~~~~
41
42If you have your ``.MdasEnv`` file setup correctly, you can connect to an SRB
43server using::
44
45    >>> from NeuroTools.utilities.srblib import *
46    >>> S = SRBFileSystem('facets.inria.fr')
47   
48(It is also possible to override the contents of ``.MdasEnv``, or even to have
49no such file at all, by passing the connection parameters (``username``,
50``password``, etc) as keyword arguments to the constructor.) You can now browse
51the server using method calls similar to the Unix command-line, e.g.::
52
53    >>> S.ls()
54    ...
55    >>> S.cd("/INRIA/home/INRIA/WP5")
56    >>> S.ls()
57    >>> S.get("srbtestfile", "/tmp/localfile")
58    >>> S.put("/tmp/localfile", "srbtestfile_copy")
59
60You can also open files and read to/write from them more-or-less as if they were
61on your local filesystem::
62
63    >>> f = S.open("srbtestfile2", "w")
64    >>> f.write("Mate, this bird wouldn't 'voom' if you put four million volts through it!\n")
65    >>> f.close()
66    >>> f = S.open("srbtestfile2", "r")
67    >>> print f.read()
68    Mate, this bird wouldn't 'voom' if you put four million volts through it!
69    >>> f.close()
70
71Accessing files by URL
72~~~~~~~~~~~~~~~~~~~~~~
73
74This part of the interface was inspired by `urllib`_ from the Python standard
75library. There is no need to create an ``SRBServer`` object, just pass an
76"``srb://``" URL to the ``urlopen`` or ``urlretrieve`` functions::
77
78    >>> f = urlopen("srb://facets.inria.fr/INRIA/home/INRIA/WP5/srbtestfile2")
79    >>> print f.read()
80    Mate, this bird wouldn't 'voom' if you put four million volts through it!
81    >>> f.close()
82
83
84.. _SRB: http://www.sdsc.edu/srb/index.php/Main_Page
85.. _srboo: http://www.cheshire3.org/docs/objects/api/srboo-pysrc.html
86.. _SRBpy: http://plone.jcu.edu.au/hpc/staff/projects/hpc-software/SRBpy
87.. _pysrb: http://sourceforge.net/projects/pysrb/
88.. _urllib: http://docs.python.org/lib/module-urllib.html
89.. _Scommands: http://www.sdsc.edu/srb/index.php/Scommands
90
91__ SRB_
Note: See TracBrowser for help on using the browser.