[TransWarp] simple application skeleton?

Vladimir Bormotov bor at vb.dn.ua
Tue Mar 4 17:25:54 EST 2003


                Hi!
                
 I try to make "simple application skeleton".  
 Code, look like "PEAK Hello, World!"
  
  
 main tasks:
    - application-wide logging
    - application-wide config for components.
   
 No storage, no UI. Just:
 
  start (write to log "Start"), 
  read components properties from local config (write to log values), 
  create one-two objects (write to log "Instance of First created" ...), 
  establish bindings (write to log "Class First establish binding to  Second"), 
  exit (write to log "Exit").
 

 where I can find some examples?
 
 Nice sources provided by net-labs.de (apps/acmgr), but no logging ;(
 
 
 Trivial local config via 
 
 $ export PEAK_CONFIG=PeakApp.ini 
 
 not work...

==== PeakApp.ini ====
[PeakApp]
tick_increment = 10
====

==== PeakApp.py ====
#!/usr/bin/python
"""PEAK Application Example
"""

from peak.api import *


__all__ = ['Tick', 'main']


class Tick(binding.Component):
    """Tick is binding.Componenet child"""

    def __init__(self, increment=None):
        """get given increment from argument or config"""
        self.tick = binding.New(int)
        self.increment = increment or \
                         binding.bindToProperty('PeakApp.tick_increment',
                                                default=5)

        LOG_DEBUG('%s.__init__(): increment=%s' % \
                  (self.__class__.__name__, self.increment))


    def next_tick(self):
        """make next tick"""
        self.tick += self.increment

        LOG_DEBUG('%s.next_tick(): tick=%s' % \
                  (self.__class__.__name__, self.tick))


def main():
    """make Tick() instance and do 10 ticks"""
    _tick = Tick()
    for idx in range(10):
        _tick.next_tick()


if __name__ == "__main__":
    main()
====

 some dummy questions, answers on which I think would find in examples
 
 at first, logging:
 
  - how set PRI_DEBUG for default logger?
  - where read messages writed to log via LOG_DEBUG?
  - how set log-file-name for default logger?
   
 I think, "source mining" not best way to learn "how programm work".
 Me prefer "full debug log reading"... 
 
 at second, config...  
 But, with logging, I can add at "dark places of PEAK" calls of LOG_*
 myself, read logfile, and understand "how it work..." ;)
 
-- 
		Bor.



More information about the PEAK mailing list