Update of /cvsroot/pymerase/pymerase/output
In directory sc8-pr-cvs1:/tmp/cvs-serv8877
Added Files:
CreateReport.py
Log Message:
Generates a report about classes, attributes, and associations.
--- NEW FILE: CreateReport.py ---
###########################################################################
# #
# C O P Y R I G H T N O T I C E #
# Copyright (c) 2002 by: #
# * California Institute of Technology #
# #
# All Rights Reserved. #
# #
# Permission is hereby granted, free of charge, to any person #
# obtaining a copy of this software and associated documentation files #
# (the "Software"), to deal in the Software without restriction, #
# including without limitation the rights to use, copy, modify, merge, #
# publish, distribute, sublicense, and/or sell copies of the Software, #
# and to permit persons to whom the Software is furnished to do so, #
# subject to the following conditions: #
# #
# The above copyright notice and this permission notice shall be #
# included in all copies or substantial portions of the Software. #
# #
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, #
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF #
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND #
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS #
# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN #
# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN #
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE #
# SOFTWARE. #
###########################################################################
#
# Authors: Brandon King
# Last Modified: $Date: 2002/12/11 17:47:32 $
#
"""Creates a report of each Class/Table"""
#Imported System Packages.
import os
import string
from ClassMembers import getAllAttributes
from ClassMembers import getAllAssociations
############################
# Globals
TRANSLATOR_NAME='CreateReport'
############################
# Writer components
def write(destination, tables):
"""
Create Report in destination dirctory.
"""
text = []
#Iterate through the tables/classes and process the data
for tbl in tables:
#Set Web Page Title
text.append("CLASS: %s" % (tbl.getName(TRANSLATOR_NAME)))
#Process each attribute in a given table (class)
for attribute in getAllAttributes(tables, tbl, TRANSLATOR_NAME):
#get attribute type
type = attribute.getType().getSQLType()
text.append(" ATTRIBUTE:")
text.append(" Name = %s" % (attribute.getName(TRANSLATOR_NAME)))
text.append(" Type = %s" % (type))
text.append(" isRequired = %s" % (attribute.isRequired()))
text.append(" isUnique = %s" % (attribute.isUnique()))
text.append(" isIndexed = %s" % (attribute.isIndexed()))
text.append(" isPrimaryKey = %s" % (attribute.isPrimaryKey()))
for assocEnd in tbl.getAssociationEnds().values():
text.append(" ASSOC END:")
text.append(" Name = %s" % (assocEnd.getAttributeName(TRANSLATOR_NAME)))
text.append(" Multiplicity = %s" % (assocEnd.getMultiplicity()))
text.append(" isNavigable = %s" % (assocEnd.isNavigable()))
text.append(" OppositeEnd = %s.%s" % \
(assocEnd.getOppositeEnd().getClassName(TRANSLATOR_NAME),
assocEnd.getOppositeEnd().getAttributeName(TRANSLATOR_NAME)))
text.append("")
text = string.join(text, '\n')
f = open(destination, 'w')
f.write(text)
f.close()
print os.linesep \
+ "Report Generation Complete... Good Bye." \
+ os.linesep
|