commit-gnue
[Top][All Lists]
Advanced

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

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


From: johannes
Subject: r5175 - in trunk/gnue-common/src/schema/scripter: . processors
Date: Fri, 27 Feb 2004 03:59:08 -0600 (CST)

Author: johannes
Date: 2004-02-27 03:59:07 -0600 (Fri, 27 Feb 2004)
New Revision: 5175

Modified:
   trunk/gnue-common/src/schema/scripter/Definition.py
   trunk/gnue-common/src/schema/scripter/Scripter.py
   trunk/gnue-common/src/schema/scripter/processors/Base.py
   trunk/gnue-common/src/schema/scripter/processors/HTML.py
   trunk/gnue-common/src/schema/scripter/processors/SQL.py
Log:
gnue-schema now uses unicode internally and encoding takes place only when
writing stuff to destination files. Fixed translation stuff.


Modified: trunk/gnue-common/src/schema/scripter/Definition.py
===================================================================
--- trunk/gnue-common/src/schema/scripter/Definition.py 2004-02-27 09:27:17 UTC 
(rev 5174)
+++ trunk/gnue-common/src/schema/scripter/Definition.py 2004-02-27 09:59:07 UTC 
(rev 5175)
@@ -67,11 +67,6 @@
     order: prologue, header, body, footer, epilogue
     """
     for line in self.merge ():
-      # TODO: since GTypecast only produces UTF-8 strings and not unicode,
-      # we have to create a unicode string before encoding as requested
-      if isinstance (line, StringType):
-        line = unicode (line, 'utf-8')
-
       destination.write (line.encode (encoding) + "\n")
 
 

Modified: trunk/gnue-common/src/schema/scripter/Scripter.py
===================================================================
--- trunk/gnue-common/src/schema/scripter/Scripter.py   2004-02-27 09:27:17 UTC 
(rev 5174)
+++ trunk/gnue-common/src/schema/scripter/Scripter.py   2004-02-27 09:59:07 UTC 
(rev 5175)
@@ -52,33 +52,33 @@
       [ 'ignore_data','D','no-data', 0, None, None,
         _("Do not generate data insertion code.  * NOT IMPLEMENTED")],
       [ 'encoding', 'e', 'encoding', True, 'UTF-8', 'encoding',
-        _("The generated SQL script will be encoded using <encoding>. ") + \
-        _("Default encoding is UTF-8")],
+        _("The generated SQL script will be encoded using <encoding>. " + \
+          "Default encoding is UTF-8")],
       [ 'upgrade_schema','u','upgrade-schema', 0, None, None,
-        _("Generate code to upgrade an older version of a schema to ") + \
-        _("the recent version. You must specify a previous schema with ") + \
-        _("on the command line.  * NOT IMPLEMENTED")],
+        _("Generate code to upgrade an older version of a schema to "    + \
+          "the recent version. You must specify a previous schema with " + \
+          "on the command line.  * NOT IMPLEMENTED")],
       [ 'upgrade_data','U','upgrade-data', 0, None, None,
-        _("Generate code to upgrade an older version of schema data to ") + \
-        _("the recent version. You must specify a previous schema with ") + \
-        _("on the command line.  * NOT IMPLEMENTED")],
+        _("Generate code to upgrade an older version of schema data to " + \
+          "the recent version. You must specify a previous schema with " + \
+          "on the command line.  * NOT IMPLEMENTED")],
       [ 'list_vendors','l','list-vendors', 0, None, None,
         _("List all supported vendors.")],
       [ 'output','o','output', 1, None, 'dest',
-        _("The destination for the created schemas. This can be in several ")+ 
\
-        _("formats. If <dest> is a file name, then output is written to ")   + 
\
-        _("this file. If <dest> is a directory, then <dest>/<Vendor>.sql ")  + 
\
-        _("is created. The default is to create <Vendor>.sql in the ")       + 
\
-        _("current directory. NOTE: the first form (<dest> as a filename) ") + 
\
-        _("is not supported for --vendors all.") ],
+        _("The destination for the created schemas. This can be in several "+ \
+          "formats. If <dest> is a file name, then output is written to "   + \
+          "this file. If <dest> is a directory, then <dest>/<Vendor>.sql "  + \
+          "is created. The default is to create <Vendor>.sql in the "       + \
+          "current directory. NOTE: the first form (<dest> as a filename) " + \
+          "is not supported for --vendors all.") ],
       [ 'vendor','v','vendor', 1, 'all', 'vendor',
-        _("The vendor to create a script for. If <vendor> is 'all', then ") + \
-        _("scripts for all supported vendors will be created. <vendor> ")   + \
-        _("can also be a comma-separated list.")],
+        _("The vendor to create a script for. If <vendor> is 'all', then " + \
+          "scripts for all supported vendors will be created. <vendor> "   + \
+          "can also be a comma-separated list.")],
       ]
 
-  SUMMARY = _("GNUe Schema Scripter creates SQL files based on GNUe ") + \
-            _("Schema Definitions.")
+  SUMMARY = _("GNUe Schema Scripter creates SQL files based on GNUe " + \
+              "Schema Definitions.")
 
   _PROC_PATH = "gnue.common.schema.scripter.processors.%s"
 
@@ -125,14 +125,14 @@
 
     # we need at least one thing to do :)
     if self.OPTIONS ["ignore_schema"] and self.OPTIONS ["ignore_data"]:
-      self.handleStartupError (_("--no-schema and --no-data cannot be used ") +
-        _("together. What to export?"))
+      self.handleStartupError (_("--no-schema and --no-data cannot be used " +
+                                 "together. What to export?"))
 
     # check for unsupported options
     if self.OPTIONS ["drop_tables"] or self.OPTIONS ["upgrade_schema"] or \
        self.OPTIONS ["upgrade_data"]:
-      self.handleStartupError (_("--drop-tables, --upgrade-schema and ") + 
-                               _("--upgrade-data\n are not implemented yet."))
+      self.handleStartupError (_("--drop-tables, --upgrade-schema and " + 
+                                 "--upgrade-data\n are not implemented yet."))
 
 
     # do we have an accessible input file
@@ -156,8 +156,8 @@
     if len (self.__vendors) > 1 and self.__output is not None:
       if not os.path.isdir (self.__output):
         self.handleStartupError ( \
-          _("If multiply vendors are specified --output must be a ") +
-          _("directory or\n left empty."))
+          _("If multiply vendors are specified --output must be a " + \
+            "directory or\n left empty."))
 
 
   # ---------------------------------------------------------------------------

Modified: trunk/gnue-common/src/schema/scripter/processors/Base.py
===================================================================
--- trunk/gnue-common/src/schema/scripter/processors/Base.py    2004-02-27 
09:27:17 UTC (rev 5174)
+++ trunk/gnue-common/src/schema/scripter/processors/Base.py    2004-02-27 
09:59:07 UTC (rev 5175)
@@ -134,13 +134,10 @@
     encoding. If text is a sequence it will be joined with newlines first.
     """
     if isinstance (text, ListType):
-      astr = join (text, "\n") + "\n"
+      astr = join (text, "\n") + u"\n"
     else:
       astr = text
 
-    if isinstance (astr, StringType):
-      astr = unicode (astr, 'utf-8')
-
     self.destination.write (astr.encode (self.encoding))
 
   
@@ -373,8 +370,8 @@
     body   = []
     result = []
     
-    ruler = "=" * (self.MAX_LINE_LENGTH - len (self.COMMENT_BEGIN) - \
-                                          len (self.COMMENT_END))
+    ruler = u"=" * (self.MAX_LINE_LENGTH - len (self.COMMENT_BEGIN) - \
+                                           len (self.COMMENT_END))
     body.append (ruler)
     if isinstance (text, ListType):
       body.extend (text)
@@ -414,16 +411,16 @@
     This method is called by the scripter on start of a dump. Use it to do 
     'per-generation' actions, e.g. set encoding 
     """
-    self._writeText ("\n")
-    self._writeText (self.comment ([ \
-      _("This file was generated by gnue-schema"),
-      _("from %s on %s") % (self.source, strftime ('%c')),
-      "",
-      _("Do NOT edit manually!")]))
-    self._writeText ("\n")
+    text = _("This file was generated by gnue-schema\nfrom %s on %s.") % \
+            (self.source, strftime ("%c"))
 
+    self._writeText (u"\n")
+    self._writeText (self.comment (text.splitlines () + \
+                     ["", _("Do NOT edit manually!")]))
+    self._writeText (u"\n")
 
 
+
   # ---------------------------------------------------------------------------
   # Virtual: called on end of a schema dump
   # ---------------------------------------------------------------------------
@@ -467,8 +464,8 @@
     """
     Depreciated - use datatype 'datetime' instead
     """
-    print _("WARNING: datatype 'timestamp' is depreciated. ") + \
-          _("Use datetime instead.")
+    print _("WARNING: datatype 'timestamp' is depreciated. " + \
+            "Use datetime instead.")
     return self.datetime (gsField)
 
 
@@ -480,8 +477,8 @@
     """
     Depreciated - use datatype 'string' without a length attribute instead
     """
-    print _("WARNING: datatype 'text' is depreciated. ") + \
-          _("Use 'string' without length instead.")
+    print _("WARNING: datatype 'text' is depreciated. " + \
+            "Use 'string' without length instead.")
     gsField.type = "string"
     return self.string (gsField)
 

Modified: trunk/gnue-common/src/schema/scripter/processors/HTML.py
===================================================================
--- trunk/gnue-common/src/schema/scripter/processors/HTML.py    2004-02-27 
09:27:17 UTC (rev 5174)
+++ trunk/gnue-common/src/schema/scripter/processors/HTML.py    2004-02-27 
09:59:07 UTC (rev 5175)
@@ -62,7 +62,7 @@
     hdr = tableDef.header
 
     pro.append ("")
-    pro.extend (self.comment (_("Table definition '%s'") % tableDef.name))
+    pro.extend (self.comment ("Table definition '%s'" % tableDef.name))
 
     pro.append ('<H2 class="tabledef"><A name="%s">%s</A></H2>' % \
         (tableDef.name, _("Table definition of '%s'") % tableDef.name))
@@ -96,7 +96,7 @@
     epi = tableDef.epilogue
 
     epi.append ("")
-    epi.extend (self.comment (_("Primary key '%s'") % pkDef.name))
+    epi.extend (self.comment ("Primary key '%s'" % pkDef.name))
 
     epi.append ('<H3 class="primarykey">%s</H3>' % \
       _("Primary Key: %s") % pkDef.name)
@@ -120,7 +120,7 @@
     epi = tableDef.epilogue
 
     epi.append ("")
-    epi.extend (self.comment (_("Index '%s'") % indexDef.name))
+    epi.extend (self.comment ("Index '%s'" % indexDef.name))
     epi.append ('<H3 class="index">%s: %s</H3>' % (uniq, indexDef.name))
 
     epi.append ('<UL>')

Modified: trunk/gnue-common/src/schema/scripter/processors/SQL.py
===================================================================
--- trunk/gnue-common/src/schema/scripter/processors/SQL.py     2004-02-27 
09:27:17 UTC (rev 5174)
+++ trunk/gnue-common/src/schema/scripter/processors/SQL.py     2004-02-27 
09:59:07 UTC (rev 5175)
@@ -48,12 +48,12 @@
     """
     Populate a table definitions sequences.
     """
-    tableDef.prologue.append ("")
+    tableDef.prologue.append (u"")
     tableDef.prologue.extend (self.comment ("Create table '%s'" % \
-                              tableDef.name))
+                                            tableDef.name))
 
-    tableDef.body.append ("CREATE TABLE %s (" % tableDef.name)
-    tableDef.footer.append (")%s" % self.END_COMMAND)
+    tableDef.body.append (u"CREATE TABLE %s (" % tableDef.name)
+    tableDef.footer.append (u")%s" % self.END_COMMAND)
 
     BaseProcessor._processFields (self, tableDef)
 
@@ -90,10 +90,10 @@
     flist = join ([pkf.name for pkf in pkDef.fields], ", ")
 
     if len (tableDef.body):
-      tableDef.body [-1] += ","
+      tableDef.body [-1] += u","
 
-    tableDef.body.append ("  CONSTRAINT %s PRIMARY KEY (%s)" % \
-                            (pkDef.name, flist))
+    tableDef.body.append (u"  CONSTRAINT %s PRIMARY KEY (%s)" % \
+                              (pkDef.name, flist))
 
 
   # ---------------------------------------------------------------------------
@@ -119,22 +119,22 @@
     """
     This function translates an index definition object into SQL code.
     """
-    indexDef.prologue.append ("")
+    indexDef.prologue.append (u"")
     indexDef.prologue.extend (self.comment ("Create index '%s'" % \
                               indexDef.name))
 
     if indexDef.unique:
-      uniq = "UNIQUE "
+      uniq = u"UNIQUE "
     else:
       uniq = ""
 
-    indexDef.header.append ("CREATE %sINDEX %s ON %s" % \
+    indexDef.header.append (u"CREATE %sINDEX %s ON %s" % \
                             (uniq, indexDef.name, tableDef.name))
 
     indexDef.body.append ("  (%s)%s" % \
         (join ([fld.name for fld in indexDef.fields], ", "), self.END_COMMAND))
 
-    indexDef.epilogue.append ("")
+    indexDef.epilogue.append (u"")
 
 
 
@@ -159,7 +159,7 @@
     This function iterates over all rows of the data definition and calls
     _processDataRow () on them.
     """
-    dataDef.prologue.append ("")
+    dataDef.prologue.append (u"")
     dataDef.prologue.extend (self.comment ("Data for '%s'" % dataDef.name))
 
     for row in dataDef.rows:
@@ -182,7 +182,7 @@
 
     for item in row.values:
       if item is None:
-        values.append ("NULL")
+        values.append (u"NULL")
       else:
         res = (self._dts_type (item))
 
@@ -198,14 +198,9 @@
     else:
       cols = ""
 
-    # values list usually has unicode items, so we make sure to get utf-8
-    vals = join (values, ", ")
-    if isinstance (vals, UnicodeType):
-      vals = vals.encode ('utf-8')
-
     # and create an insert statement
-    dataDef.body.append ("INSERT INTO %s%s VALUES (%s)%s" % \
-       (dataDef.name, cols, vals, self.END_COMMAND))
+    dataDef.body.append (u"INSERT INTO %s%s VALUES (%s)%s" % \
+       (dataDef.name, cols, join (values, ", "), self.END_COMMAND))
 
 
 





reply via email to

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