Generate ASP classes

I wrote a simple python script in order to generate some ASP (classic not dot net) classes:
Here it is as it:

# -*- coding: windows-1252 -*-
# @author: Raphaël Beck
# ex: >> python -n Country -f code -f name -f id > Country.asp

import os
import string
import re
from collections import defaultdict
from optparse import OptionParser
from datetime import datetime

name = None

baseStruc = """<%%
' -----------------------------------------------------------------------------
' @File   : /%(name)s.asp
' @Desc   : %(name)s
' @Create : %(date)s
' @Author : R.BECK
' -----------------------------------------------------------------------------
class %(name)s

    ' Constructor
    Private Sub Class_Initialize()
    end sub
    ' Destructor    
    'Private Sub Class_Terminate()    
    'end sub
    ' Setters

end class

field_format = "\tprivate %(private_field_name)s\n"

getter_format = """
    Public property get %(field_name)s    
        %(field_name)s = %(private_field_name)s
    End Property

setter_format = """
    Public property let %(field_name)s(p_%(field_name)s)  
        %(private_field_name)s = p_%(field_name)s
    End Property

init_format = """\t\t%(private_field_name)s = 0"""

if __name__ == "__main__":
    parser = OptionParser()
    parser.add_option("-f", "--fields",
                      action="append", dest="fields", default=[],
                      help="Class' fields")

    parser.add_option("-n", "--name", dest="name", 
                      help="Class' name")
    (options, args) = parser.parse_args()
    if not
        print "The name of the class is mandatory"
    name =
    private_fields = []
    getters = []
    setters = []
    init_fields = []

    for field_name in set(options.fields):
        field_dict = {"field_name": field_name, "private_field_name": "m_%s" % field_name}
        private_fields.append(field_format % field_dict)
        getters.append(getter_format % field_dict)
        setters.append(setter_format % field_dict)
        init_fields.append(init_format % field_dict)
    date =
    dateStr = "%s/%s/%s" % (, date.month, date.year)
    print baseStruc % {
        "name": name,
        "fields": "".join(private_fields),
        "getters": "\n".join(getters),
        "setters": "\n".join(setters),
        "date": dateStr,
        "init_fields": "\n".join(init_fields),


python -n Country -f code -f name -f id > Country.asp

You can use the code, modify it (I’ll be happy to see your modifications, in case I have forgotten something) and distribute it (it’ll be great if you link to this site :D).

This entry was posted in asp, python and tagged , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s