sop
index
/home/sfscript/src/py_sforce/sflib/sop.py

Copyright 2004 Chip Vanek, Magma Design Automation
 
   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at
 
       http://www.apache.org/licenses/LICENSE-2.0
 
   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
 
Simple Object persistance using pickle and file locking
    ConfigParser wrapper for text viewable user preferences
    
    ToDo: text encryption handling for any field, notably passwords & entry points
    
    Chip Vanek chip@upvia.com Nov 1st, 2004

 
Modules
       
ConfigParser
StringIO
cPickle
marshal
marshal
os
cPickle
pprint
SforceService_services
string
sys
time
types

 
Classes
       
AccessFactory
BasicCacheMixin
ConfigParser.ConfigParser(ConfigParser.RawConfigParser)
SFConfig
LockAndLoadMixin
SFEntitiesSOP
SFSOP
OpBranchSOP
SFBranchesSOP
SFCacheSOP
Private
SFEntitiesMixin
SFTestMixin
SFUtilityMixin

 
class AccessFactory
     Methods defined here:
__call__(self, *args)
__init__(self, klass)

 
class BasicCacheMixin
     Methods defined here:
__get__(self, key)
link get method to getCache
__init__(self, cache)
Pass in an SOP-based object
Provides generic set/get functionality
commitCache(self)
getCache(self, key, data={}, reset=False)
main accessor for getting cache information
getKeys(self, sortField='createDateTime')
return sorted (newest to oldest) list of all keys of items
in the pickle
setCache(self, key, data={}, commit=True)
load the latest data for the key into a simple object
persitence dictionary

Data and other attributes defined here:
cache = None
debug = 0

 
class LockAndLoadMixin
    ##########################################################################################
#  These are simple object persistence (thus SOP) classes to allow scripts to remember things
#   The SFEntitiesSOP class is tailored to store sForce entity metadata and refresh if stale
#
#   sfEntities is the entry point to access this structure, called from sfBase.py
##########################################################################################
 
  Methods defined here:
__del__(self)
changed(self)
commit(self)
getPath(self)
get the configured path for cache
load(self, default=None, marshal=False)
Must be called from init of object

 
class OpBranchSOP(SFSOP)
    Local cache of operations branch data.
 
 
Method resolution order:
OpBranchSOP
SFSOP
LockAndLoadMixin

Methods defined here:
__init__(self)
filename(self)

Data and other attributes defined here:
lastEntity = ''
lastUpdate = 0
maxObjAge = 864000
resetStale = False

Methods inherited from SFSOP:
__len__(self)
__repr__(self)
__str__(self)
data(self)
delData(self, key)
delete value from the cache
getAge(self, key)
return age of sop info in secs
getData(self, key, default='')
isStale(self, key)
Should we load fresh data from remote server
reset(self, state=False)
rest age to refresh on next access
setAge(self, key)
return age of sop info in secs
setData(self, key, value)

Methods inherited from LockAndLoadMixin:
__del__(self)
changed(self)
commit(self)
getPath(self)
get the configured path for cache
load(self, default=None, marshal=False)
Must be called from init of object

 
class Private
    simple data cloaking class that can be extended with encryption
 
  Methods defined here:
__init__(self, data, key=None, digest=False)
must have data, use preconfigured key if not provided
getData(self, dkey=None)
This needs to be private to be of any use
getDigest(self)
return public digest of this information
getKey(self, priv=False)
setData(self, data)
this can be a public method
setKey(self, key)
This needs to be private to be of any use

 
class SFBranchesSOP(SFSOP)
    Maintain a local file based copy of the branches loaded into sForce
The file path should be to a path available to all API users.
The information will be updated as load scripts are run from the 
modMigration, walkSF, and walkSCM scripts
 
 
Method resolution order:
SFBranchesSOP
SFSOP
LockAndLoadMixin

Methods defined here:
filename(self)

Data and other attributes defined here:
lastEntity = ''
lastUpdate = 0
maxObjAge = 31622400
resetStale = False

Methods inherited from SFSOP:
__init__(self, scope='All')
__len__(self)
__repr__(self)
__str__(self)
data(self)
delData(self, key)
delete value from the cache
getAge(self, key)
return age of sop info in secs
getData(self, key, default='')
isStale(self, key)
Should we load fresh data from remote server
reset(self, state=False)
rest age to refresh on next access
setAge(self, key)
return age of sop info in secs
setData(self, key, value)

Methods inherited from LockAndLoadMixin:
__del__(self)
changed(self)
commit(self)
getPath(self)
get the configured path for cache
load(self, default=None, marshal=False)
Must be called from init of object

 
class SFCacheSOP(SFSOP)
    Maintain a local file based cache of frequently accessed entities in sForce
The file path should be to a path available to all API users.
The information will be updated and used from load scripts are run from the 
modMigration, walkSF, and walkSCM scripts
 
 
Method resolution order:
SFCacheSOP
SFSOP
LockAndLoadMixin

Methods defined here:
filename(self)

Data and other attributes defined here:
lastEntity = ''
lastUpdate = 0
maxObjAge = 86400
resetStale = False

Methods inherited from SFSOP:
__init__(self, scope='All')
__len__(self)
__repr__(self)
__str__(self)
data(self)
delData(self, key)
delete value from the cache
getAge(self, key)
return age of sop info in secs
getData(self, key, default='')
isStale(self, key)
Should we load fresh data from remote server
reset(self, state=False)
rest age to refresh on next access
setAge(self, key)
return age of sop info in secs
setData(self, key, value)

Methods inherited from LockAndLoadMixin:
__del__(self)
changed(self)
commit(self)
getPath(self)
get the configured path for cache
load(self, default=None, marshal=False)
Must be called from init of object

 
class SFConfig(ConfigParser.ConfigParser)
    Simple subclass of ConfigParser to add:
 - default location of configuration file
 - parameter list handling 
Typical usage is:
 - create object with default dictionary if known
   - sfc = SFConfig({'username':'chip', 'port':80, 'output':'console'})
       ( passed defaults will overwrite defaults in files)
 - sfc.load() config from all possible config file
 - sfc.get(section, option)
 - sfc.set(section, option, value)
 - sfc.writeMy()
 
 
Method resolution order:
SFConfig
ConfigParser.ConfigParser
ConfigParser.RawConfigParser

Methods defined here:
__init__(self)
get(self, section, option, raw=False, vars=None)
Create section if it does not exist
getHome(self)
Get the os specific home directory
getList(self, section, option, raw=False, vars=None)
Get the values from the config file and return as a list
getPrivate(self, section, option, raw=False, key=None)
wrap get call with use of the Private class
load(self, scope='all')
Load a series of available configuration files from preset locations
loadMy(self)
Load or create the signed on users home sfConfig file
set(self, section, option, value)
Create section if it does not exist
setPrivate(self, section, option, value)
wrap set call with use of the Private class
writeMy(self)
Write the sfConfig file for the signed on user

Methods inherited from ConfigParser.ConfigParser:
items(self, section, raw=False, vars=None)
Return a list of tuples with (name, value) for each option
in the section.
 
All % interpolations are expanded in the return values, based on the
defaults passed into the constructor, unless the optional argument
`raw' is true.  Additional substitutions may be provided using the
`vars' argument, which must be a dictionary whose contents overrides
any pre-existing defaults.
 
The section DEFAULT is special.

Methods inherited from ConfigParser.RawConfigParser:
add_section(self, section)
Create a new section in the configuration.
 
Raise DuplicateSectionError if a section by the specified name
already exists.
defaults(self)
getboolean(self, section, option)
getfloat(self, section, option)
getint(self, section, option)
has_option(self, section, option)
Check for the existence of a given option in a given section.
has_section(self, section)
Indicate whether the named section is present in the configuration.
 
The DEFAULT section is not acknowledged.
options(self, section)
Return a list of option names for the given section name.
optionxform(self, optionstr)
read(self, filenames)
Read and parse a filename or a list of filenames.
 
Files that cannot be opened are silently ignored; this is
designed so that you can specify a list of potential
configuration file locations (e.g. current directory, user's
home directory, systemwide directory), and all existing
configuration files in the list will be read.  A single
filename may also be given.
readfp(self, fp, filename=None)
Like read() but the argument must be a file-like object.
 
The `fp' argument must have a `readline' method.  Optional
second argument is the `filename', which if not given, is
taken from fp.name.  If fp has no `name' attribute, `<???>' is
used.
remove_option(self, section, option)
Remove an option.
remove_section(self, section)
Remove a file section.
sections(self)
Return a list of section names, excluding [DEFAULT]
write(self, fp)
Write an .ini-format representation of the configuration state.

Data and other attributes inherited from ConfigParser.RawConfigParser:
OPTCRE = <_sre.SRE_Pattern object>
SECTCRE = <_sre.SRE_Pattern object>

 
class SFEntitiesMixin
    Part of the base sForce class that is focused on 
querying and storing entity metadata in the above SOP class
 
  Methods defined here:
describeGlobal(self)
describe global and set available entity list on object describeGlobal
describeSObject(self, sObjectType)
describe objects
getEntityMapFromSF(self, ent)
query sForce on metasdata on entity and return as a dictionary
_activateable: boolean
_createable: boolean
_custom: boolean
_deletable: boolean
_fields: ns2.Field_Def, optional
  _label: str
  _name: str
  _nameField: boolean
  _custom: boolean
  _filterable: boolean          -  us in where clause
  _nillable: boolean
  _createable: boolean
  _updateable: boolean
  _referenceTo: str, optional
 
  _restrictedPicklist: boolean
  _picklistValues: ns2.PicklistEntry_Def, optional
    _active: boolean
    _defaultValue: boolean
    _label: str, optional
    _value: str
  _byteLength: int
  _length: int
  _digits: int
  _precision: int
  _scale: int
  _soapType: ns2.soapType_Def
    _soapType: str, optional
  _type: ns2.fieldType_Def
    _fieldType: str, optional
_label: str
_name: str
_queryable: boolean
_replicateable: boolean
_retrieveable: boolean
_searchable: boolean
_undeletable: boolean
_updateable: boolean
setEntitiesMap(self)
load the latest metadata into a simple object persitence dictionary
setEntityMap(self, entity)
load the latest metadata for entity into a simple object persitence dictionary

 
class SFEntitiesSOP(LockAndLoadMixin)
    Maintain a file based copy of the sForce API metadata information
The file path should be to a path available to all API users.
The information will be refreashed from SF every X days or on demand
 
  Methods defined here:
__init__(self, scope='All')
__len__(self)
__repr__(self)
__str__(self)
data(self)
filename(self)
this is where the data will be pickled to
getAge(self, entity)
return age of sop info in secs
getEntity(self, entity, default='')
isStale(self, entity)
Should we load fresh data from remote server
reset(self, state=False)
rest age to refresh on next access
setAge(self, entity)
return age of sop info in secs
setEntity(self, entity, value)

Data and other attributes defined here:
lastEntity = ''
lastUpdate = 0
maxObjAge = 86400
resetStale = False

Methods inherited from LockAndLoadMixin:
__del__(self)
changed(self)
commit(self)
getPath(self)
get the configured path for cache
load(self, default=None, marshal=False)
Must be called from init of object

 
class SFSOP(LockAndLoadMixin)
    Maintain a local file based copy of sForce entity info
The file path should be to a path available to all API users.
A pair of get/set methods should be added to your tool class to 
access this class.  Examples are getEntitySOP, setEntitySOP in sfBase3
 
  Methods defined here:
__init__(self, scope='All')
__len__(self)
__repr__(self)
__str__(self)
data(self)
delData(self, key)
delete value from the cache
filename(self)
getAge(self, key)
return age of sop info in secs
getData(self, key, default='')
isStale(self, key)
Should we load fresh data from remote server
reset(self, state=False)
rest age to refresh on next access
setAge(self, key)
return age of sop info in secs
setData(self, key, value)

Data and other attributes defined here:
lastEntity = ''
lastUpdate = 0
maxObjAge = 432000
resetStale = False

Methods inherited from LockAndLoadMixin:
__del__(self)
changed(self)
commit(self)
getPath(self)
get the configured path for cache
load(self, default=None, marshal=False)
Must be called from init of object

 
class SFTestMixin
    Placeholder for methods from prior test
plus active test case data
 
  Methods defined here:
createTest1(self, entity='Task', data={}, nullEmpty=False, seed='on seed')
Some test data around the create call
getBySOQLBad(self, soql=None, limit=200)
search sForce using SOQL, return objects using retrieve call
CV May 25, 2004, another dead end with the state of the proxy objects
getRecType(self, node)
this assumes a DOM node object, Just used in getZSIProxyClass, so trash during cleanup
getZSIProxyClass(self, records)
Not used now, was a thread towards using the proxy objects build by wsdl2python
New way is to use the sellf.getEntityMap('entity') dictionary cached in file pickle
CV May 25, 2004, another dead end with the state of the proxy objects
retrieveByIds(self, ids=[], entity='Contact')
try the ZSI Proxy type objects, 
CV May 25, 2004, another dead end with the state of the proxy objects
updateTest1(self, entity='Task', data={}, nullEmpty=False, seed='on seed')
Some test data around the update call

 
class SFUtilityMixin
    Placeholder for utility methods
Field data transform, output formatters, etc.
 
  Methods defined here:
baseconvert(number, fromdigits, todigits)
convertChunk(chunk)
Used by convertId15ToId18
convertId15ToId18(id15)
Convert sForce 15 character IDs to 18 char IDs

Data and other attributes defined here:
BASE10 = '0123456789'
BASE16 = '0123456789ABCDEF'
BASE2 = '01'
BASE8 = '01234567'
BINARY = '01'
DECIMAL = '0123456789'
HEX = '0123456789ABCDEF'
OCTAL = '01234567'
TRANSLATION_TABLE = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ012345'

 
Functions
       
Lock = allocate_lock(...)
allocate_lock() -> lock object
(allocate() is an obsolete synonym)
 
Create a new lock object.  See LockType.__doc__ for information about locks.

 
Data
        False = False
True = True
opBranches = <sop.AccessFactory instance>
osFlags = 66
sfBranches = <sop.AccessFactory instance>
sfCache = <sop.AccessFactory instance>
sfEntities = <sop.AccessFactory instance>