commit-gnue
[Top][All Lists]
Advanced

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

r5104 - in trunk/gnue-common/src/schema/scripter: . processors


From: johannes
Subject: r5104 - in trunk/gnue-common/src/schema/scripter: . processors
Date: Thu, 12 Feb 2004 09:42:21 -0600 (CST)

Author: johannes
Date: 2004-02-12 09:42:20 -0600 (Thu, 12 Feb 2004)
New Revision: 5104

Modified:
   trunk/gnue-common/src/schema/scripter/Scripter.py
   trunk/gnue-common/src/schema/scripter/processors/Base.py
   trunk/gnue-common/src/schema/scripter/processors/SQL.py
   trunk/gnue-common/src/schema/scripter/processors/postgresql.py
Log:
Better comments, added a reference to the originating gsd-file at the beginning
of SQL files and multirow-values are now translated properly.


Modified: trunk/gnue-common/src/schema/scripter/Scripter.py
===================================================================
--- trunk/gnue-common/src/schema/scripter/Scripter.py   2004-02-12 15:34:33 UTC 
(rev 5103)
+++ trunk/gnue-common/src/schema/scripter/Scripter.py   2004-02-12 15:42:20 UTC 
(rev 5104)
@@ -197,6 +197,16 @@
     self.processor = dyn_import (aModule).Processor (self.destination)
 
     print _("Writing schema to %s ...") % filename
+
+    for line in self.processor.comment ( \
+      _("\nThis file was generated by %s\n") % self.NAME +
+      _("from %s\n\n") % self.ARGUMENTS [0] +
+      _("Do not edit manually!\n")):
+      self.destination.write (line.encode ('utf-8') + "\n")
+    self.destination.write ("\n")
+
+    self.processor.startDump ()
+
     self.schema.walk (self.__iterate_objects)
 
     # and finally close the output file
@@ -275,7 +285,7 @@
     data = DataDefinition (sObject.tablename)
 
     self.destination.write ("\n")
-    for line in self.processor.comment (_("\nData for %s\n") % data.name):
+    for line in self.processor.comment (_("Data for %s") % data.name):
       self.destination.write (line.encode ('utf-8') + "\n")
 
     sObject.walk (self.__data_rows, dataDef = data)
@@ -298,10 +308,20 @@
     elif sObject._type == "GSValue":
       if hasattr (sObject, "field"):
         dataDef.columns.append (sObject.field)
-      dataDef.values.append (sObject._children [0].getContent ())
 
+      if len (sObject._children) > 1:
+        # FIXME: indentation ???
+        value = ""
+        for line in sObject._children:
+          value += "%s\n" % line.getContent ()
+      else:
+        value = sObject._children [0].getContent ()
 
+      dataDef.values.append (value)
 
+
+
+
   # ---------------------------------------------------------------------------
   # Main program
   # ---------------------------------------------------------------------------

Modified: trunk/gnue-common/src/schema/scripter/processors/Base.py
===================================================================
--- trunk/gnue-common/src/schema/scripter/processors/Base.py    2004-02-12 
15:34:33 UTC (rev 5103)
+++ trunk/gnue-common/src/schema/scripter/processors/Base.py    2004-02-12 
15:42:20 UTC (rev 5104)
@@ -35,6 +35,7 @@
   """
 
   MAX_NAME_LENGTH    = 30
+  MAX_LINE_LENGTH    = 78
 
   COMMENT_BEGIN      = "-- "
   COMMENT_END        = ""
@@ -128,16 +129,23 @@
     Create a sequence of 'commented' lines given in the sequence 'text'. Use
     the COMMENT_* constants to control this functions behaviour.
     """
+    body   = []
     result = []
     
+    ruler = "=" * (self.MAX_LINE_LENGTH - len (self.COMMENT_BEGIN) - \
+                                          len (self.COMMENT_END))
+    body.append (ruler)
+    body.extend (text.split ("\n"))
+    body.append (ruler)
+
     if self.COMMENT_SINGLELINE:
-      for line in text.split ("\n"):
+      for line in body:
         result.append ("%s%s%s" % (self.COMMENT_BEGIN, line, self.COMMENT_END))
 
     else:
       space = " " * len (self.COMMENT_BEGIN)
       first = True
-      for line in text.split ("\n"):
+      for line in body:
         if first:
           line = "%s%s" % (self.COMMENT_BEGIN, line)
           first = False
@@ -188,7 +196,7 @@
       self._processConstraints (tableDef)
 
     # Now dump the table definition
-    for line in self.comment (_("\nCreate table '%s'\n") % tableDef.name):
+    for line in self.comment (_("Create table '%s'") % tableDef.name):
       self._dumpText (line + "\n")
 
     # Create the prologue
@@ -228,6 +236,16 @@
 
 
   # ---------------------------------------------------------------------------
+  # Virtual: called on start of a dump
+  # ---------------------------------------------------------------------------
+  def startDump (self):
+    """
+    This method is called by the scripter on start of a dump. Use it to do 
+    'per-generation' actions, e.g. set encoding 
+    """
+    pass
+
+  # ---------------------------------------------------------------------------
   # Virtual: called on start of a schema dump
   # ---------------------------------------------------------------------------
   def startSchema (self):

Modified: trunk/gnue-common/src/schema/scripter/processors/SQL.py
===================================================================
--- trunk/gnue-common/src/schema/scripter/processors/SQL.py     2004-02-12 
15:34:33 UTC (rev 5103)
+++ trunk/gnue-common/src/schema/scripter/processors/SQL.py     2004-02-12 
15:42:20 UTC (rev 5104)
@@ -18,7 +18,7 @@
 #
 # Copyright 2001-2004 Free Software Foundation
 #
-# $Id: $
+# $Id$
 #
 
 from gnue.common.schema.scripter.processors.Base import BaseProcessor
@@ -62,7 +62,7 @@
         uni = "UNIQUE "
 
       epi.append ("")
-      epi.extend (self.comment (_("\nCreate index '%s'\n") % index.name))
+      epi.extend (self.comment (_("Create index '%s'") % index.name))
       epi.append ("CREATE %sINDEX %s ON %s" % (uni, index.name, tableDef.name))
       epi.append (" (%s);" % join (index.fields, ", "))
 

Modified: trunk/gnue-common/src/schema/scripter/processors/postgresql.py
===================================================================
--- trunk/gnue-common/src/schema/scripter/processors/postgresql.py      
2004-02-12 15:34:33 UTC (rev 5103)
+++ trunk/gnue-common/src/schema/scripter/processors/postgresql.py      
2004-02-12 15:42:20 UTC (rev 5104)
@@ -101,14 +101,8 @@
     return "boolean"
 
   # ---------------------------------------------------------------------------
-  # Before starting schema data, set encoding to UTF-8
+  # Before starting a dump, set encoding to UTF-8
   # ---------------------------------------------------------------------------
-  def startSchema (self):
+  def startDump (self):
     self._dumpText ("\\encoding utf8\n")
 
-
-  # ---------------------------------------------------------------------------
-  # Before starting schema data, set encoding to UTF-8
-  # ---------------------------------------------------------------------------
-  def startData (self):
-    self._dumpText ("\\encoding utf8\n")





reply via email to

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