commit-gnue
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

gnue geas/examples/python/neil_methods_test.py ...


From: Neil Tiffin
Subject: gnue geas/examples/python/neil_methods_test.py ...
Date: Sun, 23 Sep 2001 10:18:12 -0400

CVSROOT:        /home/cvs
Module name:    gnue
Changes by:     Neil Tiffin <address@hidden>    01/09/23 10:18:12

Modified files:
        geas/examples/python: neil_methods_test.py 
        geas/src/methods: methods_python.c 
        gnue-config    : README 
        gnue-config/test: gcd_pass_test.gcd 
Added files:
        gnue-config/test: gcd_pass_test.py 
Removed files:
        gnue-config    : neil_test.py 

Log message:
        Add recursive directory handling to methods code.

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/geas/examples/python/neil_methods_test.py.diff?cvsroot=OldCVS&tr1=1.5&tr2=1.6&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/geas/src/methods/methods_python.c.diff?cvsroot=OldCVS&tr1=1.12&tr2=1.13&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue-config/README.diff?cvsroot=OldCVS&tr1=1.6&tr2=1.7&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue-config/test/gcd_pass_test.py?cvsroot=OldCVS&rev=1.1
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue-config/test/gcd_pass_test.gcd.diff?cvsroot=OldCVS&tr1=1.2&tr2=1.3&r1=text&r2=text

Patches:
Index: gnue/geas/examples/python/neil_methods_test.py
diff -u gnue/geas/examples/python/neil_methods_test.py:1.5 
gnue/geas/examples/python/neil_methods_test.py:1.6
--- gnue/geas/examples/python/neil_methods_test.py:1.5  Sat Sep 22 17:46:35 2001
+++ gnue/geas/examples/python/neil_methods_test.py      Sun Sep 23 10:18:11 2001
@@ -3,7 +3,7 @@
 # a test file: relies on GEAS being run from gnue/geas/src
 # and this from gnue/geas/examples/python
 
-# $Id: neil_methods_test.py,v 1.5 2001/09/22 21:46:35 ntiffin Exp $
+# $Id: neil_methods_test.py,v 1.6 2001/09/23 14:18:11 ntiffin Exp $
 
 import sys
 import md5
@@ -123,7 +123,7 @@
         obj = con.newObject( "mod1::class1" )
         obj.setField("text_fld","joe")
         try:
-            a_result = obj.callMethod( "helloworld" , [a, b])
+            a_result = obj.callMethod( "cat_a_b" , [a, b])
             # print str(x) + ", Call method: " +  str(a_result)
         except GEAS.NullField,ex:
             print ex.detail
Index: gnue/geas/src/methods/methods_python.c
diff -u gnue/geas/src/methods/methods_python.c:1.12 
gnue/geas/src/methods/methods_python.c:1.13
--- gnue/geas/src/methods/methods_python.c:1.12 Sat Sep 22 18:06:51 2001
+++ gnue/geas/src/methods/methods_python.c      Sun Sep 23 10:18:11 2001
@@ -19,7 +19,7 @@
   along with GEAS; if not, write to the Free Software Foundation, Inc.,
   59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
-  $Id: methods_python.c,v 1.12 2001/09/22 22:06:51 ntiffin Exp $
+  $Id: methods_python.c,v 1.13 2001/09/23 14:18:11 ntiffin Exp $
 */
 
 /*
@@ -251,21 +251,20 @@
 python_load_method_handlers (configuration config)
 {
   GList *lst;
+  GList *filename_list;
   char *dirname;
-  char *name;
+  // char *name;
   odl_field *f;
-  struct dirent *entry;
-  DIR *dir;
   FILE *fp;
-  GList *l, *l2;
+  GList *l; 
+  GList *l2;
   odl_class *c;
   char *full_classname;
+  odl_filenamelist *fl = NULL;
 
   g_return_val_if_fail (config, FALSE);
-
   PyEval_AcquireLock ();
   PyThreadState_Swap (py_threadstate);
-
   /* get directory where code files are stored */
   dirname =
     (char *) get_global_option_str (config, "methoddir", DEFAULT_METHOD_DIR);
@@ -273,57 +272,29 @@
     {
       return (FALSE);
     }
-  dirname = g_strdup (dirname);
-  while (dirname[strlen (dirname) - 1] == '\\' ||
-         dirname[strlen (dirname) - 1] == '/')
-    dirname[strlen (dirname) - 1] = '\0';
-  message ("method dir name: '%s'", dirname);
-
-  dir = opendir (dirname);
-  if (!dir)
-    {
-      errormsg ("Could not open directory '%s'", dirname);
-      g_free (dirname);
-      return (FALSE);
-    }
-  /* load all .py files into embedded python
-     note that this executes the file and any
-     non function code will be executed.
-   */
-  while ((entry = readdir (dir)) != NULL)
-    {
-      if (!strcmp (&entry->d_name[strlen (entry->d_name) - 3], ".py"))
+  /* get a list of all files with .py extension */
+  fl = odl_get_files_from_dir (fl, dirname, "py");
+  filename_list = (GList *) fl;
+  while (filename_list)
+    {
+      /* TODO make sure this matches a gcd function */
+      fp = fopen (filename_list->data, "r");
+      if (!fp)
         {
-          name = g_strdup_printf ("%s/%s", dirname, entry->d_name);
-          if (!name)
-            {
-              errormsg ("Out of memory");
-              closedir (dir);
-              g_free (dirname);
-              return (FALSE);
-            }
-          /* make sure it can be opened */
-          /* TODO make sure this matches a gcd function */
-          fp = fopen (name, "r");
-          if (!name)
-            {
-              errormsg ("Could not open file '%s'", name);
-              closedir (dir);
-              g_free (dirname);
-              g_free (name);    /* TODO continue on with other names */
-              return (FALSE);
-            }
-          /* run file 'name' */
-          message ("Loading file %s", name);
-          PyRun_SimpleFile (fp, name);
-          /* done this file */
+          errormsg ("Could not open file '%s'", filename_list->data);          
+        }
+      else
+        {
+          message ("Loading file %s", filename_list->data);
+          PyRun_SimpleFile (fp, filename_list->data);
           fclose (fp);
-          g_free (name);
         }
+      g_free (filename_list->data);
+      filename_list = g_list_next (filename_list);
     }
-  closedir (dir);
-  g_free (dirname);
+  g_list_free( (GList *) fl );
   /* done loading, now register */
+  message("Now registering methods from gcds."); 
   lst = l = odl_tree_list_classes (all_classes);
   while (l)
     {
@@ -343,14 +314,13 @@
             alloc_provider_data (full_classname, NULL, odl_field_get_name (f),
                                  NULL);
           provider_list = g_list_append (provider_list, current_provider);
-
           buf = g_strdup_printf
             ("method_system.register_method( \"%s_%s\" , %s_%s )",
              full_classname, odl_field_get_name (f),
              full_classname, odl_field_get_name (f));
           g_strdown (buf);
-          /* message ("Attempt to register method: %s_%s\n", full_classname,
-                   odl_field_get_name (f)); */
+          message ("Registering method: %s_%s, from file: %s", full_classname,
+                   odl_field_get_name (f), odl_class_get_gcd_filename(c) );
           PyRun_SimpleString (buf);
           g_free (buf);
           current_provider = NULL;
@@ -360,10 +330,8 @@
       l = g_list_next (l);
     }
   odl_namelist_free (l);
-
   PyThreadState_Swap (NULL);
   PyEval_ReleaseLock ();
-
   return (TRUE);
 }
 
@@ -420,10 +388,12 @@
   list = provider_list;
   while (list)
     {
+      /*
       g_message ("classname: %s = %s", ((provider_t *) list->data)->classname,
                  obj->classname);
       g_message ("fieldname: %s = %s",
                  ((provider_t *) list->data)->methodname, methodname);
+      */
       if (!g_strcasecmp
           (((provider_t *) list->data)->classname,
            g_strdelimit (obj->classname, ":", '_'))
@@ -511,7 +481,7 @@
 load_python_binding (configuration config)
 {
   gpointer gsym;
-  gchar *option_string;
+  const gchar *option_string;
   CORBA_to_Python_func = NULL;
 
   g_assert (config);
@@ -526,8 +496,7 @@
   orbit_python_library = g_module_open (option_string, G_MODULE_BIND_LAZY);
   if (!orbit_python_library)
     {
-      errormsg ("Could not load ORBit-Python module at: ");
-      errormsg (option_string);
+      errormsg ("Could not load ORBit-Python module at: %s", option_string);
       return (ERR_NO_ORBIT_PYTHON);
     }
   g_module_symbol (orbit_python_library, "CORBA_Object_to_PyObject", &gsym);
Index: gnue/gnue-config/README
diff -u gnue/gnue-config/README:1.6 gnue/gnue-config/README:1.7
--- gnue/gnue-config/README:1.6 Sun Sep  2 10:21:36 2001
+++ gnue/gnue-config/README     Sun Sep 23 10:18:11 2001
@@ -6,7 +6,7 @@
 #
 # This file originally written by Neil Tiffin (address@hidden).
 #
-# $Id: README,v 1.6 2001/09/02 14:21:36 ntiffin Exp $
+# $Id: README,v 1.7 2001/09/23 14:18:11 ntiffin Exp $
 #
 
 gnue-config Directory
@@ -14,7 +14,9 @@
 This directory contains the various files used to configure GNUe to
 perform as enterprise software.
 
-See note below for converting .geas files to .sql.
+See note below for converting .geas files to .sql.  All .py files
+are loaded as class methods (business rules).  If you don't wish
+this to happen don't put .py files in this directory tree.
 
 Directory Structure
 ===================
@@ -42,6 +44,8 @@
 
                    
 Each module-name folder contains the following folders:
+    methods - directory for method files.  All .py files are loaded
+               into GEAS if python methods are selected.
     reports - contains report definitions (.grd)
     forms - contains form definitions (.gfd)
     classes - contains class (business object) definitions (.gcd)
Index: gnue/gnue-config/test/gcd_pass_test.gcd
diff -u gnue/gnue-config/test/gcd_pass_test.gcd:1.2 
gnue/gnue-config/test/gcd_pass_test.gcd:1.3
--- gnue/gnue-config/test/gcd_pass_test.gcd:1.2 Sat Sep 22 19:16:25 2001
+++ gnue/gnue-config/test/gcd_pass_test.gcd     Sun Sep 23 10:18:12 2001
@@ -23,7 +23,7 @@
 #
 # This file originally written by Neil Tiffin (address@hidden).
 #
-# $Revision: 1.2 $ $Date: 2001/09/22 23:16:25 $ $Author: ntiffin $
+# $Revision: 1.3 $ $Date: 2001/09/23 14:18:12 $ $Author: ntiffin $
 #
 
 module mod1
@@ -60,7 +60,8 @@
       
       list list_fld : mod1::c(code) = this.char_8_fld;
 
-      text       helloworld(char a, char b);
+      # concatenate a and b together
+      text       cat_a_b(char a, char b);
 
     };
 
@@ -73,7 +74,7 @@
   class class3
     {
      mod1::class1 *   ref_fld;
-     mod1::class2 []  list_fld;
+     mod1::c []       list_fld;
    };
 };
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]