Commits

Ginés Martínez Sánchez committed f071a9f Draft

developing wsgi server

Comments (0)

Files changed (3)

ginsfsm/examples/wsgi/simple_wsgi_server.py

 """
 
 import logging
+logging.basicConfig(level=logging.DEBUG)
 
 from ginsfsm.gaplic import GAplic
 from ginsfsm.smachine import SMachine
 #===============================================================
 #                   Main
 #===============================================================
-def main(global_config, **settings):
+def main(global_config, **global_settings):
     """ Entry point to run with gserve (PasteDeploy)
     """
-    ga = GAplic('Wsgi-Example', **settings)
+    ga = GAplic('Wsgi-Example', **global_settings)
     ga.create_gobj(
         'wsgi-server',
         GWsgiServer,
 
 
 if __name__ == "__main__":
-
-    settings = {
+    global_settings = {
+        'trace_mach': True,
+        'logger': logging,
     }
-    ga = main(settings)
     SMachine._global_trace_mach = True
     GSock._global_trace_dump = True
+    ga = main({}, **global_settings)
 
     try:
         ga.mt_process()

ginsfsm/gaplic.py

     }
 }
 
+GAPLIC_GCONFIG = {
+    'global_settings': [dict, {}, 0, None,
+        'The global settings will be set to all new created gobj'
+        ' by overwrite_parameters() function'],
+    # trace_mach is inherited from SMachine.
+    'trace_mach': [bool, False, 0, None, 'Display simple machine activity'],
+    # logger is inherited from SMachine.
+    'logger': [None, None, 0, None, ''],
+}
+
 
 class GAplic(GObj):
     """ Container of gobj's running under the same process or thread.
 
     :param name: name of the gaplic, default is ``None``.
-    :param settings: keyword arguments, with the global parameters from a
-        ini configfile.
+    :param global_settings: keyword arguments,
+        with the global parameters from a ini configfile.
+        The global settings will be set to all new created gobj
+        by :func:`ginsfsm.gobj.GObj.overwrite_parameters` function.
+
 
         .. note::
 
            The parameters can be dot named to include
            the :term:`named-gobj`'s destination of the parameters.
 
-        .. warning::
-
-           The value of these global parameters **overriden**
-           the values arguments passed in :meth:`create_gobj` method.
 
     GAplic is the main boss.
     Manage the timer's, event queues, etc.
                 print('Program stopped')
 
     """
-    def __init__(self, name=None, **settings):
+    def __init__(self, name=None, **global_settings):
         GObj.__init__(self, GAPLIC_FSM)
         self.name = name
-        self.global_settings = settings.copy()
+        self.global_settings = global_settings.copy()
         # Call shutdown() to stop gaplic
         self.do_exit = multiprocessing.Event()
         """threading.Event() or multiprocessing.Event() object
         self.thread_name = 0
         self.gaplic = self
         self.deferred_list = DeferredList()
-        logger = settings.get('logger', None)
-        if isinstance(logger, string_types):
-            self.logger = logging.getLogger(logger)
-        if self.logger is None:
+
+        logger = global_settings.get('logger', None)
+        if logger is None:
             # TODO use package caller
             self.logger = logging.getLogger(__name__)
+        else:
+            if isinstance(logger, string_types):
+                self.logger = logging.getLogger(logger)
+            else:
+                self.logger = logger
         self.logger and self.logger.info('GAplic (%s) initiated' % self.name)
 
     def _increase_inside(self):
         _gaplic_kw = {
             'gaplic': self,
             'logger': self.logger,
+            'global_settings': self.global_settings,
             'create_gobj': self.create_gobj,
             'enqueue_event': self.enqueue_event,
             'register_unique_gobj': self.register_unique_gobj,
 # Attributes that a gaplic can update.
 GOBJ_GCONFIG = {
     'gaplic': [None, None, 0, None, ''],
+    'global_settings': [dict, {}, 0, None,
+        'The global settings will be set to all new created gobj'
+        ' by overwrite_parameters() function'],
     # trace_mach is inherited from SMachine.
     'trace_mach': [bool, False, 0, None, 'Display simple machine activity'],
     # logger is inherited from SMachine.
         self.owned_event_filter = None  # TODO debe ser una lista de filtros
         """Filter to broadcast_event function to check the owner of events.
         """
-        self.global_settings = None
-        """This global settings will be set to all new created gobj.
-        """
 
         self._dl_subscriptions = set()      # uauuu, how many fans!!
         self._some_subscriptions = False