Sanjay schrieb:
> I am stuck on how to write a database initialization script using "tg-
> admin shell" like the above. This is a common requirement and I was
> using it in all my TG projects.

IMHO, it would be better and more user-friendly to implement such 
database initialisation tasks as functions in the command.py module. 
Here's an example from EggBasket (slightly simplified):


def init_database(configfile):
     """Create bootstrap data in database set in given config file."""
     turbogears.update_config(configfile=configfile,
         modulename="<yourpackage>.config")
     from turbogears import database
     model = get_model()
     session = database.session
     database.bind_meta_data()
     database.metadata.create_all(database.get_engine())

     try:
         # test here whether data is already there
     except model.InvalidRequestError:
         # create you model objects here
         session.flush()
     else:
         print "Database already initialized."

def main():
     parser = optparse.OptionParser()
     parser.add_option("-i", "--init", action="store_true",
         help="Init database only, don't start server.",
         dest="init", default=False)
     (options, args) = parser.parse_args()

     configfile = find_config(args)

     if options.init:
         init_database(configfile)
     else:
         start_server(configfile)


HTH, Chris

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to