Ejemplo n.º 1
0
    def __init__(self, objects):
	AutoGen.__init__(self, objects)
	for obj in self.objects.values():
	    obj.__class__ = XMLObject
	    for property in obj.properties:
		property.__class__ = XMLProperty
	    for choice in obj.choices:
		choice.__class__ = XMLChoice
		for property in choice.properties:
		    property.__class__ = XMLProperty
Ejemplo n.º 2
0
    def reset(self, spaces = XML_SPACES):
	AutoGen.reset(self, spaces)
Ejemplo n.º 3
0
def main(argv=None):
    options = {}
    objects = None

    optionsUsage = {'a': ('generate all database information (-p -s -x)', 
                          False),
                    'b:': ('base directory', False, 'dir'),
                    'd:': ('versions directory', False, 'dir'),
                    'p': ('generate python domain classes', False),
                    's': ('generate sql schema and persistence classes', False),
                    'x': ('generate xml schema and persistence classes', False),
                    'v:': ('vistrail version tag', True, 'version'),
                    'm': ('make all directories', False),
                    'n': ('do not change current version', False)}

    optStr = ''.join(optionsUsage.keys())
    optKeys = optStr.replace(':','')
    for idx in xrange(len(optKeys)):
        options[optKeys[idx]] = False

    try:
	(optlist, args) = getopt.getopt(sys.argv[1:], optStr)
	for opt in optlist:
            if opt[1] is not None and opt[1] != '':
                options[opt[0][1:]] = opt[1]
            else:
                options[opt[0][1:]] = True
    except getopt.GetoptError:
        usage(optionsUsage)
        return

    if options['b']:
        baseDir = options['b']
    else:
	baseDir = BASE_DIR
    baseDirs = dirStructure(baseDir)

    if not options['v']:
        usage(optionsUsage)
        return

    version = options['v']
    versionName = 'v' + version.replace('.', '_')
    if options['d']:
        versionsDir = options['d']
    else:
        versionsDir = os.path.join(baseDir, 'versions')
    versionDir = os.path.join(versionsDir, versionName)
    versionDirs = dirStructure(versionDir)

    print baseDirs
    print versionDirs

    if options['m']:
        makeAllDirs(baseDirs)
        makeAllDirs(versionDirs)

    # copy specs to version
    for file in os.listdir(baseDirs['specs']):
        if file.endswith('.xml'):
            print 'copying %s' % file
            filename = os.path.join(baseDirs['specs'], file)
            toFile = os.path.join(versionDirs['specs'], file)
            shutil.copyfile(filename, toFile)

    if options['p'] or options['a']:
	# generate python domain objects
	print "generating python domain objects..."
	if objects is None:
	    parser = AutoGenParser()
	    objects = parser.parse(baseDirs['specs'])
	autoGen = AutoGen(objects)
	domainFile = os.path.join(versionDirs['domain'], 'auto_gen.py')
	f = open(domainFile, 'w')
        f.write(COPYRIGHT_NOTICE)
	f.write(autoGen.generatePythonCode())
	f.close()

        if not options['n']:
            domainFile = os.path.join(baseDirs['domain'], '__init__.py')
            f = open(domainFile, 'w')
            f.write(COPYRIGHT_NOTICE)
            f.write('from db.versions.%s.domain import *\n' % \
                        versionName)
            f.close()

    if options['x'] or options['a']:
	# generate xml schema and dao objects
	print "generating xml schema and dao objects..."
	if objects is None:
	    parser = AutoGenParser()
	    objects = parser.parse(baseDirs['specs'])
	xmlAutoGen = XMLAutoGen(objects)
	
# 	schemaFile = os.path.join(versionDirs['xmlSchema'], 'workflow.xsd')
# 	f = open(schemaFile, 'w')
#       f.write(COPYRIGHT_NOTICE)
# 	f.write(xmlAutoGen.generateSchema('workflow'))
# 	f.close()

	schemaFile = os.path.join(versionDirs['xmlSchema'], 'vistrail.xsd')
	f = open(schemaFile, 'w')
        f.write(COPYRIGHT_NOTICE)
	f.write(xmlAutoGen.generateSchema('vistrail'))
	f.close()

# 	schemaFile = os.path.join(versionDirs['xmlSchema'], 'log.xsd')
# 	f = open(schemaFile, 'w')
#       f.write(COPYRIGHT_NOTICE)
# 	f.write(xmlAutoGen.generateSchema('log'))
# 	f.close()

	daoFile = os.path.join(versionDirs['xmlPersistence'], 'auto_gen.py')
	f = open(daoFile, 'w')
        f.write(COPYRIGHT_NOTICE)
	f.write(xmlAutoGen.generateDAO(versionName))
	f.write(xmlAutoGen.generateDAOList())
	f.close()

#         if not options['n']:
#             domainFile = os.path.join(baseDirs['xmlPersistence'], 'auto_gen.py')
#             f = open(domainFile, 'w')
#             f.write(COPYRIGHT_NOTICE)
#             f.write('from db.versions.%s.persistence.xml.auto_gen import *\n' % \
#                         versionName)
#             f.close()


    if options['s'] or options['a']:
	# generate sql schema and dao objects
	print "generating sql schema and dao objects..."
	if objects is None:
	    parser = AutoGenParser()
	    objects = parser.parse(baseDirs['specs'])
	sqlAutoGen = SQLAutoGen(objects)
	
	schemaFile = os.path.join(versionDirs['sqlSchema'], 'vistrails.sql')
	f = open(schemaFile, 'w')
        f.write(COPYRIGHT_NOTICE)
	f.write(sqlAutoGen.generateSchema())
	f.close()
	
	schemaFile = os.path.join(versionDirs['sqlSchema'],'vistrails_drop.sql')
	f = open(schemaFile, 'w')
        f.write(COPYRIGHT_NOTICE)
	f.write(sqlAutoGen.generateDeleteSchema())
	f.close()

 	daoFile = os.path.join(versionDirs['sqlPersistence'], 'auto_gen.py')
 	f = open(daoFile, 'w')
        f.write(COPYRIGHT_NOTICE)
 	f.write(sqlAutoGen.generateDAO(versionName))
	f.write(sqlAutoGen.generateDAOList())
	f.close()

#         if not options['n']:
#             domainFile = os.path.join(baseDirs['sqlPersistence'], 'auto_gen.py')
#             f = open(domainFile, 'w')
#             f.write(COPYRIGHT_NOTICE)
#             f.write('from db.versions.%s.persistence.sql.auto_gen import *\n' % \
#                         versionName)
#             f.close()

    if not options['n']:
        domainFile = os.path.join(baseDirs['persistence'], '__init__.py')
        f = open(domainFile, 'w')
        f.write(COPYRIGHT_NOTICE)
        f.write('from db.versions.%s.persistence import *\n' % \
                    versionName)
        f.close()