CodeGenerator.py :  » Web-Frameworks » Webware » Webware-1.0.2 » MiddleKit » Design » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Web Frameworks » Webware 
Webware » Webware 1.0.2 » MiddleKit » Design » CodeGenerator.py
"""CodeGenerator.py


This module defines the basic machinery for a code generator, but cannot be used directly.
Instead, use concrete generators like MySQLPythonGeneratory and MySQLSQLGenerator.

Terminology: "the standard classes" = ModelObject, Klasses, Klass and Attr

Modules that wish to do code generation must:
  * Define a class that inherits CodeGenerator (even if its implementation is 'pass').
  * Define various mix-in classes such as ModelObject, Klasses, Klass and Attr for
    the purpose of defining methods to aid in code generation.

What happens: When the generator is initialized, mixes in the methods of various classes
found in the module with the ones found in the model (typically these come from MiddleKit.Core).

TO DO
-----
Make sure all three goals are met:
  * User-defined classes can be used in place of the standard classes
  * Inheritance of generators is supported
  * Class inheritance (like Klasses inheriting ModelObject works)

"""


import os, sys
from time import asctime,localtime,time

from MiscUtils import AbstractError
from MiscUtils.Configurable import Configurable
from MiddleKit.Core.ModelUser import ModelUser

try: # for Python < 2.3
  True, False
except NameError:
  True, False = 1, 0


class CodeGenerator(ModelUser):

  def name(self):
    """Return the name of the generator for informational purposes.

    The name the is the class name.

    """
    return self.__class__.__name__

  def requireDir(self, dirname):
    if not os.path.exists(dirname):
      os.mkdir(dirname)
    assert os.path.isdir(dirname)

  def writeInfoFile(self, filename):
    file = open(filename, 'w')
    self.writeInfoItems(file)
    file.close()

  def writeInfoItems(self, file):
    wr = self.writeInfoItem
    wr(file, 'Date', asctime(localtime(time())))
    wr(file, 'Python ver', sys.version)
    wr(file, 'Op Sys', os.name)
    wr(file, 'Platform', sys.platform)
    wr(file, 'Cur dir', os.getcwd())

  def writeInfoItem(self, out, key, value):
    key = key.ljust(10)
    out.write('%s = %s\n' % (key, value))

  def generate(self, outdir):
    raise AbstractError, self.__class__
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.