PyCool Utilities

PyCool is a python bindings package for COOL. The following utilities are based on it:

CoolConsole

CoolConsole builds on top of PyCool and offers a 'console' to access a COOL database.

CoolTool

CoolTool offers inspection for COOL databases.

CoolCopy

CoolCopy implements basic replication of COOL databases.

CoolConsole Demonstration

[titan:COOL_HEAD/src/CoolCopy] sas% python python/CoolConsole.py COOLTEST.db
Connected to 'sqlite://;schema=COOLTEST.db;dbname=COOLTEST'
Welcome to CoolConsole. Type 'help' for instructions.
>>> help
Available commands:
  exit     : quit the interpreter session
  help     : help overview
  ls       : list contents of folders and foldersets, e.g. ls "/"
  open     : open the specified database, e.g. open 'sqlite://...'
  quit     : alias for exit
These commands are shortcuts that are forwarded to a CoolTool
instance 'this', referring to the currently connected database.
Since this environment is a fully functional python shell,
'this' can be used like any python object, e.g.:
  this.ls( '/' )
>>> open 'COOLTEST.db'
>>> ls
Contents of '/':
  /f1/              first folderset
  /f2/              a description
>>> ls f1
Contents of '/f1':
  /f1/a             
  /f1/b             
>>> ls f1/a
Contents of '/f1/a':
  Object [0,1[ (0) { I : 0, D : 0.0, S : Object 00000, channel 00000 }
  Object [1,2[ (0) { I : 1000, D : 1.0, S : Object 00001, channel 00000 }
  Object [2,3[ (0) { I : 2000, D : 2.0, S : Object 00002, channel 00000 }
  Object [3,4[ (0) { I : 3000, D : 3.0, S : Object 00003, channel 00000 }
>>> import CoolCopy 
>>> help(CoolCopy)
Help on module CoolCopy:

NAME
    CoolCopy

FILE
    /Users/sas/Projects/Atlas/myLCG/COOL_HEAD/src/CoolCopy/python/CoolCopy.py

CLASSES
    CoolCopy
    exceptions.Exception
        CopyError
    Selection
    
    class CoolCopy
     |  Methods defined here:
     |  
     |  __init__(self, source)
     |      Initialize the object to a given database.
     |      
     |      If 'source' is of type string, it must be a RAL compliant connect 
     |      string or an sqlite filename following the requirements described 
     |      in CoolTool.connect.
...
>>> help(CoolCopy.copy)
Help on function copy in module CoolCopy:

copy(sourceDb, targetDb, nodeName='/',
     since=<PyCool.ValidityKey.ValidityKey instance at 0x2ec300>, 
     until=<PyCool.ValidityKey.ValidityKey instance at 0x2ec1c0>,
     channels=<pylcgdict.ChannelSelection object at 0x46ab70>, tag='')
    Copies the specified selection from the given source to the target database.
    
    'sourceDb' and 'targetDb' are RAL compatible connection strings or
    cool.IDatabase objects.
    
    If 'targetDb' is a connection string, the database must not exists
    -- 'copy' will attempt to create it and fail if it exists. In case
    'targetDb' is a cool.IDatabase object, database must not contain any
    data. (A check is made if any nodes other than '/' exist on the target
    database.)
    
    The selection is specified through the following arguments:
        nodeName : name of a folder or folderset
        since    : beginning of IOV, long or cool.ValidiyKey
        until    : end of IOV, long or cool.ValidiyKey. NB: the end point is
                   *included* in selections
        channels : a channel range as specified through cool.ChannelSelection 
        tag      : a tag name
(END) 
>>> CoolCopy.copy( this.db, 'sqlite://;schema=REPLICA.db;dbname=REPLICA', '/f1' )
INFO:CoolCopy: Copying HEAD of folder '/f1/a'
INFO:CoolCopy: Copying HEAD of folder '/f1/b'
>>> open REPLICA.db
>>> ls
Contents of '/':
  /f1/              
>>> CoolCopy.copy( this.db, 'REPLICA.db', '/f1' )
Copy failed with error: Target database 'sqlite://;schema=REPLICA.db;dbname=REPLICA' 
could not be created: Could not create a table named "REPLICA_DB_ATTRIBUTES" under 
the user schema "main". It already exists.
>>> import CoolTool
>>> targetDb, connectString = CoolTool.connect( 'REPLICA.db' )
>>> print targetDb
<pylcgdict.IDatabase object at 0x4260f0>
>>> print connectString
sqlite://;schema=REPLICA.db;dbname=REPLICA
>>> CoolCopy.copy( this.db, targetDb, '/f1' )
Copy failed with error: Target database contains data. Copy aborted.

-- SvenASchmidt - 14 Sep 2005

Edit | Attach | Watch | Print version | History: r3 < r2 < r1 | Backlinks | Raw View | WYSIWYG | More topic actions
Topic revision: r3 - 2005-09-19 - SvenASchmidt
 
    • Cern Search Icon Cern Search
    • TWiki Search Icon TWiki Search
    • Google Search Icon Google Search

    LCG All webs login

This site is powered by the TWiki collaboration platform Powered by PerlCopyright & 2008-2019 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback