13 import sys, logging, traceback
 
   28 from serverportfolio 
import Utils
 
   36 if __name__ == 
"__main__":
 
   39     print "DictionaryStocks main"    
   42     logging.basicConfig(level=logging.DEBUG)
 
   46     logger = logging.getLogger(
'SP')
 
   49     main_logger = logging.getLogger(
"SP.main") 
 
   53         dict_filename = str(sys.argv[1])
 
   54         main.logger.debug(
"dictionary file as argument: %s" % dict_filename)
 
   61     print "DictionaryStocks initialized" 
   64     print "\n== dict_stocks 2, test Singleton" 
   69     print id(dict_stocks1)
 
   71     print id(dict_stocks2)
 
   75     print "\n== get 1 Stock, CAC40" 
   81     dict_stocks1.print_dict_stocks( opt_print = 
True )
 
   85     lines = dict_stocks1.print_dict_stocks( 
"CAC40", opt_print = 
False )
 
   92     dict_stocks1.get_stocks(
"toto")
 
   98     print "\n== Print a existing and non-loaded stock" 
   99     lines = dict_stocks1.print_dict_stocks( [
"CAC40",
"SP500"], opt_print = 
False )
 
  100     print "line CAC40 SP500" 
  103     print "\n== Print 2 existing and 1 non-existing stock" 
  104     lines = dict_stocks1.print_dict_stocks( [
"CAC40",
"SP500", 
"toto"], opt_print = 
False )
 
  105     print "line CAC40 SP500 toto" 
  110     print "\n=== Update Inst Value" 
  114         dict_stocks1.update_data( action=
'InstValue' )
 
  116     except PortfolioError 
as ex:
 
  117         print "Main catch a PortfolioError " 
  123         exc_type, exc_value, exc_traceback = sys.exc_info()
 
  125         print "*** print_tb:" 
  126         traceback.print_tb(exc_traceback, limit=2, file=sys.stdout)
 
  127         print "full message: \n", ex.get_format_string()
 
  129         print "exit properly " 
  133     except Exception 
as ex:
 
  135         print "got general Exception in Update(), Should not happen %s " % ex
 
  136         exc_type, exc_value, exc_traceback = sys.exc_info()
 
  138         print "*** print_tb:" 
  139         traceback.print_tb(exc_traceback, limit=4, file=sys.stdout)
 
  144     print '\n== After update inst value, summarize' 
  145     dict_stocks1.print_dict_stocks( opt_print = 
True )
 
  148     print "\n===== all stocks ===== " 
  150     dict_stocks1.print_dict_stocks( opt_print = 
True )
 
  155     print "\n=== check_open " 
  157     for stock 
in [
"CAC40",
"SP500", 
"toto"]:
 
  159         print "   CheckOpen ",dict_stocks1.check_open(stock)
 
  166     dict_stocks1.print_dict_stocks( opt_print = 
True )
 
  170     print "\n=== time_to_open " 
  171     for stock 
in dict_stocks1.get_stocks( [
"CAC40",
"SP500", 
"toto"] ):
 
  172         time_to_open = stock.time_to_open()
 
  173         print "   time_to_open ",time_to_open
 
  174     dict_stocks1.print_dict_stocks( opt_print = 
True )
 
  178     print "\n SaveInstValue " 
  180     for stock 
in dict_stocks1.get_stocks( [
"CAC40",
"SP500", 
"toto"] ):
 
  181        print "stock : ", stock
 
  196        stock.save_inst_value()
 
Define custom and specific exceptions for the complete package. 
Container of all Stocks objects, it also reads the static stocks configuration file "dictstocks...
Define singleton class DictionaryStocks, act as the main container of Stocks objects.