Ticket #1386: start-script.patch

File start-script.patch, 4.7 kB (added by Chris Arndt, 8 months ago)
  • turbogears/qstemplates/quickstart/start-+package+.py_tmpl

    old new  
    11#!${sys_executable} 
    2 import pkg_resources 
    3 pkg_resources.require("TurboGears") 
     2# -*- coding: UTF-8 -*- 
     3"""Start script for the ${project} TurboGears project. 
    44 
    5 from turbogears import config, update_config, start_server 
    6 import cherrypy 
    7 cherrypy.lowercase_api = True 
    8 from os.path import * 
     5This script is only needed during development for running from the project  
     6directory. When the project is installed, easy_install will create a 
     7proper start script. 
     8""" 
     9 
    910import sys 
     11from ${package}.commands import start, ConfigurationError 
    1012 
    11 # first look on the command line for a desired config file, 
    12 # if it's not on the command line, then 
    13 # look for setup.py in this directory. If it's not there, this script is 
    14 # probably installed 
    15 if len(sys.argv) > 1: 
    16     update_config(configfile=sys.argv[1], 
    17         modulename="${package}.config") 
    18 elif exists(join(dirname(__file__), "setup.py")): 
    19     update_config(configfile="dev.cfg",modulename="${package}.config") 
    20 else: 
    21     update_config(configfile="prod.cfg",modulename="${package}.config") 
    22 config.update(dict(package="${package}")) 
    23  
    24 from ${package}.controllers import Root 
    25  
    26 start_server(Root()) 
     13if __name__ == "__main__": 
     14    try: 
     15        start() 
     16    except ConfigurationError, exc: 
     17        sys.stderr.write(str(exc)) 
     18        sys.exit(1) 
  • turbogears/qstemplates/quickstart/+package+/commands.py_tmpl

    old new  
     1#!${sys_executable} 
     2# -*- coding: UTF-8 -*- 
     3"""This module contains functions called from console script entry points.""" 
     4 
     5import os 
     6import sys 
     7 
     8from os.path import dirname, exists, join 
     9 
     10import pkg_resources 
     11pkg_resources.require("TurboGears") 
     12 
     13import turbogears 
     14import cherrypy 
     15 
     16cherrypy.lowercase_api = True 
     17 
     18class ConfigurationError(Exception): 
     19    pass 
     20 
     21def start(): 
     22    """Start the CherryPy application server.""" 
     23 
     24    setupdir = dirname(dirname(__file__)) 
     25    curdir = os.getcwd() 
     26 
     27    # First look on the command line for a desired config file, 
     28    # if it's not on the command line, then look for 'setup.py' 
     29    # in the current directory. If there, load configuration 
     30    # from a file called 'dev.cfg'. If it's not there, the project  
     31    # is probably installed and we'll look first for a file called 
     32    # 'prod.cfg' in the current directory and then for a default 
     33    # config file called 'default.cfg' packaged in the egg. 
     34    if len(sys.argv) > 1: 
     35        configfile = sys.argv[1] 
     36    elif exists(join(setupdir, "setup.py")): 
     37        configfile = join(setupdir, "dev.cfg") 
     38    elif exists(join(curdir, "prod.cfg")): 
     39        configfile = join(curdir, "prod.cfg") 
     40    else: 
     41        try: 
     42            configfile = pkg_resources.resource_filename( 
     43              pkg_resources.Requirement.parse("${project}"),  
     44                "config/default.cfg") 
     45        except pkg_resources.DistributionNotFound: 
     46            raise ConfigurationError("Could not find default configuration.") 
     47 
     48    turbogears.update_config(configfile=configfile, 
     49        modulename="${package}.config") 
     50 
     51    from ${package}.controllers import Root 
     52 
     53    turbogears.start_server(Root()) 
  • turbogears/qstemplates/quickstart/setup.py_tmpl

    old new  
     1# -*- coding: UTF-8 -*- 
     2 
    13from setuptools import setup, find_packages 
    24from turbogears.finddata import find_package_data 
    35 
     
    3032        "SQLAlchemy", 
    3133#end if 
    3234    ], 
    33     scripts=["start-${package}.py"], 
    3435    zip_safe=False, 
    3536    packages=packages, 
    3637    package_data=package_data, 
     
    6869        # 'Framework :: TurboGears :: Widgets', 
    6970    ], 
    7071    test_suite='nose.collector', 
     72    entry_points = { 
     73        'console_scripts': [ 
     74            'start-${package} = ${package}.commands:start', 
     75        ], 
     76    }, 
     77    # Uncomment next line and create a default.cfg file in your project dir 
     78    # if you want to package a default configuration in your egg. 
     79    #data_files = [('config', ['default.cfg'])], 
    7180    ) 
    7281