fdi.pal package

Subpackages

Submodules

fdi.pal.comparable module

class fdi.pal.comparable.Comparable(**kwds)[source]

Bases: object

compareTo(o)[source]

fdi.pal.context module

class fdi.pal.context.AbstractContext(*args, **kwds)[source]

Bases: object

A special kind of Product that can hold references to other Products.

This abstract product introduces the lazy loading and saving of references to Products or ProductRefs that it is holding. It remembers its state. http://herschel.esac.esa.int/hcss-doc-15.0/load/hcss_drm/api/herschel/ia/pal/Context.html

Sets rule to None if zInfo does not have refs, else to zInfo['refs'].

__init__(*args, **kwds)[source]

Sets rule to None if zInfo does not have refs, else to zInfo['refs'].

addRule(rule)[source]

Add to the rule that controls the products to be added into the context. The new rule will be old rule AND added rule.

applyRule(*args)[source]

returns True if the input ProductRef passes rule.

If refs is not specified in zInfo return True. If ``zInfo[‘refs’] is empty, return True.

Subclasses can override this method according to what is written in zInfo.

getAllRefs(recursive, includeContexts)[source]

Provides a set of the unique references stored in this context.

getRefs()[source]

Returns the reference container mapping

getRule()[source]

Get the rule that controls the products to be added into the context.

hasDirtyReferences(storage)[source]

Returns a logical to specify whether this context has dirty references or not.

static isContext(cls)[source]

Yields true if specified class belongs to the family of contexts.

isValid()[source]

Provides a mechanism to ensure whether it is valid to store this context in its current state.

readDataset(storage, table, defaultPoolId)[source]

Reads a dataset with information within this context that is normally not accessible from the normal Product interface.

property refs

Property

refsChanged()[source]

Indicates that the references have been changed in memory, which marks this context as dirty.

set(name, refs)[source]

add owner to RefContainer or add named references.

Name

name of the new RefContainer. if is refs, set owner of refs to self.

setRefs(refs)[source]

Changes/Adds the mapping container that holds references.

setRule(rule)[source]

Set the rule that controls the products to be added into the context.

writeDataset(storage)[source]

Creates a dataset with information within this context that is normally not accessible from the normal Product interface.

class fdi.pal.context.Context(*args, **kwds)[source]

Bases: fdi.pal.context.AbstractContext, fdi.dataset.baseproduct.BaseProduct

See docstring of AbstractContext.

__init__(*args, **kwds)[source]
applyRule(*args)[source]

returns True if the input ProductRef passes rule.

Default behavior is return the superclass.applyRule() result.

Subclasses can override this method according to what is written in zInfo.

getAllRefs(recursive=False, includeContexts=True, seen=None)[source]

Provides a set of the unique references stored in this Context.

This includes references that are contexts, but not the contents of these subcontexts. This is equivalent to getAllRefs(recursive=false, includeContexts= true). recursive - if true, include references in subcontexts includeContexts - if true, include references to contexts, not including this one

hasDirtyReferences(storage)[source]

Returns a logical to specify whether this context has dirty references or not.

exception fdi.pal.context.ContextRuleException[source]

Bases: ValueError

class fdi.pal.context.MapContext(*args, **kwds)[source]

Bases: fdi.pal.context.Context

Allows grouping Products into a map of (String, ProductRef) pairs. New entries can be added if they comply to the adding rules of this context. The default behaviour is to allow adding any (String,ProductRef) given that rule is not set.

An example:

image     = ImageProduct(description="hi")
spectrum  = SpectrumProduct(description="there")
simple    = Product(description="everyone")

context=MapContext()
context.refs.put("x",ProductRef(image))
context.refs.put("y",ProductRef(spectrum))
context.refs.put("z",ProductRef(simple))
print context.refs.size() # 3
print context.refs.get('x').product.description # hi
print context.refs.get('y').product.description # there
print context.refs.get('z').product.description # everyone

It is possible to insert a ProductRef at a specific key in the MapContext. The same insertion behaviour is followed as for a Python dict, in that if there is already an existing ProductRef for the given key, that ProductRef is replaced with the new one:

product4=SpectrumProduct(description="everybody")
context.refs.put("y", ProductRef(product4))
product5=SpectrumProduct(description="here")
context.refs.put("a", ProductRef(product5))

print context.refs.get('x').product.description # hi
print context.refs.get('y').product.description # everybody
print context.refs.get('z').product.description # everyone
print context.refs.get('a').product.description # here

Note that the rules are only applied when putting an entry to the map!

Be aware that

  1. the put() method of the map view may throw a ContextRuleException if the data added to the context violates the rules applied to the context.

  2. the put() method of the map view may throw a ValueError if either of the arguments to the put() method are null.

    BaseProduct–Product

AbstractContext——Contex———MapContext

__init__(*args, **kwds)[source]
addRule(rule)[source]

Add to the rule that controls the products to be added into the context. The new rule will be old rule AND added rule.

applyRule(key, ref)[source]

returns True if the input key name and ProductRef pass rule.

Default behavior is return True if the fully qualified class name of the product which ref refers to equals zInfo['refs'][key], OR the superclass.applyRule() result.

Subclasses can override this method according to what is written in zInfo.

class fdi.pal.context.RefContainer(**kwds)[source]

Bases: fdi.dataset.odict.ODict

A map where Rules of its owner Context are applied when put(k,v) is called, and the owner MapContext’s ID can be put to v’s parents list.

Implemented as an ODict that RefContainer has a _STID when json.loads’ed. A MapContext has a _data, which has a refs:RefContainer, which has a datap, which has a name:ProductRef. when used as context.refs.get(‘x’).product.description, the RefContainer is called with get() or __getitem__(), which calls superclass composite’s __getitem__()

__init__(**kwds)[source]
clear()[source]

remove all productRefs

get(key, *args, **kwds)[source]
getOwner()[source]

Returns the reference container mapping

property owner

Property

put(key, ref)

set label-ref pair after validating then add parent to the ref

set(key, ref)[source]

set label-ref pair after validating then add parent to the ref

setOwner(owner)[source]

records who owns this container.

Due to reason described in __setitem__ doc, existing refs will be set again upon owner set

size()[source]
string(level=0, tablefmt='grid', **kwds)
level

default=0,

keyval

default=`None`. If set to a string, ODict class name is not shown and a label of given string is shown with each key as ‘label key:

‘.
tablefmt

=’rst’, tablefmt1=’simple’, tablefmt2=’simple’, matprint=None, trans=True, heavy=True

toString(level=0, tablefmt='grid', **kwds)[source]
level

default=0,

keyval

default=`None`. If set to a string, ODict class name is not shown and a label of given string is shown with each key as ‘label key:

‘.
tablefmt

=’rst’, tablefmt1=’simple’, tablefmt2=’simple’, matprint=None, trans=True, heavy=True

fdi.pal.definable module

class fdi.pal.definable.Definable(**kwds)[source]

Bases: object

for items being able to be defined with a Definition.

getDefinition()[source]

Returns the definition associated to this definable item. mh: adopting http://herschel.esac.esa.int/hcss-doc-15.0/load/hcss_drm/api/index.html?herschel/ia/pal/ProductRef.html but parameterize definition does not seem worth it given the few numbers of implemented definitions

fdi.pal.dicthk module

class fdi.pal.dicthk.DictHk(**kwds)[source]

Bases: fdi.pal.taggable.Taggable

Definition of services provided by a product storage supporting versioning.

getTagUrnMap()[source]

Get the full tag->urn mappings. mh: returns an iterator

getTags(urn=None)[source]

Get all of the tags that map to a given URN. Get all known tags if urn is not specified. mh: returns an iterator.

getUrn(tag)[source]

Gets the URNs corresponding to the given tag. Returns an empty list if tag does not exist.

getUrnObject(tag)[source]

Gets the URNobjects corresponding to the given tag.

removeTag(tag)[source]

Remove the given tag from the tag and urn maps.

removeUrn(urn)[source]

Remove the given urn from the tag and urn maps.

Only changes maps in memory, not on disk.

removekey(key, themap, thename, othermap, othername)[source]

Remove the given key.

setTag(tag, urn)[source]

Sets the specified tag to the given URN.

tagExists(tag)[source]

Tests if a tag exists.

fdi.pal.httpclientpool module

class fdi.pal.httpclientpool.HttpClientPool(**kwds)[source]

Bases: fdi.pal.productpool.ProductPool

the pool will save all products on a remote server.

Initialize connection to the remote server. creates file structure if there isn’t one. if there is, read and populate house-keeping records. create persistent files on server if not exist.

__init__(**kwds)[source]

Initialize connection to the remote server. creates file structure if there isn’t one. if there is, read and populate house-keeping records. create persistent files on server if not exist.

dereference(**kwds)[source]

Decrement the reference count of a ProductRef.

exists(**kwds)[source]

Determines the existence of a product with specified URN.

getCacheInfo(**kwds)[source]
getCount(**kwds)[source]

Return the number of URNs for the product type.

getPoolpath(**kwds)[source]
getProductClasses(**kwds)[source]

Returns all Product classes found in this pool. mh: returns an iterator.

getReferenceCount(**kwds)[source]

Returns the reference count of a ProductRef.

getTagUrnMap(**kwds)[source]

Get the full tag->urn mappings. mh: returns an iterator

getTags(**kwds)[source]

Get all of the tags that map to a given URN. Get all known tags if urn is not specified. mh: returns an iterator.

getUrn(**kwds)[source]

Gets the URNs corresponding to the given tag. Returns an empty list if tag does not exist.

getUrnObject(**kwds)[source]

Gets the URNobjects corresponding to the given tag.

isAlive(**kwds)[source]

Test if the pool is capable of responding to commands.

isEmpty(**kwds)[source]

Determines if the pool is empty.

meta(urn)[source]

Loads the meta-data belonging to the product of specified URN.

readHK()[source]

loads and returns the housekeeping data

reference(**kwds)[source]

Increment the reference count of a ProductRef.

removeAll(**kwds)[source]

Remove all pool data (self, products) and all pool meta data (self, descriptors, indices, etc.).

removeTag(**kwds)[source]

Remove the given tag from the tag and urn maps.

removeUrn(**kwds)[source]

Remove the given urn from the tag and urn maps.

removekey(**kwds)[source]

Remove the given key.

schematicLoad(resourcetype, index, start=None, end=None, serialize_out=False)[source]

does the scheme-specific part of loadProduct.

schematicRemove(urn=None, resourcetype=None, index=None)[source]

does the scheme-specific part of removal.

urn or (resourcetype, index)

schematicSave(products, tag=None, geturnobjs=False, serialize_out=False, **kwds)[source]

does the media-specific saving to remote server.

schematicSelect(**kwds)[source]

to be implemented by subclasses to do the scheme-specific querying.

schematicWipe()[source]

does the scheme-specific remove-all

setTag(**kwds)[source]

Sets the specified tag to the given URN.

setup()[source]

Sets up HttpPool interals.

Make sure that self._poolname and self._poolurl are present.

tagExists(**kwds)[source]

Tests if a tag exists.

fdi.pal.httpclientpool.parseApiArgs1(all_args, serialize_out=False)[source]

parse the command path to get positional and keywords arguments.

all_args: a list of path segments for the args list.

fdi.pal.httpclientpool.serialize_args1(*args, **kwds)[source]
fdi.pal.httpclientpool.toServer(method_name=None)[source]

decorator to divert local calls to server and return what comes back.

fdi.pal.httpclientpool.toserver(self, method, *args, **kwds)[source]
fdi.pal.httpclientpool.writeJsonwithbackup(fp, data)[source]

write data in JSON after backing up the existing one.

fdi.pal.httppool module

class fdi.pal.httppool.HttpPool(**kwds)[source]

Bases: fdi.pal.localpool.LocalPool

the pool will save all products locally on the host Http server.

creates file structure if there isn’t one. if there is, read and populate house-keeping records. create persistent files if not exist.

__init__(**kwds)[source]

creates file structure if there isn’t one. if there is, read and populate house-keeping records. create persistent files if not exist.

fdi.pal.localpool module

class fdi.pal.localpool.LocalPool(makenew=True, **kwds)[source]

Bases: fdi.pal.productpool.ManagedPool

the pool will save all products in local computer.

Makenew

when the pool does not exist, make a new one (``True`; default) or throws PoolNotFoundError (`False`).

creates file structure if there isn’t one. if there is, read and populate house-keeping records. create persistent files if not exist.

__init__(makenew=True, **kwds)[source]

creates file structure if there isn’t one. if there is, read and populate house-keeping records. create persistent files if not exist.

doLoad(resourcetype, index, start=None, end=None, serialize_out=False)[source]

does the action of loading.

serialize_out: if True returns contents in serialized form.

doRemove(resourcetype, index)[source]

does the action of removal of product from pool.

doSave(resourcetype, index, data, tag=None, serialize_in=True, **kwds)[source]

does the media-specific saving.

index: int

doWipe()[source]

does the action of remove-all

getCacheInfo()[source]
getHead(ref)[source]

Returns the latest version of a given product, belonging to the first pool where the same track id is found.

getMetaByUrn(urn, resourcetype=None, index=None)[source]

Get all of the meta data belonging to a product of a given URN.

mh: returns an iterator.

getMetaByUrnJson(urn, resourcetype, index)[source]
readHK(hktype=None, serialize_out=False)[source]

loads and returns the housekeeping data

hktype: one of ‘classes’, ‘tags’, ‘urns’ to return. default is None to return alldirs serialize_out: if True return serialized form. Default is false.

readmmap(filename, start=None, end=None, close=False, check_time=False)[source]
setMetaByUrn(start, end, urn)[source]

Sets the location of the meta data of the specified data to the given URN.

Data

usually serialized Product.

setup()[source]

Sets up LocalPool interals.

Make sure that self._poolname and self._poolurl are present.

writeHK(fp0=None)[source]

save the housekeeping data to disk

writeJsonmmap(fp, data, serialize_in=True, serialize_out=False, close=False, check_time=False, meta_location=False, **kwds)[source]

write data in JSON from mmap file at fp.

register the file. Leave file open by default close. data: to be serialized and saved. serialize_out: if True returns contents in serialized form. :check_time: to check if file has not been written since we did last time. Default False. :meta_location: return the start and end offsets of metadata in data JSON. Default False. :return: int bytes written. If meta_location is `True`, adding int int start and end point offsets of metadata in seriaized data.

fdi.pal.localpool.wipeLocal(path)[source]

does the scheme-specific remove-all.

A new directory at path will be created.

fdi.pal.mempool module

class fdi.pal.mempool.MemPool(**kwds)[source]

Bases: fdi.pal.productpool.ManagedPool

the pool will save all products in memory.

creates data structure if there isn’t one. if there is, read and populate house-keeping records. create persistent files if not exist.

__init__(**kwds)[source]

creates data structure if there isn’t one. if there is, read and populate house-keeping records. create persistent files if not exist.

doLoad(resourcetype, index, start=0, end=0, serialize_out=False)[source]

does the action of loadProduct. note that the index is given as a string.

doRemove(resourcetype, index)[source]

does the action of removal.

doSave(resourcetype, index, data, tag=None, serialize_in=True, **kwds)[source]

does the media-specific saving

doWipe()[source]

does the action of remove-all

getHead(ref)[source]

Returns the latest version of a given product, belonging to the first pool where the same track id is found.

getMetaByUrn(urn, resourcetype=None, index=None)[source]

Get all of the meta data belonging to a product of a given URN.

getPoolSpace()[source]

returns the map of this memory pool.

readHK(hktype=None, serialize_in=True, serialize_out=False)[source]

loads and returns the housekeeping data

hktype: one of ‘classes’, ‘tags’, ‘urns’ to return. default is None to return alldirs serialize_out: if True return serialized form. Default is false.

setMetaByUrn(data, urn)[source]

Sets the location of the meta data of the specified data to the given URN.

Data

usually unserialized Product.

setup()[source]

Sets up MemPool interals.

make sure that self._poolname and self._poolurl are present.

writeHK()[source]

save the housekeeping data to mempool

fdi.pal.poolmanager module

class fdi.pal.poolmanager.PoolManager[source]

Bases: object

This class provides the means to reference ProductPool objects without having to hard-code the type of pool. For example, it could be desired to easily switch from one pool type to another.

This is done by calling the getPool() method, which will return an existing pool or create a new one if necessary.

PlacePaths = {'file': '/tmp', 'http': '127.0.0.1:9883/fdi/v0.12', 'https': '127.0.0.1:9883/fdi/v0.12', 'mem': '/', 'server': '/tmp/data'}
classmethod getMap()[source]

Returns a poolname - poolobject map.

classmethod getPool(poolname=None, poolurl=None, pool=None, makenew=True, **kwds)[source]

returns an instance of pool according to name or path of the pool.

Returns the pool object if the pool is registered. Creates the pool if it does not already exist. the same poolname-path always get the same pool. Http pools will be registered on the sserver side.

Pools registered are kept as long as the last reference remains. When the last is gone the pool gets :meth;`removed` d.

poolname

name of the pool.

poolurl

if given the poolpath, scheme, place will be derived from it. if not given for making a new pool (i.e. when poolname is not a registered pool name..

If poolname is missing it is derived from poolurl; if poolurl is also absent, ValueError will be raised.
makenew

when the pool does not exist, make a new one (``True`; default) or throws PoolNotFoundError (`False`).

kwds

passed to pool instanciation arg-list.

Returns

the pool object.

classmethod getPoolurlMap()[source]

Gives the default poolurls of PoolManager.

classmethod isLoaded(poolname)[source]

Whether an item with the given id has been loaded (cached).

Returns

the number of remaining week references if the pool is loaded. Returns 0 if poolname is not found in _GlobalPoolList or weakref count is 0.

items()[source]

Returns map’s items

classmethod remove(poolname)[source]

Remove from list and unregister remote pools.

returns 0 for successful removal, 1 for poolname not registered or referenced, still attempted to remove. > 1 for the number of weakrefs the pool still have, and removing failed.

classmethod removeAll()[source]

deletes all pools from the pool list, pools not wiped

classmethod save(poolname, poolobj)[source]
classmethod setPoolurlMap(new)[source]

Sets the default poolurls of PoolManager.

classmethod size()[source]

Gives the number of entries in this manager.

fdi.pal.poolmanager.remoteRegister(p, poolurl)[source]
fdi.pal.poolmanager.remoteUnregister(poolurl)[source]

this method does not reference pool object.

fdi.pal.productpool module

class fdi.pal.productpool.ManagedPool(**kwds)[source]

Bases: fdi.pal.productpool.ProductPool, fdi.pal.dicthk.DictHk

A ProductPool that manages its internal house keeping.

Creates and initializes a productpool.

  • poolname: if provided will override that in poolurl.

  • poolurl: needed to initialize.

dereference(ref)[source]

Decrement the reference count of a ProductRef.

doLoad(resourcetype, index, start=None, end=None, serialize_out=False)[source]

to be implemented by subclasses to do the action of loading

doRemove(resourcetype, index)[source]

to be implemented by subclasses to do the action of reemoving

doSave(resourcetype, index, data, tag=None, serialize_in=True, **kwds)[source]

to be implemented by subclasses to do the action of saving

doSelect(query, results=None)[source]

to be implemented by subclasses to do the action of querying.

doWipe()[source]

to be implemented by subclasses to do the action of wiping.

exists(urn)[source]

Determines the existence of a product with specified URN.

getCacheInfo()[source]
getCount(typename)[source]

Return the number of URNs for the product type.

getMetaByUrn(urn, resourcetype=None, index=None)[source]

Get all of the meta data belonging to a product of a given URN.

mh: returns an iterator.

getPoolpath()[source]

Gets the poolpath of this pool.

poolpath is usually derived from poolurl received from PoolManager during initialization.

getProductClasses()[source]

Returns all Product classes found in this pool. mh: returns an iterator.

getReferenceCount(ref)[source]

Returns the reference count of a ProductRef.

isEmpty()[source]

Determines if the pool is empty.

loadDescriptors(urn)[source]

Loads the descriptors belonging to specified URN.

lockpath(op='w')[source]

Make lock path using transformed poolname as name.

meta(urn)[source]

Loads the meta-data info belonging to the product of specified URN.

meta_filter(q, typename=None, reflist=None, urnlist=None, snlist=None)[source]

returns filtered collection using the query.

q is a MetaQuery valid inputs: typename and ns list; productref list; urn list

prod_filter(q, cls=None, reflist=None, urnlist=None, snlist=None)[source]

returns filtered collection using the query.

q: an AbstractQuery. valid inputs: cls and ns list; productref list; urn list

reference(ref)[source]

Increment the reference count of a ProductRef.

saveOne(prd, tag, geturnobjs, serialize_in, serialize_out, res, kwds)[source]

Save one product.

Res

list of result.

Serialize_out

if True returns contents in serialized form.

schematicLoad(resourcetype, index, start=None, end=None, serialize_out=False)[source]

do the scheme-specific loading

schematicRemove(urn=None, resourcetype=None, index=None)[source]

do the scheme-specific removing

schematicSave(products, tag=None, geturnobjs=False, serialize_in=True, serialize_out=False, **kwds)[source]

do the scheme-specific saving.

Serialize_out

if True returns contents in serialized form.

schematicSelect(query, results=None)[source]

do the scheme-specific querying.

schematicWipe()[source]

do the scheme-specific wiping

setMetaByUrn(start, end, urn)[source]

Sets the location of the meta data of the specified data to the given URN.

Data

usually un/serialized Product.

setup()[source]
Sets up interal machiney of this Pool,

but only if self._poolname and self._poolurl are present, and other pre-requisits are met.

Subclasses should implement own setup(), and make sure that self._poolname and self._poolurl are present with ``

if <pre-requisit not met>: return True if super().setup(): return True

# super().setup() has done its things by now. <do setup> return False

``

returns: True if not both self._poolname and self._poolurl are present.

transformpath(path)[source]

override this to changes the output from the input one (default) to something else.

exception fdi.pal.productpool.PoolNotFoundError[source]

Bases: Exception

class fdi.pal.productpool.ProductPool(poolname='', poolurl='', **kwds)[source]

Bases: fdi.pal.definable.Definable, fdi.pal.taggable.Taggable, fdi.pal.versionable.Versionable

A mechanism that can store and retrieve Products.

A product pool should not be used directly by users. The general user should access data in a ProductPool through a ProductStorage instance.

When implementing a ProductPool, the following rules need to be applied:

  1. Pools must guarantee that a Product saved via the pool saveProduct(Product) method is stored persistently, and that method returns a unique identifier (URN). If it is not possible to save a Product, an IOException shall be raised.

  2. A saved Product can be retrieved using the loadProduct(Urn) method, using as the argument the same URN that assigned to that Product in the earlier saveProduct(Product) call. No other Product shall be retrievable by that same URN. If this is not possible, an IOException or GeneralSecurityException is raised.

  3. Pools should not implement functionality currently implemented in the core package. Specifically, it should not address functionality provided in the Context abstract class, and it should not implement versioning/cloning support.

Creates and initializes a productpool.

  • poolname: if provided will override that in poolurl.

  • poolurl: needed to initialize.

exception ParametersIncommpleteError[source]

Bases: Exception

__init__(poolname='', poolurl='', **kwds)[source]

Creates and initializes a productpool.

  • poolname: if provided will override that in poolurl.

  • poolurl: needed to initialize.

accept(visitor)[source]

Hook for adding functionality to object through visitor pattern.

dereference(ref)[source]

Decrement the reference count of a ProductRef.

exists(urn)[source]

Determines the existence of a product with specified URN.

getCount(typename)[source]

Return the number of URNs for the product type.

getDefinition()[source]

Returns pool definition info which contains pool type and other pool specific configuration parameters

getId()[source]

Gets the identifier of this pool.

getPlace()[source]

Gets the place of this pool.

getPoolname()[source]

Gets the poolname of this pool as an Object.

getPoolurl()[source]

Gets the pool URL of this pool.

getProductClasses()[source]

Returns all Product classes found in this pool. mh: returns an iterator.

getReferenceCount(ref)[source]

Returns the reference count of a ProductRef.

getScheme()[source]

Gets the scheme of this pool.

getUrnId()[source]

Get the identifier of this pool used to build URN, usually it’s same as id returned by getId().

isAlive()[source]

Test if the pool is capable of responding to commands.

isEmpty()[source]

Determines if the pool is empty.

loadDescriptors(urn)[source]

Loads the descriptors belonging to specified URN.

loadProduct(urn, serialize_out=False)[source]

Loads a Product belonging to specified URN.

serialize_out: if True returns contents in serialized form.

meta(urn)[source]

Loads the meta-data belonging to the product of specified URN.

property poolname

for property getter

property poolurl

for property getter

reference(ref)[source]

Increment the reference count of a ProductRef.

remove(urn)[source]

Removes a Product belonging to specified URN.

removeAll()[source]

Remove all pool data (self, products) and all pool meta data (self, descriptors, indices, etc.).

saveDescriptors(urn, desc)[source]

Save/Update descriptors in pool.

saveProduct(product, tag=None, geturnobjs=False, serialize_in=True, serialize_out=False, **kwds)[source]

Saves specified product and returns the designated ProductRefs or URNs.

Saves a product or a list of products to the pool, possibly under the supplied tag, and returns the reference (or a list of references if the input is a list of products), or Urns if geturnobjs is True.

See pal document for pool structure.

serialize_out: if True returns contents in serialized form.

schematicLoad(resourcetype, index, start=None, end=None, serialize_out=False)[source]

to be implemented by subclasses to do the scheme-specific loading

schematicRemove(urn=None, resourcetype=None, index=None)[source]

to be implemented by subclasses to do the scheme-specific removing

schematicSave(products, tag=None, geturnobjs=False, serialize_in=True, serialize_out=False, **kwds)[source]

to be implemented by subclasses to do the scheme-specific saving

schematicSelect(query, results=None)[source]

to be implemented by subclasses to do the scheme-specific querying.

schematicWipe()[source]

to be implemented by subclasses to do the scheme-specific wiping.

select(query, variable='m', ptype=<class 'fdi.dataset.product.Product'>, results=None)[source]

Returns a list of references to products that match the specified query.

setPoolname(poolname)[source]

Replaces the current poolname of this pool.

setPoolurl(poolurl)[source]

Replaces the current poolurl of this pool.

setup()[source]
Sets up interal machiney of this Pool,

but only if self._poolname and self._poolurl are present, and other pre-requisits are met.

Subclasses should implement own setup(), and make sure that self._poolname and self._poolurl are present with ``

if <pre-requisit not met>: return True if super().setup(): return True

# super().setup() has done its things by now. <do setup> return False

``

returns: True if not both self._poolname and self._poolurl are present.

fdi.pal.productpool.makeLockpath(direc, op='w')[source]

returns the appropriate path to put lock file.

creats the path if non-existing. Set lockpath-base permission to all-modify so other fdi users can use. op: ‘r’ for readlock no-reading) ‘w’ for writelock (no-writing)

fdi.pal.productref module

class fdi.pal.productref.ProductRef(urn=None, poolname=None, product=None, meta=None, **kwds)[source]

Bases: fdi.dataset.metadataholder.MetaDataHolder, fdi.dataset.eq.DeepcmpEqual, fdi.dataset.serializable.Serializable, fdi.pal.comparable.Comparable

A lightweight reference to a product that is stored in a ProductPool or in memory.

Urn can be the string or URNobject.

Poolname if given overrides the pool name in urn, and causes metadata to be loaded from pool, unless this prodref points to a mempool. If meta is given, it will be used instead of that from poolname. A productref created from a single product will result in a memory pool urn, and the metadata won’t be loaded.

__init__(urn=None, poolname=None, product=None, meta=None, **kwds)[source]

Urn can be the string or URNobject.

Poolname if given overrides the pool name in urn, and causes metadata to be loaded from pool, unless this prodref points to a mempool. If meta is given, it will be used instead of that from poolname. A productref created from a single product will result in a memory pool urn, and the metadata won’t be loaded.

addParent(parent)[source]

add a parent

equals(o, verbose=False)[source]

true if o is a non-null ProductRef, with the same Product type than this one, and:

urns and products are null in both refs, or nurs are equal and products are null, or # <– mh urns are null in both refs, and their products are equal, or urns and products are equal in both refs

getHash()[source]

Returns a code number for the product; actually its MD5 signature. This allows checking whether a product already exists in a pool or not.

getMeta()[source]

Returns the metadata of the product.

getParents()[source]

Return the in-memory parent context products of this reference.

That is, the contexts in program memory that contain this product reference object. A context that contains a different product reference object pointing to the same URN is not a parent of this product reference.

Furthermore, it should be understood that this method does not return the parent contexts of the product pointed to by this reference as stored in any underlying pool or storage.

Returns: the parents

getPoolname()[source]

Returns the name of the product pool associated.

getProduct()[source]

Get the product that this reference points to.

If the product is a Context, it is kept internally, so further accesses don’t need to ask the storage for loading it again. Otherwise, the product is returned but the internal reference remains null, so every call to this method involves a request to the storage.

This way, heavy products are not kept in memory after calling this method, thus maintaining the ProductRef a lighweight reference to the target product.

In case of a Context, if it is wanted to free the reference, call unload().

Returns: the product

getSize()[source]

Returns the estimated size(in bytes) of the product in memory.

Useful for providing this information for a user that wants to download the product from a remote site. Returns: the size in bytes

getStorage()[source]

Returns the product storage associated.

getType()[source]

Specifies the Product class to which this Product reference is pointing to.

getUrn()[source]

Returns the Uniform Resource Name (URN) of the product.

getUrnObj()[source]

Returns the URN as an object.

isLoaded()[source]

Informs whether the pointed product is already loaded.

property meta

Property

property parents

property

property product
removeParent(parent)[source]

remove a parent

Parameters

parent

setParents(parents)[source]

Sets the in-memory parent context products of this reference.

Parameters

parents

setStorage(storage)[source]

Sets the product storage associated.

setUrn(urn)[source]
setUrnObj(urnobj, poolname=None, meta=None)[source]

sets urn

A productref created from a single product will result in a memory pool urn, and the metadata won’t be loaded.

urnobj: Urn a URN object. poolname: str if given overrides the pool name in urn, and causes metadata to be loaded from pool. meta: MetaData If is given, it will be used instead of that from poolname.

string(level=0, **kwds)
toString(level=0, **kwds)[source]
unload()[source]

Clear the cached meta and frees internal reference to the product, so it can be garbage collected.

property urn

Property

property urnobj

Property

fdi.pal.productstorage module

class fdi.pal.productstorage.ProductStorage(pool=None, poolurl=None, **kwds)[source]

Bases: object

Logical store created from a pool or a poolURL.

Every instanciation with the same pool will result in a new instance of ProdStorage.

Gets the storage “control pannel” for pool with specifed name.

pool: if is a string will be taken as a poolname. if is a pool object will be registered with its name, poolurl: is sent to the PoolManager with poolname to get the pool object.

__init__(pool=None, poolurl=None, **kwds)[source]

Gets the storage “control pannel” for pool with specifed name.

pool: if is a string will be taken as a poolname. if is a pool object will be registered with its name, poolurl: is sent to the PoolManager with poolname to get the pool object.

accept(visitor)[source]

Hook for adding functionality to object through visitor pattern.

getAllTags()[source]

Get all tags defined in the writable pool.

getHead(ref)[source]

Returns the latest version of a given product, belonging to the first pool where the same track id is found.

getMeta(urn)[source]

Get the metadata belonging to the writable pool that associated to a given URN. returns an ODict.

getPool(poolname)[source]

mh: returns the pool object from poolname

getPools()[source]

Returns the set of ProductPools registered. mh: in a list of poolnames

getProductClasses(poolname)[source]

Yields all Product classes found in this pool.

getTags(urn)[source]

Get the tags belonging to the writable pool that associated to a given URN. returns an iterator.

getUrnFromTag(tag)[source]

Get the URN belonging to the writable pool that is associated to a given tag.

getWritablePool()[source]

returns the poolname of the first pool, which is the only writeable pool.

load(urnortag)[source]

Loads a product with a URN or a list of products with a tag, from the (writeable) pool.

It always creates new ProductRefs. :return: productref if there is only one. A `list` of `ProductRefs`. urnortag: urn or tag

register(poolname=None, poolurl=None, pool=None, **kwds)[source]

Registers the given pools to the storage.

remove(urn)[source]

removes product of urn from the writeable pool

save(product, tag=None, poolname=None, geturnobjs=False, **kwds)[source]

saves to the writable pool if it has been registered.

product: can be one or a list of prpoducts. poolName: if the named pool is not registered, registers and saves. geturnobjs: mh: returns UrnObjs if geturnobjs is True. kwds: options passed to json.dump() for localpools. Returns: one or a list of productref with storage info.

select(query, previous=None)[source]

Returns a list of URNs to products that match the specified query.

Parameters: query - the query object previous - results to be refined Returns: the set of return eferences to products matching the supplied query.

unregister(pool=None, **kwds)[source]

Unregisters the given pools to the storage.

unregisterAll()[source]
wipePool()[source]

Clear all data and meta data of the writable pool.

fdi.pal.query module

class fdi.pal.query.AbstractQuery(product=<class 'fdi.dataset.product.Product'>, variable='p', where='', allVersions=False, **kwds)[source]

Bases: fdi.pal.query.StorageQuery

provides default implementations for the pal storage query.

creates an AbstractQuery with product variable name, query string or function.

product: type (Class or ‘Card’ name) of the products to be queried. where: the query string.

__init__(product=<class 'fdi.dataset.product.Product'>, variable='p', where='', allVersions=False, **kwds)[source]

creates an AbstractQuery with product variable name, query string or function.

product: type (Class or ‘Card’ name) of the products to be queried. where: the query string.

class fdi.pal.query.MetaQuery(product=<class 'fdi.dataset.product.Product'>, where='', allVersions=False, **kwds)[source]

Bases: fdi.pal.query.AbstractQuery

Meta data query formulates a query on the meta data of a Product.

Typically this type of query is faster than a full query on the Product Access Layer.

creates an MetaQuery with a query string or function.

product: type (Class or ‘Card’ name) of the products to be queried. where: the query string. ‘where’ is a query string or function that returns True or False. In the query string variable name is ‘m’ for a MetaData type, as in m = product.meta.

__init__(product=<class 'fdi.dataset.product.Product'>, where='', allVersions=False, **kwds)[source]

creates an MetaQuery with a query string or function.

product: type (Class or ‘Card’ name) of the products to be queried. where: the query string. ‘where’ is a query string or function that returns True or False. In the query string variable name is ‘m’ for a MetaData type, as in m = product.meta.

class fdi.pal.query.StorageQuery(**kwds)[source]

Bases: fdi.dataset.serializable.Serializable

Query on a ProductStorage.

accept(visitor)[source]

Hook for adding functionality to object through visitor pattern.

property allVersions
getAllVersions()[source]

Are all versions to be retrieved, or just the latest?

getType()[source]

Get the class used in the query.

getVariable()[source]

Get the variable name used in the query expression, eg “p”.

getWhere()[source]

Get the query expression to be evaluated.

retrieveAllVersions()[source]

Returns the allVersions related to this object.

setAllVersions(allVersions)[source]

Sets the allVersions of this object.

setType(type)[source]

Sets the type of this object.

setVariable(variable)[source]

Sets the variable of this object.

setWhere(where)[source]

Sets the where of this object.

string(level=0, tablefmt='rst', tablefmt1='simple', tablefmt2='rst', **kwds)
toString(level=0, tablefmt='rst', tablefmt1='simple', tablefmt2='rst', **kwds)[source]
property type
property variable
property where

fdi.pal.taggable module

class fdi.pal.taggable.Taggable(**kwds)[source]

Bases: object

Definition of services provided by a product storage supporting tagging.

getTagUrnMap()[source]

Get the full tag->urn mappings. mh: returns an iterator

getTags(urn=None)[source]

Get all of the tags that map to a given URN. Get all known tags if urn is not specified. mh: returns an iterator.

getUrn(tag)[source]

Gets the URNs corresponding to the given tag. Returns an empty list if tag does not exist.

getUrnObject(tag)[source]

Gets the URNobjects corresponding to the given tag.

removeTag(tag)[source]

Remove the given tag from the tag and urn maps.

removeUrn(urn)[source]

Remove the given urn from the tag and urn maps.

removekey(key, themap, thename, othermap, othername)[source]

Remove the given key.

setTag(tag, urn)[source]

Sets the specified tag to the given URN.

tagExists(tag)[source]

Tests if a tag exists.

fdi.pal.urn module

class fdi.pal.urn.Urn(urn=None, poolname=None, cls=None, index=None, poolurl=None, **kwds)[source]

Bases: fdi.dataset.eq.DeepcmpEqual, fdi.dataset.serializable.Serializable, fdi.pal.comparable.Comparable

The object representation of the product URN string.

The memory consumed by sets of this object are much less than sets of URN strings.

Only when the class types in URN string are not in classpath, the urn object will consume equals or a little more than URN string as the object has to hold the original urn string. However this should be considered as exceptional cases.

Using this object representation also help to avoid parsing cost of URN string. URN string should be immutable.

About_URN

The Universial Resource Name (URN) string has this format:

urn:<poolname>:<resourcetype>:<serialnumber>

where

<poolname>

Also called poolID. Its requirements is like that to a file name and a URL segment, having only printable characters excluding `` , ``%, ?, *, =, /.

<resourcetype>

class name of the data item (usually Product)

<serialnumber>

internal index for a certain <resourcetype>.

The poolname in a URN is a label. Some examples:

Storage Pools (subclasses of ProductPool) are where data item reside. The PoolURL is used to give practical information of a pool, such as a poolname, its location, and its access scheme. It is designed to be a local set-up detail that is supposed to be hidden from pool users. Data processing software use ``URN``s to refer to products, without specifying pool location. The poolID in a URN could be a LocalPool on the development laptop and a HTTPClientPool on the production cloud.

Creates the URN object with the urn string or components.

give urn and optional poolurl, or all poolname, cls, index arguments. if urn is given and pool, class, etc are also specified, the latter are ignored. else the URN object is constructed from them. Urn(u) will make a Urn object out of u.

All arguements are None by default.

__init__(urn=None, poolname=None, cls=None, index=None, poolurl=None, **kwds)[source]

Creates the URN object with the urn string or components.

give urn and optional poolurl, or all poolname, cls, index arguments. if urn is given and pool, class, etc are also specified, the latter are ignored. else the URN object is constructed from them. Urn(u) will make a Urn object out of u.

All arguements are None by default.

getIndex()[source]

Returns the product index.

getPlace()[source]

Returns the netloc in this

getPool()[source]

Returns the pool name in this

getPoolId()[source]

Returns the pool URN in this

getPoolpath()[source]

returns the poolpath stored

getScheme()[source]

Returns the urn scheme.

getType()[source]

Returns class type of Urn

getTypeName()[source]

Returns class type name of Urn.

getUrn()[source]

Returns the urn in this

getUrnWithoutPoolId()[source]
property place
property pool

returns the poolname.

setUrn(urn, poolurl=None)[source]

parse urn to get poolname, resource, index.

string(level=0, **kwds)
toString(level=0, **kwds)[source]
property urn

property

class fdi.pal.urn.UrnUtils[source]

Bases: object

static checkUrn(identifier)[source]

Throw a ValueError if the identifier is not a legal URN.

static containsUrn(poolobj, urn)[source]

Informs whether a URN belongs to the given pool.

static extractRecordIDs(urns)[source]

Extracts product IDs (serial numbers) from a set of urns.

static getClass(urn)[source]

Get the class contained in a URN.

static getClassName(urn)[source]

Get the class name contained in a URN.

static getLater(urn1, urn2)[source]

Returns the later of two urns.

static getPool(urn, pools)[source]

Returns the pool corresponding to the pool id inside the given urn.

pools: ProductPool or subclass

static getPoolId(urn)[source]

Returns the pool id part of the URN.

static getProductId(urn)[source]

Returns the product id part of the URN, that is, the last token.

static isUrn(identifier)[source]

Informs whether the given identifier corresponds to a URN.

fdi.pal.urn.makeUrn(poolname, typename, index)[source]

assembles a URN with infos of the pool, the resource type, and the index

index: int or string

fdi.pal.urn.parseUrn(urn)[source]

Checks the URN string is valid in its form and splits it.

A Product URN has several segment. For example if the urn is urn:mypool/v2:proj1.product:322 * poolname, also called poolURN or poolID, optionally path-like: mypool/v2, * resource type (usually class) name proj1.product, * index number 322,

returns poolname, resourceclass, index. if urn is None or empty returns (None,None,None)

fdi.pal.urn.parse_poolurl(url, poolhint=None)[source]

Disassambles a pool URL.

A Pool URL is It is generated to desribe . For example:

input: * url: to be decomposed. * poolhint: A urn or a poolname (the first distinctive substring) needs to be given if the poolname has more than one level.

returns: poolpath, scheme, place, poolname. returns (None, None,None,None) if url is None or empty.

About_poolURL

The PoolURL format is in the form of a URL that preceeds its poolname part:

<scheme>://<place><poolpath>/<poolname>

<scheme>

Implementation protocol including file for LocalPool, mem for MemPool, http, https for HttpclientPool.

<place>

IP:port such as``192.168.5.6:8080`` for http and https schemes, or an empty string for file and mem schemes.

<poolname>

same as in URN.

<poolpath>

The part between place and an optional poolhint:

<username>

<password>

  • For file or server schemes, e.g. poolpath is /c:/tmp in http://localhost:9000/c:/tmp/mypool/ with poolhint keyword arguement of parse_poolurl() not given, or given as mypool (or myp or my …).

  • For http and https schemes, it is e.g. /0.6/tmp in https://10.0.0.114:5000/v0.6/tmp/mypool with poolhint keyword arguement not given, or given as mypool (or myp` or 'my' ...). The meaning of poolpath is subject to interpretation by the  server. In the preceeding example the poolpath has an API version.  :meth:`ProductPool.transformpath` is used to map it further. Note that trailing blank and ``/ are ignored, and stripped in the output.

Examples:

fdi.pal.versionable module

class fdi.pal.versionable.Versionable(**kwds)[source]

Bases: object

for items being able to be defined with a Definition.

getLastVersion(ref)[source]

Returns the latest version of the given ProductRef.

getVersions(ref)[source]

Returns all the versions of the given ProductRef.

saveProductRef(ref)[source]

Saves the product referenced and returns the designated URN.

fdi.pal.webapi module