tvaLib
Public Member Functions | Public Attributes | List of all members
lib.scene.SQLlists Class Reference

Generic. More...

Inheritance diagram for lib.scene.SQLlists:
lib.scene.Analyses lib.scene.CameraTypes lib.scene.Clusters lib.scene.SiteAnalyses lib.scene.Sites

Public Member Functions

def __init__ (self, class_prototype, sql_prototype, nonOptionalArgs, dir='', filename='scene.sqlite', kwargs)
 
def new (self, sqlFields={}, classFields)
 
def update (self)
 
def exportToCode (self, moduleName='tvaMetaData')
 
def objectFromDict (idx=0, kwargs)
 
def getAlchemyObject (self, idx)
 

Public Attributes

 nonOptionalArgs
 
 prototype
 
 class_prototype
 
 session
 

Detailed Description

Generic.

Definition at line 30 of file scene.py.

Constructor & Destructor Documentation

◆ __init__()

def lib.scene.SQLlists.__init__ (   self,
  class_prototype,
  sql_prototype,
  nonOptionalArgs,
  dir = '',
  filename = 'scene.sqlite',
  kwargs 
)
Example usage:
    SQLlists(Analysis, tvaMetaData.Analysis, config.dir, config.dbn, sites=sites, config=config)

Definition at line 31 of file scene.py.

31  def __init__(self, class_prototype, sql_prototype, nonOptionalArgs, dir='', filename='scene.sqlite', **kwargs):
32  ''' Example usage:
33  SQLlists(Analysis, tvaMetaData.Analysis, config.dir, config.dbn, sites=sites, config=config)
34  '''
35  tvaLib.Constructors.SuperList.__init__(self)
36  self.nonOptionalArgs = nonOptionalArgs
37  self.prototype = sql_prototype
38  self.class_prototype = class_prototype
39  try: dir = kwargs['dir_overide']
40  except: pass
41  try: filename = kwargs['filename_overide']
42  except: pass
43  try: self.session = tvaMetaData.createDatabase(os.path.join(dir,filename))
44  except: raise Exception, [390, 'Scene database file "'+os.path.join(dir,filename)+'" does not exist.']
45  #sorted(self.session.query(self.prototype).all(), key=lambda mbr: operator.attrgetter('name')(mbr).lower())
46  for object_ in self.session.query(self.prototype).all():
47  self.data.append(self.class_prototype(object_, *nonOptionalArgs, **kwargs))
48  return
49 

Member Function Documentation

◆ exportToCode()

def lib.scene.SQLlists.exportToCode (   self,
  moduleName = 'tvaMetaData' 
)

Definition at line 66 of file scene.py.

66  def exportToCode(self, moduleName='tvaMetaData'):
67  for object_ in self:
68  object_.exportToCode(moduleName)
69  return True
70 

◆ getAlchemyObject()

def lib.scene.SQLlists.getAlchemyObject (   self,
  idx 
)
Use this to pull a raw SQLalchemy object (usefull for injecting
    backreferences). Note the use of idx, and not Ix

Definition at line 80 of file scene.py.

80  def getAlchemyObject(self, idx):
81  ''' Use this to pull a raw SQLalchemy object (usefull for injecting
82  backreferences). Note the use of idx, and not Ix'''
83  return [x for x in self.session.query(self.prototype).all() if x.idx==idx][0]
84 

◆ new()

def lib.scene.SQLlists.new (   self,
  sqlFields = {},
  classFields 
)

Definition at line 50 of file scene.py.

50  def new(self, sqlFields={}, **classFields):
51  data = self.prototype(**sqlFields)
52  self.session.add_all([data])
53  self.session.commit()
54  self.data.append(self.class_prototype(data, *self.nonOptionalArgs, **classFields))
55  return True
56 

◆ objectFromDict()

def lib.scene.SQLlists.objectFromDict (   idx = 0,
  kwargs 
)
Take a dict of object parameters and emulate equivalent sqlaclhemy
    object with corresponding parameters. 

Definition at line 71 of file scene.py.

71  def objectFromDict(idx=0, **kwargs):
72  ''' Take a dict of object parameters and emulate equivalent sqlaclhemy
73  object with corresponding parameters. '''
74  from collections import namedtuple
75  struct = namedtuple('struct', ' '.join([kwarg for kwarg in kwargs]))
76  obj = struct(**kwargs)
77  obj.idx = idx
78  return obj
79 
def join(obj1, obj2, postSmoothing=True)
Definition: tools_obj.py:816

◆ update()

def lib.scene.SQLlists.update (   self)
Pass back any changes into SQLlist database. 

Definition at line 57 of file scene.py.

57  def update(self):
58  ''' Pass back any changes into SQLlist database. '''
59  objects = self.session.query(self.prototype).all()
60  for oIx in range(len(objects)):
61  objects[oIx] = self.data[oIx].write(objects[oIx])
62  self.session.add_all(objects)
63  self.session.commit()
64  return True
65 

Member Data Documentation

◆ class_prototype

lib.scene.SQLlists.class_prototype

Definition at line 38 of file scene.py.

◆ nonOptionalArgs

lib.scene.SQLlists.nonOptionalArgs

Definition at line 36 of file scene.py.

◆ prototype

lib.scene.SQLlists.prototype

Definition at line 37 of file scene.py.

◆ session

lib.scene.SQLlists.session

Definition at line 43 of file scene.py.


The documentation for this class was generated from the following file: