On 12/9/06, Adam Jones <[EMAIL PROTECTED]> wrote:
>
> Ok, maybe that is a little melodramatic, but there are a lot of cool
> things setuptools can do for you. One of the really nice ones is
> automatically generating platform-specific console scripts and
> installing them in the appropriate console directory. You have already
> seen this done, since it is how the tg-admin command is created. Here's
> a quick run-through on wrapping up your start-<projectname>.py file for
> easy access.
>
> First, copy your start-<projectname>.py file into the project itself in
> a new file named "commands.py". Then reformat it so it looks something
> like this:
>
> import pkg_resources
> pkg_resources.require("TurboGears")
>
> from os.path import *
> import os
> import sys
>
>
> def start():
> from turbogears import update_config, start_server
> import cherrypy
> cherrypy.lowercase_api = True
>
> # first look on the command line for a desired config file,
> # if it's not on the command line, then
> # look for setup.py in this directory. If it's not there, this
> script is
> # probably installed
> if len(sys.argv) > 1:
> update_config(configfile=sys.argv[1],
> modulename="sample.config")
> elif exists(join(os.getcwd(), "setup.py")):
>
> update_config(configfile="dev.cfg",modulename="sample.config")
> else:
>
> update_config(configfile="prod.cfg",modulename="sample.config")
>
> from sample.controllers import Root
>
> start_server(Root())
>
> The big change that we made was capturing most of the startup script's
> logic in a new start function that takes no arguments. Other than that
> we had to modify the elif statement that is looking for your dev.cfg
> file so it uses the current directory instead of looking for it in the
> same directory as the calling file.
>
> Now all you have to do is add an entry point that tells setuptools you
> are implementing a console script. This is done in your setup.py file.
> Here is a sample line:
>
> setup(
> name="sample",
> version=version,
> ...
> entry_points = """
> [console_scripts]
> sample-start = sample.commands:start
> """
>
> And that is pretty much it. When your project is installed, unless the
> user specifically requests that console scripts are not installed, a
> "sample-start" script is created and placed in the normal system
> directory.
>
nice
I like the idea
anyone else thinks something like this should be the default?
> -Adam
>
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---